diff --git a/designer-base/src/main/java/com/fr/design/data/MapCompareUtils.java b/designer-base/src/main/java/com/fr/design/data/MapCompareUtils.java deleted file mode 100644 index 331e980834..0000000000 --- a/designer-base/src/main/java/com/fr/design/data/MapCompareUtils.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.fr.design.data; - -import org.jetbrains.annotations.NotNull; - -import java.util.LinkedHashMap; -import java.util.Map; - -/** - * @author rinoux - * @version 10.0 - * Created by rinoux on 2022/3/28 - */ -public final class MapCompareUtils { - - - /** - * 对比两个map 查找出相比orig,other中有哪些是新增的、删除的或者被修改的,并分别进行处理 - * - * 对比时默认用equals方法来判断是否为 EntryEventKind#UPDATED - * - * @param orig 原始map - * @param other 参考的新map - * @param eventHandler 有区别时的事件处理器 - * @param K - * @param V - */ - public static void contrastMapEntries(@NotNull Map orig, @NotNull Map other, @NotNull EventHandler eventHandler) { - - contrastMapEntries(orig, other, eventHandler, UpdateRule.DEFAULT); - } - - /** - * 对比两个map 查找出相比orig,other中有哪些是新增的、删除的或者被修改的,并分别进行处理 - * - * 对比时用自定义的规则来判断是否为 EntryEventKind#UPDATED - * - * @param orig 原始map - * @param other 参考的新map - * @param eventHandler 有区别时的事件处理器 - * @param updateRule 自定义的Update事件判定规则 - * @param - * @param - */ - public static void contrastMapEntries(@NotNull Map orig, @NotNull Map other, @NotNull EventHandler eventHandler, @NotNull UpdateRule updateRule) { - - Map copiedOrig = new LinkedHashMap<>(orig); - - other.forEach((k, v) -> { - V existedV = copiedOrig.remove(k); - if (existedV != null) { - if (updateRule.needUpdate(existedV, v)) { - eventHandler.on(EntryEventKind.UPDATED, k, v); - } - } else { - eventHandler.on(EntryEventKind.ADDED, k, v); - } - }); - - copiedOrig.forEach((k, v) -> eventHandler.on(EntryEventKind.REMOVED, k, v)); - } - - - /** - * 事件处理器,对应比较后的三种结果的事件处理 - * @param - * @param - */ - public interface EventHandler { - void on(EntryEventKind entryEventKind, K k, V v); - } - - /** - * 数据被修改(EntryEventKind.UPDATED) 的判定规则 - * @param - * @param - */ - public interface UpdateRule { - - EntryEventKind eventKind = EntryEventKind.UPDATED; - - UpdateRule DEFAULT = new UpdateRule() {}; - - default boolean needUpdate(V origin, V v) { - return !v.equals(origin); - } - } - - public enum EntryEventKind { - ADDED, - REMOVED, - UPDATED; - } -} diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/TableDataPaneListPane.java b/designer-base/src/main/java/com/fr/design/data/datapane/TableDataPaneListPane.java index 0694222339..ea368bbfcd 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/TableDataPaneListPane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/TableDataPaneListPane.java @@ -5,12 +5,8 @@ import com.fr.base.TableDataBean; import com.fr.config.RemoteConfigEvent; import com.fr.data.MultiResultTableData; import com.fr.data.TableDataSource; -import com.fr.data.impl.*; -import com.fr.data.impl.storeproc.StoreProcedure; -import com.fr.data.metric.utils.DatabaseConnectionMetricHandler; import com.fr.design.data.BasicTableDataUtils; import com.fr.design.data.DesignTableDataManager; -import com.fr.design.data.MapCompareUtils; import com.fr.design.dialog.FineJOptionPane; import com.fr.design.gui.controlpane.JListControlPane; import com.fr.design.gui.controlpane.NameableCreator; @@ -23,7 +19,6 @@ import com.fr.file.TableDataOperator; import com.fr.file.TableDataOperatorImpl; import com.fr.general.ComparatorUtils; import com.fr.general.NameObject; -import com.fr.general.jsqlparser.schema.Table; import com.fr.log.FineLoggerFactory; import com.fr.rpc.ExceptionHandler; import com.fr.rpc.RPCInvokerExceptionInfo; @@ -37,8 +32,12 @@ import com.fr.workspace.WorkContext; import javax.swing.DefaultListModel; import javax.swing.JPanel; import javax.swing.SwingUtilities; -import java.util.*; -import java.util.stream.Collectors; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; /** * TableDataList Pane. @@ -47,8 +46,6 @@ public class TableDataPaneListPane extends JListControlPane implements TableData private boolean isNamePermitted = true; private Map dsNameChangedMap = new HashMap<>(); - private final Map populatedTableDataSnapshot = new LinkedHashMap<>(); - public TableDataPaneListPane() { super(); dsNameChangedMap.clear(); @@ -228,12 +225,10 @@ public class TableDataPaneListPane extends JListControlPane implements TableData while (nameIt.hasNext()) { String name = nameIt.next(); nameObjectList.add(new NameObject(name, tableDataConfig.getTableData(name))); - populatedTableDataSnapshot.put(name, tableDataConfig.getTableData(name)); } while (procedurenameIt.hasNext()) { String name = procedurenameIt.next(); nameObjectList.add(new NameObject(name, ProcedureConfig.getInstance().getProcedure(name))); - populatedTableDataSnapshot.put(name, ProcedureConfig.getInstance().getProcedure(name)); } populate(nameObjectList.toArray(new NameObject[0])); @@ -250,7 +245,6 @@ public class TableDataPaneListPane extends JListControlPane implements TableData return saveByOldWay(tableDataBeans); } }).saveTableData(new ArrayList<>(tableDataConfig.getTableDatas().keySet()), tableDataBeans); - logOperateMessage(populatedTableDataSnapshot, getUpdateTableDataMap(tableDataBeans)); if (!WorkContext.getCurrent().isLocal()) { EventDispatcher.fire(RemoteConfigEvent.EDIT, TableDataConfig.getInstance().getNameSpace()); } @@ -278,57 +272,6 @@ public class TableDataPaneListPane extends JListControlPane implements TableData } return tableDataBeans; } - - private Map getUpdateTableDataMap(List tableDataBeans) { - Map updateTableDataMap = new HashMap<>(); - for (TableDataBean bean : tableDataBeans) { - updateTableDataMap.put(bean.getName(), bean.getTableData()); - } - return updateTableDataMap; - } - - private void logOperateMessage(Map old, Map newMap) { - List add = new ArrayList<>(); - List update = new ArrayList<>(); - List delete = new ArrayList<>(); - MapCompareUtils.contrastMapEntries(old, newMap, (entryEventKind, s, tableData) -> { - switch (entryEventKind) { - case REMOVED: - delete.add(s); - break; - case ADDED: - add.add(s); - break; - case UPDATED: - update.add(s); - break; - default: - break; - } - }, new MapCompareUtils.UpdateRule() { - @Override - public boolean needUpdate(TableData old, TableData update) { - return !update.equals(old) || !isEmbedConnection(update); - } - - /** - * 是否是主工程里内置的TableData - */ - private boolean isEmbedConnection(TableData tableData) { - return tableData instanceof DBTableData || - tableData instanceof ClassTableData || - tableData instanceof EmbeddedTableData || - tableData instanceof FileTableData || - tableData instanceof RecursionTableData || - tableData instanceof ConditionTableData || - tableData instanceof StoreProcedure; - } - }); - - WorkContext.getCurrent().get(TableDataOperator.class).logOperateMessage(add, update, delete); - } - - private boolean saveByOldWay(List tableDataBean) { try { return TableDataOperatorImpl.getInstance().saveTableData(tableDataBean); diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionListPane.java b/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionListPane.java index 87b1c404f3..6bfd0a37f0 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionListPane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionListPane.java @@ -9,7 +9,7 @@ import com.fr.data.impl.JNDIDatabaseConnection; import com.fr.data.metric.utils.DatabaseConnectionMetricHandler; import com.fr.data.operator.DataOperator; import com.fr.design.ExtraDesignClassManager; -import com.fr.design.data.MapCompareUtils; +import com.fr.general.MapCompareUtils; import com.fr.design.dialog.BasicDialog; import com.fr.design.fun.ConnectionProvider; import com.fr.design.gui.controlpane.JListControlPane; diff --git a/designer-base/src/test/java/com/fr/design/data/MapCompareUtilsTest.java b/designer-base/src/test/java/com/fr/design/data/MapCompareUtilsTest.java index 1f1e60e2be..97f3cb7dc4 100644 --- a/designer-base/src/test/java/com/fr/design/data/MapCompareUtilsTest.java +++ b/designer-base/src/test/java/com/fr/design/data/MapCompareUtilsTest.java @@ -1,5 +1,6 @@ package com.fr.design.data; +import com.fr.general.MapCompareUtils; import org.junit.Assert; import org.junit.Test;