Browse Source

REPORT-107992 改一下实现 & 格式优化

release/11.0
obo 1 year ago
parent
commit
050439e1db
  1. 93
      designer-base/src/main/java/com/fr/design/data/MapCompareUtils.java
  2. 69
      designer-base/src/main/java/com/fr/design/data/datapane/TableDataPaneListPane.java
  3. 2
      designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionListPane.java
  4. 1
      designer-base/src/test/java/com/fr/design/data/MapCompareUtilsTest.java

93
designer-base/src/main/java/com/fr/design/data/MapCompareUtils.java

@ -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 查找出相比origother中有哪些是新增的删除的或者被修改的并分别进行处理
*
* 对比时默认用equals方法来判断是否为 EntryEventKind#UPDATED
*
* @param orig 原始map
* @param other 参考的新map
* @param eventHandler 有区别时的事件处理器
* @param <K> K
* @param <V> V
*/
public static <K, V> void contrastMapEntries(@NotNull Map<K, V> orig, @NotNull Map<K, V> other, @NotNull EventHandler<K, V> eventHandler) {
contrastMapEntries(orig, other, eventHandler, UpdateRule.DEFAULT);
}
/**
* 对比两个map 查找出相比origother中有哪些是新增的删除的或者被修改的并分别进行处理
*
* 对比时用自定义的规则来判断是否为 EntryEventKind#UPDATED
*
* @param orig 原始map
* @param other 参考的新map
* @param eventHandler 有区别时的事件处理器
* @param updateRule 自定义的Update事件判定规则
* @param <K>
* @param <V>
*/
public static <K, V> void contrastMapEntries(@NotNull Map<K, V> orig, @NotNull Map<K, V> other, @NotNull EventHandler<K, V> eventHandler, @NotNull UpdateRule<K, V> updateRule) {
Map<K, V> 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 <K>
* @param <V>
*/
public interface EventHandler<K, V> {
void on(EntryEventKind entryEventKind, K k, V v);
}
/**
* 数据被修改(EntryEventKind.UPDATED) 的判定规则
* @param <K>
* @param <V>
*/
public interface UpdateRule<K, V> {
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;
}
}

69
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<String, String> dsNameChangedMap = new HashMap<>();
private final Map<String, TableData> 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<String, TableData> getUpdateTableDataMap(List<TableDataBean> tableDataBeans) {
Map<String, TableData> updateTableDataMap = new HashMap<>();
for (TableDataBean bean : tableDataBeans) {
updateTableDataMap.put(bean.getName(), bean.getTableData());
}
return updateTableDataMap;
}
private void logOperateMessage(Map<String, TableData> old, Map<String, TableData> newMap) {
List<String> add = new ArrayList<>();
List<String> update = new ArrayList<>();
List<String> 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<String, TableData>() {
@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> tableDataBean) {
try {
return TableDataOperatorImpl.getInstance().saveTableData(tableDataBean);

2
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;

1
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;

Loading…
Cancel
Save