Browse Source

KERNEL-7160 服务器数据集支持

research/11.0
rinoux 4 years ago
parent
commit
7f6dc681d3
  1. 4
      designer-base/src/main/java/com/fr/design/actions/server/GlobalTableDataAction.java
  2. 7
      designer-base/src/main/java/com/fr/design/data/datapane/ESDStrategyConfigPane.java
  3. 30
      designer-base/src/main/java/com/fr/design/data/datapane/TableDataTreePane.java
  4. 260
      designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/DBTableDataPane.java
  5. 47
      designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/db/DBTableDataSavedHook.java
  6. 70
      designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/db/ServerStrategyConfigHandler.java
  7. 33
      designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/db/StrategyConfigFrom.java
  8. 16
      designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/db/StrategyConfigHandler.java
  9. 50
      designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/db/TemplateStrategyConfigHandler.java

4
designer-base/src/main/java/com/fr/design/actions/server/GlobalTableDataAction.java

@ -20,6 +20,9 @@ import com.fr.design.gui.imenu.UIMenuItem;
import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.DesignerFrame; import com.fr.design.mainframe.DesignerFrame;
import com.fr.design.menu.MenuKeySet; import com.fr.design.menu.MenuKeySet;
import com.fr.esd.event.DSMapping;
import com.fr.esd.event.DsNameTarget;
import com.fr.esd.event.StrategyEventsNotifier;
import com.fr.file.TableDataConfig; import com.fr.file.TableDataConfig;
import com.fr.transaction.CallBackAdaptor; import com.fr.transaction.CallBackAdaptor;
@ -89,6 +92,7 @@ public class GlobalTableDataAction extends UpdateAction implements ResponseDataS
protected void renameConnection(final String oldName, final String newName) { protected void renameConnection(final String oldName, final String newName) {
tableDataConfig.renameTableData(oldName, newName); tableDataConfig.renameTableData(oldName, newName);
StrategyEventsNotifier.modifyDataSet(DSMapping.ofServerDS(new DsNameTarget(oldName)));
} }
}; };
final BasicDialog globalTableDataDialog = globalTableDataPane.showWindowWithCustomSize(designerFrame, null, DEFAULT_DIMENSION); final BasicDialog globalTableDataDialog = globalTableDataPane.showWindowWithCustomSize(designerFrame, null, DEFAULT_DIMENSION);

7
designer-base/src/main/java/com/fr/design/data/datapane/ESDStrategyConfigPane.java

@ -35,6 +35,8 @@ import java.util.List;
* Created by rinoux on 2020/7/22 * Created by rinoux on 2020/7/22
*/ */
public class ESDStrategyConfigPane extends BasicBeanPane<StrategyConfig> { public class ESDStrategyConfigPane extends BasicBeanPane<StrategyConfig> {
private static final String CRON_HELP_URL = "http://help.fanruan.com/finereport/doc-view-693.html";
private UIRadioButton selectAutoUpdate; private UIRadioButton selectAutoUpdate;
private UIRadioButton selectBySchema; private UIRadioButton selectBySchema;
private UICheckBox shouldEvolve; private UICheckBox shouldEvolve;
@ -46,7 +48,6 @@ public class ESDStrategyConfigPane extends BasicBeanPane<StrategyConfig> {
private final boolean global; private final boolean global;
private StrategyConfig strategyConfig; private StrategyConfig strategyConfig;
private static final String CRON_HELP_URL = "http://help.fanruan.com/finereport/doc-view-693.html";
public ESDStrategyConfigPane(boolean global) { public ESDStrategyConfigPane(boolean global) {
this.global = global; this.global = global;
@ -182,7 +183,7 @@ public class ESDStrategyConfigPane extends BasicBeanPane<StrategyConfig> {
} }
} else { } else {
this.schemaTimeCheckTips.setVisible(true); this.schemaTimeCheckTips.setVisible(true);
throw new IllegalArgumentException("update schema time format error."); throw new IllegalArgumentException("[ESD]Update schema time format error.");
} }
config.setScheduleBySchema(true); config.setScheduleBySchema(true);
config.setUpdateSchema(schemaTimes); config.setUpdateSchema(schemaTimes);
@ -193,7 +194,7 @@ public class ESDStrategyConfigPane extends BasicBeanPane<StrategyConfig> {
config.setUpdateInterval(intervalMillis); config.setUpdateInterval(intervalMillis);
} else { } else {
this.updateIntervalCheckTips.setVisible(true); this.updateIntervalCheckTips.setVisible(true);
throw new IllegalArgumentException("Error update interval format."); throw new IllegalArgumentException("[ESD]Error update interval format.");
} }
config.setShouldEvolve(this.shouldEvolve.isSelected()); config.setShouldEvolve(this.shouldEvolve.isSelected());

30
designer-base/src/main/java/com/fr/design/data/datapane/TableDataTreePane.java

@ -41,6 +41,7 @@ import com.fr.esd.core.strategy.config.StrategyConfigHelper;
import com.fr.esd.event.DSMapping; import com.fr.esd.event.DSMapping;
import com.fr.esd.event.DsNameTarget; import com.fr.esd.event.DsNameTarget;
import com.fr.esd.event.StrategyEventsNotifier; import com.fr.esd.event.StrategyEventsNotifier;
import com.fr.esd.query.StrategicTableData;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.general.IOUtils; import com.fr.general.IOUtils;
import com.fr.general.NameObject; import com.fr.general.NameObject;
@ -202,12 +203,12 @@ public class TableDataTreePane extends BasicTableDataTreePane {
TableData tableData = (TableData) creator.createObject(); TableData tableData = (TableData) creator.createObject();
//新建的DBTableData单独换为DBTableData //新建的DBTableData单独换为DBTableData
if (tableData instanceof DBTableData) { if (tableData instanceof StrategicTableData) {
tableData = new DBTableData(); tableData = new DBTableData();
String dsName = createDsName(creator.getPrefix()); StrategicTableData.Binder
((DBTableData) tableData).setDsName(dsName); .bind((DBTableData) tableData)
} else { .setDsName(createDsName(creator.getPrefix()))
// TODO: 2020/11/10 后期支持其它数据集,这里转化可以不用侵入修改TableDataCreatorProducer .setScope(StrategicTableData.Scope.TEMPLATE);
} }
return new TemplateTableDataWrapper(tableData); return new TemplateTableDataWrapper(tableData);
} }
@ -269,21 +270,6 @@ public class TableDataTreePane extends BasicTableDataTreePane {
((DBTableData) td).setDsName(tdName); ((DBTableData) td).setDsName(tdName);
} }
//服务器数据集不会走这里,入口不一样
/*if (tableDataPane instanceof ServerDBTableDataPane) {
StrategyConfig editingConfig = ((ServerDBTableDataPane) tableDataPane).updateStrategyConfig();
if (editingConfig != null) {
editingConfig.setDsName(tdName);
if (!ComparatorUtils.equals(oldName, tdName)) {
//重命名
DesignerStrategyConfigUtils.removeServerStrategyConfig(oldName);
}
DesignerStrategyConfigUtils.addServerStrategyConfig(editingConfig);
}
}*/
tds.putTableData(tdName, td); tds.putTableData(tdName, td);
Map<String, String> map = new HashMap<String, String>(); Map<String, String> map = new HashMap<String, String>();
if (!ComparatorUtils.equals(oldName, tdName)) { if (!ComparatorUtils.equals(oldName, tdName)) {
@ -339,8 +325,8 @@ public class TableDataTreePane extends BasicTableDataTreePane {
String tdName = (String) tdIterator.next(); String tdName = (String) tdIterator.next();
String oldName = tdName; String oldName = tdName;
TableData td = tableDataSource.getTableData(tdName); TableData td = tableDataSource.getTableData(tdName);
boolean isDsNameRepeaded = isDsNameRepeaded(tdName); boolean isDsNameRepeated = isDsNameRepeaded(tdName);
tdName = BasicTableDataUtils.getTableDataName(isCover, tds, tdName, srcName, isDsNameRepeaded); tdName = BasicTableDataUtils.getTableDataName(isCover, tds, tdName, srcName, isDsNameRepeated);
tds.putTableData(tdName, td); tds.putTableData(tdName, td);
if (!ComparatorUtils.equals(oldName, tdName)) { if (!ComparatorUtils.equals(oldName, tdName)) {
tdNameMap.put(oldName, tdName); tdNameMap.put(oldName, tdName);

260
designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/DBTableDataPane.java

@ -17,10 +17,13 @@ import com.fr.design.data.datapane.ESDStrategyConfigPane;
import com.fr.design.data.datapane.connect.ConnectionTableProcedurePane; import com.fr.design.data.datapane.connect.ConnectionTableProcedurePane;
import com.fr.design.data.datapane.preview.PreviewTablePane; import com.fr.design.data.datapane.preview.PreviewTablePane;
import com.fr.design.data.datapane.sqlpane.SQLEditPane; import com.fr.design.data.datapane.sqlpane.SQLEditPane;
import com.fr.design.data.tabledata.tabledatapane.db.ServerStrategyConfigHandler;
import com.fr.design.data.tabledata.tabledatapane.db.StrategyConfigFrom;
import com.fr.design.data.tabledata.tabledatapane.db.StrategyConfigHandler;
import com.fr.design.data.tabledata.tabledatapane.db.TemplateStrategyConfigHandler;
import com.fr.design.dialog.BasicDialog; import com.fr.design.dialog.BasicDialog;
import com.fr.design.dialog.BasicPane; import com.fr.design.dialog.BasicPane;
import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.dialog.DialogActionAdapter;
import com.fr.design.file.HistoryTemplateListCache;
import com.fr.design.fun.DBTableDataMenuHandler; import com.fr.design.fun.DBTableDataMenuHandler;
import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.icheckbox.UICheckBox; import com.fr.design.gui.icheckbox.UICheckBox;
@ -39,11 +42,8 @@ import com.fr.design.menu.ToolBarDef;
import com.fr.design.utils.ParameterUtils; import com.fr.design.utils.ParameterUtils;
import com.fr.design.utils.gui.GUICoreUtils; import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.esd.core.strategy.config.StrategyConfig; import com.fr.esd.core.strategy.config.StrategyConfig;
import com.fr.esd.core.strategy.config.StrategyConfigHelper; import com.fr.esd.core.strategy.config.service.StrategyConfigService;
import com.fr.esd.event.DSMapping; import com.fr.esd.query.StrategicTableData;
import com.fr.esd.event.DsNameTarget;
import com.fr.esd.event.StrategyEventsNotifier;
import com.fr.esd.event.xml.XMLSavedHook;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.general.IOUtils; import com.fr.general.IOUtils;
import com.fr.general.sql.SqlUtils; import com.fr.general.sql.SqlUtils;
@ -52,7 +52,6 @@ import com.fr.script.Calculator;
import com.fr.stable.ArrayUtils; import com.fr.stable.ArrayUtils;
import com.fr.stable.ParameterProvider; import com.fr.stable.ParameterProvider;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import com.fr.workspace.WorkContext;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
import javax.swing.Box; import javax.swing.Box;
@ -89,20 +88,26 @@ public class DBTableDataPane extends AbstractTableDataPane<DBTableData> {
private UITableEditorPane<ParameterProvider> editorPane; private UITableEditorPane<ParameterProvider> editorPane;
private DBTableDataMenuHandler dbTableDataMenuHandler; private DBTableDataMenuHandler dbTableDataMenuHandler;
private SQLEditPane sqlTextPane; private SQLEditPane sqlTextPane;
UIComboBox configFromList;
UICheckBox esdEnabled;
private UIButton esdSettingsBtn;
private UILabel barErrorTips;
private String pageQuery; private String pageQuery;
private DBTableData dbTableData; private DBTableData dbTableData;
StrategyConfig strategyConfig;
//ESD
private UILabel esdSettingsLabel;
private UIComboBox esdConfigOption;
private UICheckBox esdEnabled;
private UIButton esdSettingsBtn;
private UILabel barErrorTips;
//配置
private StrategyConfig strategyConfig;
private StrategyConfigHandler configHandler;
public DBTableDataPane() { public DBTableDataPane() {
init(); init();
initMainSplitPane(); initMainSplitPane();
} }
private void init() { private void init() {
setLayout(new BorderLayout(4, 4)); setLayout(new BorderLayout(4, 4));
@ -182,7 +187,6 @@ public class DBTableDataPane extends AbstractTableDataPane<DBTableData> {
}); });
} }
private void initMainSplitPane() { private void initMainSplitPane() {
Box box = new Box(BoxLayout.Y_AXIS); Box box = new Box(BoxLayout.Y_AXIS);
@ -223,7 +227,6 @@ public class DBTableDataPane extends AbstractTableDataPane<DBTableData> {
add(mainSplitPane, BorderLayout.CENTER); add(mainSplitPane, BorderLayout.CENTER);
} }
private boolean isPreviewOrRefreshButton(FocusEvent e) { private boolean isPreviewOrRefreshButton(FocusEvent e) {
if (e.getOppositeComponent() != null) { if (e.getOppositeComponent() != null) {
String name = e.getOppositeComponent().getName(); String name = e.getOppositeComponent().getName();
@ -232,13 +235,11 @@ public class DBTableDataPane extends AbstractTableDataPane<DBTableData> {
return false; return false;
} }
@Override @Override
protected String title4PopupWindow() { protected String title4PopupWindow() {
return Toolkit.i18nText("Fine-Design_Basic_DS-Database_Query"); return Toolkit.i18nText("Fine-Design_Basic_DS-Database_Query");
} }
private void refreshParameters() { private void refreshParameters() {
String[] paramTexts = new String[2]; String[] paramTexts = new String[2];
paramTexts[0] = SqlUtils.tryPureSqlText(this.sqlTextPane.getText()); paramTexts[0] = SqlUtils.tryPureSqlText(this.sqlTextPane.getText());
@ -249,7 +250,6 @@ public class DBTableDataPane extends AbstractTableDataPane<DBTableData> {
this.editorPane.populate(ParameterUtils.analyzeAndUnionParameters(paramTexts, ps)); this.editorPane.populate(ParameterUtils.analyzeAndUnionParameters(paramTexts, ps));
} }
private JToolBar createToolBar() { private JToolBar createToolBar() {
ToolBarDef toolBarDef = new ToolBarDef(); ToolBarDef toolBarDef = new ToolBarDef();
toolBarDef.addShortCut(new PreviewAction()); toolBarDef.addShortCut(new PreviewAction());
@ -261,26 +261,34 @@ public class DBTableDataPane extends AbstractTableDataPane<DBTableData> {
toolBarDef.addShortCut(this.dbTableDataMenuHandler.createQueryAction()); toolBarDef.addShortCut(this.dbTableDataMenuHandler.createQueryAction());
} }
UILabel esdSettingsLabel = new UILabel(Toolkit.i18nText("Fine-Design_ESD_Cache_Settings")); UIToolbar editToolBar = ToolBarDef.createJToolBar();
this.configFromList = new UIComboBox(ConfigFrom.values()); toolBarDef.updateToolBar(editToolBar);
//esd相关组件初始化
createToolbarEsdComponents(editToolBar);
return editToolBar;
}
private void createToolbarEsdComponents(final UIToolbar editToolBar) {
this.esdSettingsLabel = new UILabel(Toolkit.i18nText("Fine-Design_ESD_Cache_Settings"));
this.esdConfigOption = new UIComboBox(StrategyConfigFrom.values());
this.esdEnabled = new UICheckBox(Toolkit.i18nText("Fine-Design_ESD_Enable_Cache")); this.esdEnabled = new UICheckBox(Toolkit.i18nText("Fine-Design_ESD_Enable_Cache"));
this.barErrorTips = new UILabel(); this.barErrorTips = new UILabel();
this.barErrorTips.setForeground(Color.RED); this.barErrorTips.setForeground(Color.RED);
this.barErrorTips.setVisible(false); this.barErrorTips.setVisible(false);
esdSettingsBtn = new UIButton(Toolkit.i18nText("Fine-Design_ESD_Strategy_Config")); esdSettingsBtn = new UIButton(Toolkit.i18nText("Fine-Design_ESD_Strategy_Config"));
esdSettingsBtn.addActionListener(new ActionListener() { esdSettingsBtn.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
final boolean global = (DBTableDataPane.this.configFromList.getSelectedIndex() == DBTableDataPane.ConfigFrom.GLOBAL.getIndex()); final boolean global = globalOptionSelected();
final ESDStrategyConfigPane strategyConfigPane = new ESDStrategyConfigPane(global); final ESDStrategyConfigPane strategyConfigPane = new ESDStrategyConfigPane(global);
StrategyConfig populateStrategyConfig = null; StrategyConfig populateStrategyConfig;
if (global) { if (global) {
populateStrategyConfig = StrategyConfigHelper.getGlobalStrategyConfig(); populateStrategyConfig = StrategyConfigService.getGlobalConfig();
} else { } else {
populateStrategyConfig = strategyConfig; populateStrategyConfig = strategyConfig;
} }
@ -295,6 +303,7 @@ public class DBTableDataPane extends AbstractTableDataPane<DBTableData> {
if (!global) { if (!global) {
//点击策略配置面板的确定,重新设置策略配置 //点击策略配置面板的确定,重新设置策略配置
strategyConfig = strategyConfigPane.updateBean(); strategyConfig = strategyConfigPane.updateBean();
// TODO: 2021/3/12 这个直接使用不太好
} }
} }
}); });
@ -303,56 +312,49 @@ public class DBTableDataPane extends AbstractTableDataPane<DBTableData> {
} }
}); });
this.configFromList.setSelectedIndex(DBTableDataPane.ConfigFrom.GLOBAL.getIndex()); this.esdConfigOption.setSelectedIndex(StrategyConfigFrom.GLOBAL.getIndex());
this.configFromList.addActionListener(e -> setEsdEnabled()); this.esdConfigOption.addActionListener(e -> setEsdEnabled());
UIToolbar editToolBar = ToolBarDef.createJToolBar();
toolBarDef.updateToolBar(editToolBar);
editToolBar.add(esdSettingsLabel); //工具栏加上esd相关组件
editToolBar.add(this.configFromList); editToolBar.add(this.esdSettingsLabel);
editToolBar.add(this.esdConfigOption);
editToolBar.add(this.esdEnabled); editToolBar.add(this.esdEnabled);
editToolBar.add(this.esdSettingsBtn); editToolBar.add(this.esdSettingsBtn);
editToolBar.add(this.barErrorTips); editToolBar.add(this.barErrorTips);
return editToolBar;
} }
private boolean globalOptionSelected() {
/* private void showBarError(String errorTips) { return esdConfigOption.getSelectedIndex() == StrategyConfigFrom.GLOBAL.getIndex();
this.barErrorTips.setText(errorTips);
this.barErrorTips.setVisible(true);
} }
private boolean checkQuery(String errorTips) { private void setEsdEnableStatus(boolean selected, boolean enabled) {
if (StringUtils.isEmpty(this.sqlTextPane.getText())) { this.esdEnabled.setSelected(selected);
showBarError(errorTips); this.esdEnabled.setEnabled(enabled);
return false;
} }
return true; private void setEsdEnabled() {
}*/ boolean useIndividualConfig = !this.globalOptionSelected();
/**
* 设置是否开启
*/
protected void setEsdEnabled() {
boolean useIndividualConfig = configFromList.getSelectedIndex() == ConfigFrom.INDIVIDUAL.getIndex();
if (useIndividualConfig) { if (useIndividualConfig) {
if (this.strategyConfig == null) { if (this.strategyConfig == null) {
//新建的数据集,选择单独时,可用但是不勾选 //新建的数据集,选择单独时,可用但是不勾选
this.esdEnabled.setSelected(false); setEsdEnableStatus(false, true);
this.esdEnabled.setEnabled(true);
} else { } else {
this.esdEnabled.setSelected(!this.strategyConfig.isUseGlobal() && this.strategyConfig.enabled()); setEsdEnableStatus(!this.strategyConfig.isUseGlobal() && this.strategyConfig.enabled(), true);
this.esdEnabled.setEnabled(true);
} }
} else { } else {
this.esdEnabled.setSelected(DesignerStrategyConfigUtils.isEditingTemplateRecommended()); //判断是不是模版数据集
this.esdEnabled.setEnabled(false); switch (this.dbTableData.getScope()) {
case TEMPLATE:
setEsdEnableStatus(DesignerStrategyConfigUtils.isEditingTemplateRecommended(), false);
break;
case SERVER:
//不会走到这里
default:
break;
}
} }
} }
public StrategyConfig updateStrategyConfig() { public StrategyConfig updateStrategyConfig() {
return this.strategyConfig; return this.strategyConfig;
@ -386,7 +388,6 @@ public class DBTableDataPane extends AbstractTableDataPane<DBTableData> {
refreshParameters(); refreshParameters();
} }
@Override @Override
public void populateBean(DBTableData dbTableData) { public void populateBean(DBTableData dbTableData) {
this.dbTableData = dbTableData; this.dbTableData = dbTableData;
@ -410,56 +411,60 @@ public class DBTableDataPane extends AbstractTableDataPane<DBTableData> {
this.sqlTextPane.moveCaretPosition(this.sqlTextPane.getCaretPosition()); this.sqlTextPane.moveCaretPosition(this.sqlTextPane.getCaretPosition());
switch (dbTableData.getScope()) {
case TEMPLATE:
this.configHandler = new TemplateStrategyConfigHandler(dbTableData);
break;
case SERVER:
//服务器数据集
default:
//新建服务器数据集
this.configHandler = new ServerStrategyConfigHandler(dbTableData);
break;
}
//设置esd相关组件显示状态
populateESDComponents();
}
private void populateESDComponents() {
//查找映射的配置 //查找映射的配置
this.strategyConfig = mapStrategyConfig(dbTableData); this.strategyConfig = configHandler.find();
boolean shouldEnable = false; boolean shouldEnable = false;
ConfigFrom from = ConfigFrom.GLOBAL; StrategyConfigFrom from = StrategyConfigFrom.GLOBAL;
if (this.strategyConfig != null) { if (this.strategyConfig != null) {
if (this.strategyConfig.enabled()) { if (this.strategyConfig.enabled()) {
shouldEnable = true; shouldEnable = true;
} }
if (!this.strategyConfig.isUseGlobal()) { if (!this.strategyConfig.isUseGlobal()) {
from = ConfigFrom.INDIVIDUAL; from = StrategyConfigFrom.INDIVIDUAL;
}
} }
this.esdEnabled.setSelected(shouldEnable);
this.configFromList.setSelectedIndex(from.getIndex());
} }
//服务器数据集不允许设置来源,只能单独配置
protected StrategyConfig mapStrategyConfig(DBTableData dbTableData) { if (dbTableData.getScope() != StrategicTableData.Scope.TEMPLATE) {
//获取配置,如果是模版数据集,dbTableData实例应该是DBTableData,如果是服务器数据集是DBTableData from = StrategyConfigFrom.INDIVIDUAL;
StrategyConfig strategyConfig = null; this.esdConfigOption.setEnabled(false);
if (dbTableData != null) {
//设置保存数据集的事件检查钩子
String tplPath = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate().getEditingFILE().getPath();
//新建模版此时不存在,不需要注册钩子
if (dbTableData.getXmlSavedHook() == null && WorkContext.getWorkResource().exist(tplPath)) {
dbTableData.setXmlSavedHook(new DBTableDataSavedHook(tplPath, dbTableData));
}
//获取当前的缓存配置,没有就创建一份
String dsName = this.dbTableData.getDsName();
strategyConfig = DesignerStrategyConfigUtils.getStrategyConfig(dsName);
if (strategyConfig == null && dbTableData.isShare()) {
strategyConfig = StrategyConfigHelper.createStrategyConfig(true, false, true);
}
} }
this.esdEnabled.setSelected(shouldEnable);
return strategyConfig; this.esdConfigOption.setSelectedIndex(from.getIndex());
} }
@Override
public DBTableData updateBean() { public DBTableData updateBean() {
updateDBTableData(); updateDBTableData();
internalUpdateStrategyConfig();
return this.dbTableData;
}
private void internalUpdateStrategyConfig() {
//这边只修改enable和useGlobal //这边只修改enable和useGlobal
boolean global = DBTableDataPane.this.configFromList.getSelectedIndex() == DBTableDataPane.ConfigFrom.GLOBAL.getIndex(); boolean global = globalOptionSelected();
boolean enable = DBTableDataPane.this.esdEnabled.isSelected(); boolean enable = this.esdEnabled.isSelected();
//未开启缓存的,如果选择了单独配置,需要创建配置 //未开启缓存的,如果选择了单独配置,需要创建配置
@ -473,10 +478,10 @@ public class DBTableDataPane extends AbstractTableDataPane<DBTableData> {
this.strategyConfig.setUseGlobal(global); this.strategyConfig.setUseGlobal(global);
} }
return this.dbTableData; //保存
this.configHandler.save(this.dbTableData, this.strategyConfig);
} }
private void updateDBTableData() { private void updateDBTableData() {
String dbName = this.connectionTableProcedurePane.getSelectedDatabaseConnnectonName(); String dbName = this.connectionTableProcedurePane.getSelectedDatabaseConnnectonName();
if (StringUtils.isBlank(dbName) || StringUtils.isBlank(this.sqlTextPane.getText())) { if (StringUtils.isBlank(dbName) || StringUtils.isBlank(this.sqlTextPane.getText())) {
@ -524,9 +529,7 @@ public class DBTableDataPane extends AbstractTableDataPane<DBTableData> {
} }
} }
private class PreviewAction extends UpdateAction {
private class PreviewAction
extends UpdateAction {
public PreviewAction() { public PreviewAction() {
setName(PREVIEW_BUTTON); setName(PREVIEW_BUTTON);
setMnemonic('P'); setMnemonic('P');
@ -600,79 +603,4 @@ public class DBTableDataPane extends AbstractTableDataPane<DBTableData> {
return this.title; return this.title;
} }
} }
enum ConfigFrom {
GLOBAL(0, Toolkit.i18nText("Fine-Design_ESD_Use_Global_Settings")),
INDIVIDUAL(1, Toolkit.i18nText("Fine-Design_ESD_Use_Individual_Settings"));
int index;
String displayText;
ConfigFrom(int index, String displayText) {
this.index = index;
this.displayText = displayText;
}
static int parse(StrategyConfig config) {
return (config == null || config.isUseGlobal()) ? ConfigFrom.GLOBAL.getIndex() : ConfigFrom.INDIVIDUAL.getIndex();
}
public int getIndex() {
return this.index;
}
public String getDisplayText() {
return this.displayText;
}
public String toString() {
return getDisplayText();
}
}
private static class DBTableDataSavedHook implements XMLSavedHook<DBTableData> {
private static final long serialVersionUID = 4925391747683335372L;
private final String tplPath;
private String origName;
private String origConnection;
private String origQuery;
public DBTableDataSavedHook(String tplPath, DBTableData origDBTableData) {
this.tplPath = tplPath;
this.origName = origDBTableData.getDsName();
this.origConnection = origDBTableData.getDatabase().toString();
this.origQuery = origDBTableData.getQuery();
}
@Override
public void doAfterSaved(DBTableData saved) {
String dsName = saved.getDsName();
String conn = saved.getDatabase().toString();
String query = saved.getQuery();
//检查数据集名称、数据链接和sql是否修改,如果修改需要触发缓存监听事件
if (!dsName.equals(origName) || !conn.equals(origConnection) || !query.equals(origQuery)) {
if (StringUtils.isNotEmpty(tplPath) && StringUtils.isNotEmpty(origName)) {
//新建数据集的origName为null,不用触发
StrategyEventsNotifier.modifyDataSet(new DSMapping(tplPath, new DsNameTarget(origName)));
}
}
this.origName = dsName;
this.origConnection = conn;
this.origQuery = query;
}
}
} }

47
designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/db/DBTableDataSavedHook.java

@ -0,0 +1,47 @@
package com.fr.design.data.tabledata.tabledatapane.db;
import com.fr.data.impl.DBTableData;
import com.fr.esd.event.DSMapping;
import com.fr.esd.event.DsNameTarget;
import com.fr.esd.event.StrategyEventsNotifier;
import com.fr.esd.event.xml.XMLSavedHook;
import com.fr.stable.StringUtils;
public class DBTableDataSavedHook implements XMLSavedHook<DBTableData> {
private static final long serialVersionUID = 4925391747683335372L;
private final String tplPath;
private String origName;
private String origConnection;
private String origQuery;
public DBTableDataSavedHook(String tplPath, DBTableData origDBTableData) {
this.tplPath = tplPath;
this.origName = origDBTableData.getDsName();
this.origConnection = origDBTableData.getDatabase().toString();
this.origQuery = origDBTableData.getQuery();
}
@Override
public void doAfterSaved(DBTableData saved) {
String dsName = saved.getDsName();
String conn = saved.getDatabase().toString();
String query = saved.getQuery();
//检查数据集名称、数据链接和sql是否修改,如果修改需要触发缓存监听事件
if (!dsName.equals(origName) || !conn.equals(origConnection) || !query.equals(origQuery)) {
if (StringUtils.isNotEmpty(tplPath) && StringUtils.isNotEmpty(origName)) {
//新建数据集的origName为null,不用触发
StrategyEventsNotifier.modifyDataSet(new DSMapping(tplPath, new DsNameTarget(origName)));
}
}
this.origName = dsName;
this.origConnection = conn;
this.origQuery = query;
}
}

70
designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/db/ServerStrategyConfigHandler.java

@ -0,0 +1,70 @@
package com.fr.design.data.tabledata.tabledatapane.db;
import com.fr.data.impl.DBTableData;
import com.fr.esd.core.strategy.config.StrategyConfig;
import com.fr.esd.event.DSMapping;
import com.fr.esd.event.DsNameTarget;
import com.fr.esd.event.StrategyEventsNotifier;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.StringUtils;
/**
* @author rinoux
* @version 10.0
* Created by rinoux on 2021/3/19
*/
public class ServerStrategyConfigHandler implements StrategyConfigHandler {
private final DBTableData tableData;
private final String origName;
private final String origConnection;
private final String origQuery;
public ServerStrategyConfigHandler(DBTableData tableData) {
this.tableData = tableData;
this.origName = tableData.getDsName();
this.origConnection = tableData.getDatabase().toString();
this.origQuery = tableData.getQuery();
}
@Override
public StrategyConfig find() {
StrategyConfig strategyConfig = null;
if (tableData != null) {
try {
strategyConfig = tableData.getStrategyConfig() == null ? null : tableData.getStrategyConfig().clone();
} catch (CloneNotSupportedException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
return strategyConfig;
}
@Override
public void save(DBTableData saved, StrategyConfig strategyConfig) {
String conn = saved.getDatabase().toString();
String query = saved.getQuery();
//检查数据链接和sql是否修改,如果修改需要触发缓存监听事件
if (!conn.equals(origConnection) || !query.equals(origQuery)) {
if (StringUtils.isNotEmpty(origName)) {
//新建数据集的origName为null,不用触发
StrategyEventsNotifier.modifyDataSet(DSMapping.ofServerDS(new DsNameTarget(origName)));
}
}
//配置变动事件
try {
final StrategyConfig orig = tableData.getStrategyConfig();
saved.setStrategyConfig(strategyConfig.clone());
StrategyEventsNotifier.compareAndFireConfigEvents(orig, strategyConfig, DSMapping.ofServerDS(new DsNameTarget(saved.getDsName())));
} catch (CloneNotSupportedException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
}

33
designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/db/StrategyConfigFrom.java

@ -0,0 +1,33 @@
package com.fr.design.data.tabledata.tabledatapane.db;
import com.fr.design.i18n.Toolkit;
public enum StrategyConfigFrom {
GLOBAL(0, Toolkit.i18nText("Fine-Design_ESD_Use_Global_Settings")),
INDIVIDUAL(1, Toolkit.i18nText("Fine-Design_ESD_Use_Individual_Settings"));
int index;
String displayText;
StrategyConfigFrom(int index, String displayText) {
this.index = index;
this.displayText = displayText;
}
public int getIndex() {
return this.index;
}
public String getDisplayText() {
return this.displayText;
}
public String toString() {
return getDisplayText();
}
}

16
designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/db/StrategyConfigHandler.java

@ -0,0 +1,16 @@
package com.fr.design.data.tabledata.tabledatapane.db;
import com.fr.data.impl.DBTableData;
import com.fr.esd.core.strategy.config.StrategyConfig;
/**
* @author rinoux
* @version 10.0
* Created by rinoux on 2021/3/19
*/
public interface StrategyConfigHandler {
StrategyConfig find();
void save(DBTableData saved, StrategyConfig config);
}

50
designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/db/TemplateStrategyConfigHandler.java

@ -0,0 +1,50 @@
package com.fr.design.data.tabledata.tabledatapane.db;
import com.fr.base.TableData;
import com.fr.data.impl.DBTableData;
import com.fr.design.data.DesignerStrategyConfigUtils;
import com.fr.design.file.HistoryTemplateListCache;
import com.fr.esd.core.strategy.config.StrategyConfig;
import com.fr.esd.query.StrategicTableData;
import com.fr.workspace.WorkContext;
/**
* @author rinoux
* @version 10.0
* Created by rinoux on 2021/3/19
*/
public class TemplateStrategyConfigHandler implements StrategyConfigHandler {
DBTableData tableData;
public TemplateStrategyConfigHandler(DBTableData tableData) {
this.tableData = tableData;
}
@Override
public StrategyConfig find() {
StrategyConfig strategyConfig = null;
if (tableData != null) {
//设置保存数据集的事件检查钩子
String tplPath = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate().getEditingFILE().getPath();
//新建模版此时不存在,不需要注册钩子
if (tableData.getXmlSavedHook() == null && WorkContext.getWorkResource().exist(tplPath)) {
tableData.setXmlSavedHook(new DBTableDataSavedHook(tplPath, tableData));
}
//获取当前的缓存配置,没有就创建一份
String dsName = tableData.getDsName();
//这里为了之前兼容插件创建的配置,缓存配置不在DBTableData,而是从模版attr读取
strategyConfig = DesignerStrategyConfigUtils.getStrategyConfig(dsName);
}
return strategyConfig;
}
@Override
public void save(DBTableData saved, StrategyConfig config) {
}
}
Loading…
Cancel
Save