From 6fa53eda15eb07c0f150f60c6f2bd6428c24defb Mon Sep 17 00:00:00 2001 From: rinoux Date: Mon, 16 Aug 2021 11:05:29 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-51472=20=E5=B9=B3=E5=8F=B0=E5=BC=80?= =?UTF-8?q?=E5=90=AF=E7=9A=84=E6=A8=A1=E7=89=88=E8=AF=BB=E4=B8=8D=E5=88=B0?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/DesignerStrategyConfigUtils.java | 3 +- .../strategy/StrategyConfigHandler.java | 37 ++++++ .../tabledatapane/DBTableDataPane.java | 114 +++++++++++++++++- .../db/ServerStrategyConfigHandler.java | 70 ----------- .../db/StrategyConfigHandler.java | 16 --- .../db/TemplateStrategyConfigHandler.java | 50 -------- .../fr/start/module/DesignerESDActivator.java | 4 + 7 files changed, 154 insertions(+), 140 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/design/data/tabledata/strategy/StrategyConfigHandler.java delete mode 100644 designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/db/ServerStrategyConfigHandler.java delete mode 100644 designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/db/StrategyConfigHandler.java delete mode 100644 designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/db/TemplateStrategyConfigHandler.java diff --git a/designer-base/src/main/java/com/fr/design/data/DesignerStrategyConfigUtils.java b/designer-base/src/main/java/com/fr/design/data/DesignerStrategyConfigUtils.java index 8bc5f3644..c15b3f3ce 100644 --- a/designer-base/src/main/java/com/fr/design/data/DesignerStrategyConfigUtils.java +++ b/designer-base/src/main/java/com/fr/design/data/DesignerStrategyConfigUtils.java @@ -5,6 +5,7 @@ import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.mainframe.JTemplate; 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.core.strategy.persistence.StrategyConfigsAttr; import com.fr.esd.event.DSMapping; import com.fr.esd.event.DsNameTarget; @@ -67,7 +68,7 @@ public class DesignerStrategyConfigUtils { FILE file = jTemplate.getEditingFILE(); if (file != null) { String path = file.getPath(); - return StrategyConfigHelper.recommended(path); + return StrategyConfigService.isTemplateEnabled(path); } } return false; diff --git a/designer-base/src/main/java/com/fr/design/data/tabledata/strategy/StrategyConfigHandler.java b/designer-base/src/main/java/com/fr/design/data/tabledata/strategy/StrategyConfigHandler.java new file mode 100644 index 000000000..5b6a744d0 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/data/tabledata/strategy/StrategyConfigHandler.java @@ -0,0 +1,37 @@ +package com.fr.design.data.tabledata.strategy; + +import com.fr.esd.core.strategy.config.StrategyConfig; +import com.fr.esd.query.StrategicTableData; + +/** + * @author rinoux + * @version 10.0 + * Created by rinoux on 2021/3/19 + */ +public abstract class StrategyConfigHandler { + + private final T tableData; + + public StrategyConfigHandler(T tableData) { + this.tableData = tableData; + } + + protected T getTableData() { + return tableData; + } + + /** + * 查找配置 + * + * @return 缓存配置 + */ + public abstract StrategyConfig find(); + + + /** + * 保存配置 + * + * @param config 缓存配置 + */ + public abstract void save(T saved, StrategyConfig config); +} diff --git a/designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/DBTableDataPane.java b/designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/DBTableDataPane.java index ec3276b92..8f17a2a10 100644 --- a/designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/DBTableDataPane.java +++ b/designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/DBTableDataPane.java @@ -18,13 +18,13 @@ import com.fr.design.data.datapane.connect.ConnectionTableProcedurePane; import com.fr.design.data.datapane.preview.PreviewTablePane; import com.fr.design.data.datapane.preview.sql.PreviewPerformedSqlPane; import com.fr.design.data.datapane.sqlpane.SQLEditPane; -import com.fr.design.data.tabledata.tabledatapane.db.ServerStrategyConfigHandler; +import com.fr.design.data.tabledata.strategy.StrategyConfigHandler; +import com.fr.design.data.tabledata.tabledatapane.db.DBTableDataSavedHook; 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.BasicPane; import com.fr.design.dialog.DialogActionAdapter; +import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.fun.DBTableDataMenuHandler; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.icheckbox.UICheckBox; @@ -43,7 +43,11 @@ import com.fr.design.menu.ToolBarDef; import com.fr.design.utils.ParameterUtils; import com.fr.design.utils.gui.GUICoreUtils; 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.event.DsNameTarget; +import com.fr.esd.event.StrategyEventsNotifier; import com.fr.esd.query.StrategicTableData; import com.fr.general.ComparatorUtils; import com.fr.general.IOUtils; @@ -53,6 +57,7 @@ import com.fr.script.Calculator; import com.fr.stable.ArrayUtils; import com.fr.stable.ParameterProvider; import com.fr.stable.StringUtils; +import com.fr.workspace.WorkContext; import javax.swing.BorderFactory; import javax.swing.Box; @@ -619,4 +624,107 @@ public class DBTableDataPane extends AbstractTableDataPane { return this.title; } } + + /** + * 服务器数据集配置处理器 + */ + private static class ServerStrategyConfigHandler extends StrategyConfigHandler { + private final String origName; + + private final String origConnection; + + private final String origQuery; + + public ServerStrategyConfigHandler(DBTableData tableData) { + super(tableData); + this.origName = tableData.getDsName(); + this.origConnection = tableData.getDatabase().toString(); + this.origQuery = tableData.getQuery(); + } + + @Override + public StrategyConfig find() { + StrategyConfig strategyConfig = null; + if (getTableData() != null) { + try { + strategyConfig = getTableData().getStrategyConfig() == null ? null : getTableData().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 = getTableData().getStrategyConfig(); + saved.setStrategyConfig(strategyConfig.clone()); + StrategyEventsNotifier.compareAndFireConfigEvents(orig, strategyConfig, DSMapping.ofServerDS(new DsNameTarget(saved.getDsName()))); + } catch (CloneNotSupportedException e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + } + } + + + /** + * 模版数据集配置处理器 + */ + private static class TemplateStrategyConfigHandler extends StrategyConfigHandler { + public TemplateStrategyConfigHandler(DBTableData tableData) { + super(tableData); + } + + @Override + public StrategyConfig find() { + StrategyConfig strategyConfig = null; + String tplPath = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate().getEditingFILE().getPath(); + if (getTableData() != null && StringUtils.isNotEmpty(tplPath)) { + //设置保存数据集的事件检查钩子 + //新建模版此时不存在,不需要注册钩子 + if (getTableData().getXmlSavedHook() == null && WorkContext.getWorkResource().exist(tplPath)) { + getTableData().setXmlSavedHook(new DBTableDataSavedHook(tplPath, getTableData())); + } + + //获取当前的缓存配置,没有就创建一份 + String dsName = getTableData().getDsName(); + + //这里为了之前兼容插件创建的配置,缓存配置不在DBTableData,而是从模版attr读取 + strategyConfig = DesignerStrategyConfigUtils.getStrategyConfig(dsName); + + if (strategyConfig == null || strategyConfig.isUseGlobal()) { + //模版里面没有配置,检查模版是否被开启 + boolean tplEnabled = StrategyConfigService.isTemplateEnabled(tplPath); + if (tplEnabled) { + //使用全局配置 + strategyConfig = StrategyConfigHelper.createStrategyConfig(true); + } + } + } + + return strategyConfig; + } + + @Override + public void save(DBTableData saved, StrategyConfig config) { + + //DBTableDataSavedHook处理了 + } + } } diff --git a/designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/db/ServerStrategyConfigHandler.java b/designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/db/ServerStrategyConfigHandler.java deleted file mode 100644 index 467c29482..000000000 --- a/designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/db/ServerStrategyConfigHandler.java +++ /dev/null @@ -1,70 +0,0 @@ -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); - } - } -} diff --git a/designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/db/StrategyConfigHandler.java b/designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/db/StrategyConfigHandler.java deleted file mode 100644 index 346410e0e..000000000 --- a/designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/db/StrategyConfigHandler.java +++ /dev/null @@ -1,16 +0,0 @@ -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); -} diff --git a/designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/db/TemplateStrategyConfigHandler.java b/designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/db/TemplateStrategyConfigHandler.java deleted file mode 100644 index 4b0c98add..000000000 --- a/designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/db/TemplateStrategyConfigHandler.java +++ /dev/null @@ -1,50 +0,0 @@ -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) { - - } -} diff --git a/designer-realize/src/main/java/com/fr/start/module/DesignerESDActivator.java b/designer-realize/src/main/java/com/fr/start/module/DesignerESDActivator.java index ebfaf3470..827e91648 100644 --- a/designer-realize/src/main/java/com/fr/start/module/DesignerESDActivator.java +++ b/designer-realize/src/main/java/com/fr/start/module/DesignerESDActivator.java @@ -1,6 +1,9 @@ package com.fr.start.module; +import com.fr.esd.cache.manager.RecommendManager; import com.fr.esd.core.strategy.config.service.StrategyConfigService; +import com.fr.esd.core.strategy.recomend.EnabledTemplateService; +import com.fr.esd.core.strategy.recomend.EnabledTemplateServiceProvider; import com.fr.esd.impl.strategy.config.service.DefaultStrategyConfigServiceProvider; import com.fr.module.Activator; @@ -13,6 +16,7 @@ public class DesignerESDActivator extends Activator { @Override public void start() { StrategyConfigService.setService(new DefaultStrategyConfigServiceProvider()); + EnabledTemplateService.getInstance().registerService(path -> RecommendManager.getInstance().findByPath(path) != null); } @Override