Browse Source

REPORT-107992 【日志记录数据连接操作】设计器修改数据连接和数据集名称后操作日志会记录大片不好区分

newui
obo 1 year ago
parent
commit
6176bc6666
  1. 100
      designer-base/src/main/java/com/fr/design/data/datapane/TableDataPaneListPane.java

100
designer-base/src/main/java/com/fr/design/data/datapane/TableDataPaneListPane.java

@ -5,8 +5,12 @@ import com.fr.base.TableDataBean;
import com.fr.config.RemoteConfigEvent; import com.fr.config.RemoteConfigEvent;
import com.fr.data.MultiResultTableData; import com.fr.data.MultiResultTableData;
import com.fr.data.TableDataSource; 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.BasicTableDataUtils;
import com.fr.design.data.DesignTableDataManager; import com.fr.design.data.DesignTableDataManager;
import com.fr.design.data.MapCompareUtils;
import com.fr.design.dialog.FineJOptionPane; import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.gui.controlpane.JListControlPane; import com.fr.design.gui.controlpane.JListControlPane;
import com.fr.design.gui.controlpane.NameableCreator; import com.fr.design.gui.controlpane.NameableCreator;
@ -19,6 +23,7 @@ import com.fr.file.TableDataOperator;
import com.fr.file.TableDataOperatorImpl; import com.fr.file.TableDataOperatorImpl;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.general.NameObject; import com.fr.general.NameObject;
import com.fr.general.jsqlparser.schema.Table;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
import com.fr.rpc.ExceptionHandler; import com.fr.rpc.ExceptionHandler;
import com.fr.rpc.RPCInvokerExceptionInfo; import com.fr.rpc.RPCInvokerExceptionInfo;
@ -32,12 +37,8 @@ import com.fr.workspace.WorkContext;
import javax.swing.DefaultListModel; import javax.swing.DefaultListModel;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import java.util.ArrayList; import java.util.*;
import java.util.Collection; import java.util.stream.Collectors;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/** /**
* TableDataList Pane. * TableDataList Pane.
@ -46,6 +47,8 @@ public class TableDataPaneListPane extends JListControlPane implements TableData
private boolean isNamePermitted = true; private boolean isNamePermitted = true;
private Map<String, String> dsNameChangedMap = new HashMap<>(); private Map<String, String> dsNameChangedMap = new HashMap<>();
private final Map<String, TableData> populatedTableDataSnapshot = new LinkedHashMap<>();
public TableDataPaneListPane() { public TableDataPaneListPane() {
super(); super();
dsNameChangedMap.clear(); dsNameChangedMap.clear();
@ -225,10 +228,12 @@ public class TableDataPaneListPane extends JListControlPane implements TableData
while (nameIt.hasNext()) { while (nameIt.hasNext()) {
String name = nameIt.next(); String name = nameIt.next();
nameObjectList.add(new NameObject(name, tableDataConfig.getTableData(name))); nameObjectList.add(new NameObject(name, tableDataConfig.getTableData(name)));
populatedTableDataSnapshot.put(name, tableDataConfig.getTableData(name));
} }
while (procedurenameIt.hasNext()) { while (procedurenameIt.hasNext()) {
String name = procedurenameIt.next(); String name = procedurenameIt.next();
nameObjectList.add(new NameObject(name, ProcedureConfig.getInstance().getProcedure(name))); nameObjectList.add(new NameObject(name, ProcedureConfig.getInstance().getProcedure(name)));
populatedTableDataSnapshot.put(name, ProcedureConfig.getInstance().getProcedure(name));
} }
populate(nameObjectList.toArray(new NameObject[0])); populate(nameObjectList.toArray(new NameObject[0]));
@ -236,17 +241,7 @@ public class TableDataPaneListPane extends JListControlPane implements TableData
@Override @Override
public void update(TableDataConfig tableDataConfig) { public void update(TableDataConfig tableDataConfig) {
Nameable[] tableDataArray = this.update(); List<TableDataBean> tableDataBeans = getUpdateTableDataBeans();
List<TableDataBean> tableDataBeans = new ArrayList<>();
Map<String, String> map = MapUtils.invertMap(getDsNameChangedMap());
for (int i = 0; i < tableDataArray.length; i++) {
NameObject nameObject = (NameObject) tableDataArray[i];
String oldName = map.get(nameObject.getName());
if (oldName == null) {
oldName = StringUtils.EMPTY;
}
tableDataBeans.add(new TableDataBean(nameObject.getName(), oldName, (TableData) nameObject.getObject()));
}
try { try {
WorkContext.getCurrent().get(TableDataOperator.class, new ExceptionHandler() { WorkContext.getCurrent().get(TableDataOperator.class, new ExceptionHandler() {
@Override @Override
@ -255,6 +250,7 @@ public class TableDataPaneListPane extends JListControlPane implements TableData
return saveByOldWay(tableDataBeans); return saveByOldWay(tableDataBeans);
} }
}).saveTableData(new ArrayList<>(tableDataConfig.getTableDatas().keySet()), tableDataBeans); }).saveTableData(new ArrayList<>(tableDataConfig.getTableDatas().keySet()), tableDataBeans);
logOperateMessage(populatedTableDataSnapshot, getUpdateTableDataMap(tableDataBeans));
if (!WorkContext.getCurrent().isLocal()) { if (!WorkContext.getCurrent().isLocal()) {
EventDispatcher.fire(RemoteConfigEvent.EDIT, TableDataConfig.getInstance().getNameSpace()); EventDispatcher.fire(RemoteConfigEvent.EDIT, TableDataConfig.getInstance().getNameSpace());
} }
@ -263,6 +259,76 @@ public class TableDataPaneListPane extends JListControlPane implements TableData
} }
} }
/**
* 获取更新时的数据集快照
*
* @return 快照
*/
private List<TableDataBean> getUpdateTableDataBeans() {
Nameable[] tableDataArray = this.update();
List<TableDataBean> tableDataBeans = new ArrayList<>();
Map<String, String> map = MapUtils.invertMap(getDsNameChangedMap());
for (Nameable nameable : tableDataArray) {
NameObject nameObject = (NameObject) nameable;
String oldName = map.get(nameObject.getName());
if (oldName == null) {
oldName = StringUtils.EMPTY;
}
tableDataBeans.add(new TableDataBean(nameObject.getName(), oldName, (TableData) nameObject.getObject()));
}
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) { private boolean saveByOldWay(List<TableDataBean> tableDataBean) {
try { try {
return TableDataOperatorImpl.getInstance().saveTableData(tableDataBean); return TableDataOperatorImpl.getInstance().saveTableData(tableDataBean);

Loading…
Cancel
Save