Browse Source

REPORT-75140 抽象出一个多结果数据集

feature/x
rinoux 2 years ago
parent
commit
829ee8999c
  1. 22
      designer-base/src/main/java/com/fr/design/data/BasicTableDataTreePane.java
  2. 83
      designer-base/src/main/java/com/fr/design/data/DesignTableDataManager.java
  3. 73
      designer-base/src/main/java/com/fr/design/data/datapane/TableDataSourceOP.java
  4. 4
      designer-base/src/main/java/com/fr/design/data/datapane/TableDataTree.java
  5. 10
      designer-base/src/main/java/com/fr/design/data/datapane/management/search/control/common/TableDataSearchTask.java
  6. 25
      designer-base/src/main/java/com/fr/design/data/datapane/preview/PreviewTablePane.java
  7. 8
      designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/ProcedureDataPane.java
  8. 150
      designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/MultiResultTableDataNameWrapper.java
  9. 296
      designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/MultiResultTableDataWrapper.java
  10. 3
      designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/StoreProcedureDataWrapper.java
  11. 3
      designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/StoreProcedureNameWrapper.java

22
designer-base/src/main/java/com/fr/design/data/BasicTableDataTreePane.java

@ -2,9 +2,9 @@ package com.fr.design.data;
import com.fr.base.BaseUtils;
import com.fr.base.TableData;
import com.fr.data.MultiResultTableData;
import com.fr.data.TableDataSource;
import com.fr.data.api.StoreProcedureAssist;
import com.fr.data.impl.storeproc.StoreProcedure;
import com.fr.design.DesignModelAdapter;
import com.fr.design.actions.UpdateAction;
import com.fr.design.data.datapane.TableDataCreatorProducer;
@ -13,7 +13,7 @@ import com.fr.design.data.datapane.TableDataSourceOP;
import com.fr.design.data.datapane.TableDataTree;
import com.fr.design.data.tabledata.ResponseDataSourceChange;
import com.fr.design.data.tabledata.tabledatapane.AbstractTableDataPane;
import com.fr.design.data.tabledata.wrapper.StoreProcedureDataWrapper;
import com.fr.design.data.tabledata.wrapper.MultiResultTableDataWrapper;
import com.fr.design.data.tabledata.wrapper.TableDataWrapper;
import com.fr.design.data.tabledata.wrapper.TemplateTableDataWrapper;
import com.fr.design.dialog.BasicDialog;
@ -441,16 +441,16 @@ public abstract class BasicTableDataTreePane extends DockingView implements Resp
data = selectedNO.getObject();
}
try {
if (((TableDataWrapper) Objects.requireNonNull(data)).getTableData() instanceof StoreProcedure) {
((StoreProcedure) (((TableDataWrapper) data).getTableData())).resetDataModelList();
if (data instanceof StoreProcedureDataWrapper) {
StoreProcedureDataWrapper oldSdw = ((StoreProcedureDataWrapper) data);
StoreProcedureDataWrapper newSdw = new StoreProcedureDataWrapper((StoreProcedure) oldSdw.getTableData(), oldSdw.getStoreprocedureName(), oldSdw.getTableDataName());
newSdw.previewData(StoreProcedureDataWrapper.PREVIEW_ONE);
if (((TableDataWrapper) Objects.requireNonNull(data)).getTableData() instanceof MultiResultTableData) {
((MultiResultTableData<?>) (((TableDataWrapper) data).getTableData())).resetDataModelList();
if (data instanceof MultiResultTableDataWrapper) {
MultiResultTableDataWrapper oldSdw = ((MultiResultTableDataWrapper) data);
MultiResultTableDataWrapper newSdw = new MultiResultTableDataWrapper((MultiResultTableData<?>) oldSdw.getTableData(), oldSdw.getTableDataName(), oldSdw.getTableDataName());
newSdw.previewData(MultiResultTableDataWrapper.PREVIEW_ONE);
} else {
StoreProcedure storeProcedure = (StoreProcedure) ((TableDataWrapper) data).getTableData();
StoreProcedureDataWrapper storeProcedureDataWrapper = new StoreProcedureDataWrapper(storeProcedure, StringUtils.EMPTY, StringUtils.EMPTY);
storeProcedureDataWrapper.previewData(StoreProcedureDataWrapper.PREVIEW_ALL);
MultiResultTableData<?> tableData = (MultiResultTableData<?>) ((TableDataWrapper) data).getTableData();
MultiResultTableDataWrapper storeProcedureDataWrapper = new MultiResultTableDataWrapper(tableData, StringUtils.EMPTY, StringUtils.EMPTY);
storeProcedureDataWrapper.previewData(MultiResultTableDataWrapper.PREVIEW_ALL);
}
} else {
((TableDataWrapper) data).previewData();

83
designer-base/src/main/java/com/fr/design/data/DesignTableDataManager.java

@ -3,19 +3,20 @@ package com.fr.design.data;
import com.fr.base.StoreProcedureParameter;
import com.fr.base.TableData;
import com.fr.concurrent.NamedThreadFactory;
import com.fr.data.MultiResultTableData;
import com.fr.data.TableDataSource;
import com.fr.data.TableDataSourceTailor;
import com.fr.data.core.DataCoreXmlUtils;
import com.fr.data.impl.EmbeddedTableData;
import com.fr.data.impl.storeproc.ProcedureDataModel;
import com.fr.data.impl.NameDataModel;
import com.fr.data.impl.storeproc.StoreProcedure;
import com.fr.data.impl.storeproc.StoreProcedureConstants;
import com.fr.data.operator.DataOperator;
import com.fr.design.DesignModelAdapter;
import com.fr.design.data.datapane.preview.PreviewTablePane;
import com.fr.design.data.tabledata.wrapper.MultiResultTableDataNameWrapper;
import com.fr.design.data.tabledata.wrapper.MultiResultTableDataWrapper;
import com.fr.design.data.tabledata.wrapper.ServerTableDataWrapper;
import com.fr.design.data.tabledata.wrapper.StoreProcedureDataWrapper;
import com.fr.design.data.tabledata.wrapper.StoreProcedureNameWrapper;
import com.fr.design.data.tabledata.wrapper.TableDataFactory;
import com.fr.design.data.tabledata.wrapper.TableDataWrapper;
import com.fr.design.data.tabledata.wrapper.TemplateTableDataWrapper;
@ -325,28 +326,38 @@ public abstract class DesignTableDataManager {
while (entryIt.hasNext()) {
String key = entryIt.next().getKey();
TableDataWrapper tableDataWrapper = resMap.get(key);
if (tableDataWrapper.getTableData() instanceof StoreProcedure) {
StoreProcedure storeProcedure = (StoreProcedure) tableDataWrapper.getTableData();
boolean hasSchemaOrResult = false;
StoreProcedureParameter[] parameters = StoreProcedure.getSortPara(storeProcedure.getParameters());
if (tableDataWrapper.getTableData() instanceof MultiResultTableData) {
MultiResultTableData<?> tableData = (MultiResultTableData<?>) tableDataWrapper.getTableData();
String name = tableDataWrapper.getTableDataName();
List<String> resultNames = storeProcedure.getResultNames();
TableDataWrapper tdw = new StoreProcedureNameWrapper(name + "_Table", storeProcedure);
List<String> resultNames = tableData.getResultNames();
TableDataWrapper tdw = new MultiResultTableDataNameWrapper(name + "_Table", tableData);
boolean hasSchemaOrResult = false;
for (StoreProcedureParameter parameter : parameters) {
if (parameter.getSchema() != StoreProcedureConstants.IN) {
String parameterName = name + "_" + parameter.getName();
TableDataWrapper newTwd = new StoreProcedureDataWrapper(storeProcedure, name, parameterName, false);
dsMap.put(parameterName, newTwd);
hasSchemaOrResult = true;
if (tableData instanceof StoreProcedure) {
StoreProcedure storeProcedure = (StoreProcedure) tableData;
StoreProcedureParameter[] parameters = StoreProcedure.getSortPara(storeProcedure.getParameters());
for (StoreProcedureParameter parameter : parameters) {
if (parameter.getSchema() != StoreProcedureConstants.IN) {
String parameterName = name + "_" + parameter.getName();
TableDataWrapper newTwd = new MultiResultTableDataWrapper(storeProcedure, name, parameterName, false);
dsMap.put(parameterName, newTwd);
hasSchemaOrResult = true;
}
}
} else {
for (NameDataModel nameDataModel : tableData.getDataModelList()) {
String dmName = name + "_" + nameDataModel.getName();
dsMap.put(nameDataModel.getName(), new MultiResultTableDataWrapper(tableData, name, dmName, false));
}
}
if (!resultNames.isEmpty()) {
hasSchemaOrResult = true;
for (int i = 0; i < resultNames.size(); i++) {
String parameterName = name + "_" + resultNames.get(i);
TableDataWrapper newTwd = new StoreProcedureDataWrapper(storeProcedure, name, parameterName, false);
TableDataWrapper newTwd = new MultiResultTableDataWrapper(tableData, name, parameterName, false);
dsMap.put(parameterName, newTwd);
}
}
@ -429,7 +440,7 @@ public abstract class DesignTableDataManager {
if (globalDsCache.containsKey(name)) {
resMap.put(name, globalDsCache.get(name));
} else {
TableDataWrapper tdw = new StoreProcedureNameWrapper(name, storeProcedure);
TableDataWrapper tdw = new MultiResultTableDataNameWrapper(name, storeProcedure);
resMap.put(name, tdw);
globalDsCache.put(name, tdw);
}
@ -599,29 +610,35 @@ public abstract class DesignTableDataManager {
* 所以用该方法不会对一个已经计算了的存储过程重复计算.和分页预览时处理机制一样这样对有多个返回数据集的存储过程来说很有必要
*
* @param needLoadingBar 是否需要进度条
* @param storeProcedure 存储过程
* @param tableData 存储过程
* @return 数据
*/
public static ProcedureDataModel[] createLazyDataModel(StoreProcedure storeProcedure, boolean needLoadingBar) throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
XMLPrintWriter writer = XMLPrintWriter.create(out);
// 把storeProcedure写成xml文件到out
DataCoreXmlUtils.writeXMLStoreProcedure(writer, storeProcedure, null);
if (storeProcedure.getDataModelSize() > 0 && !storeProcedure.isFirstExpand()) {
return storeProcedure.creatLazyDataModel();
}
ParameterProvider[] inParameters = DataOperator.getInstance().getStoreProcedureParameters(storeProcedure);
public static NameDataModel[] createLazyDataModel(MultiResultTableData<?> tableData, boolean needLoadingBar) throws Exception {
Map<String, Object> parameterMap = new HashMap<>();
if (inParameters.length > 0 && !ComparatorUtils.equals(threadLocal.get(), NO_PARAMETER)) {// 检查Parameter.
showParaWindow(parameterMap, inParameters);
if (tableData instanceof StoreProcedure) {
StoreProcedure storeProcedure = (StoreProcedure) tableData;
ByteArrayOutputStream out = new ByteArrayOutputStream();
XMLPrintWriter writer = XMLPrintWriter.create(out);
// 把storeProcedure写成xml文件到out
DataCoreXmlUtils.writeXMLStoreProcedure(writer, storeProcedure, null);
if (storeProcedure.getDataModelSize() > 0 && !storeProcedure.isFirstExpand()) {
return storeProcedure.creatLazyDataModel();
}
ParameterProvider[] inParameters = DataOperator.getInstance().getStoreProcedureParameters(storeProcedure);
if (inParameters.length > 0 && !ComparatorUtils.equals(threadLocal.get(), NO_PARAMETER)) {// 检查Parameter.
showParaWindow(parameterMap, inParameters);
}
storeProcedure.setFirstExpand(false);
}
storeProcedure.setFirstExpand(false);
// 存储过程有些特殊处理
// 这个就简单直接获取暂存列表吧
// TODO 参数处理?
if (needLoadingBar) {
StoreProcedureDataWrapper.loadingBar.start();
MultiResultTableDataWrapper.loadingBar.start();
}
return DataOperator.getInstance().previewProcedureDataModel(storeProcedure, parameterMap, 0);
return DataOperator.getInstance().previewRichTableData(tableData, parameterMap, 0);
}
private static void showParaWindow(final Map<String, Object> parameterMap, ParameterProvider[] inParameters) {

73
designer-base/src/main/java/com/fr/design/data/datapane/TableDataSourceOP.java

@ -2,20 +2,25 @@ package com.fr.design.data.datapane;
import com.fr.base.StoreProcedureParameter;
import com.fr.base.TableData;
import com.fr.data.MultiResultTableData;
import com.fr.data.TableDataSource;
import com.fr.data.impl.NameDataModel;
import com.fr.data.impl.storeproc.StoreProcedure;
import com.fr.data.impl.storeproc.StoreProcedureConstants;
import com.fr.design.DesignModelAdapter;
import com.fr.design.data.DesignTableDataManager;
import com.fr.design.data.tabledata.wrapper.StoreProcedureDataWrapper;
import com.fr.design.data.tabledata.wrapper.StoreProcedureNameWrapper;
import com.fr.design.data.tabledata.wrapper.MultiResultTableDataNameWrapper;
import com.fr.design.data.tabledata.wrapper.MultiResultTableDataWrapper;
import com.fr.design.data.tabledata.wrapper.TableDataWrapper;
import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode;
import com.fr.design.gui.itree.refreshabletree.UserObjectOP;
import com.fr.general.NameObject;
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
/**
@ -155,9 +160,9 @@ public class TableDataSourceOP implements UserObjectOP<TableDataWrapper> {
list.add(initStoreProcedureNode(storeProcedureMap));
for (int i = 0; i < getNodeArrayFromMap(storeProcedureMap).length; i++) {
ExpandMutableTreeNode tmpNode = getNodeArrayFromMap(storeProcedureMap)[i];
if (((NameObject) tmpNode.getUserObject()).getObject() instanceof StoreProcedureNameWrapper) {
TableData tableData = ((StoreProcedureNameWrapper) (((NameObject) tmpNode.getUserObject()).getObject())).getStoreProcedure();
setStoreProcedureTree(tableData, tmpNode);
if (((NameObject) tmpNode.getUserObject()).getObject() instanceof MultiResultTableDataNameWrapper) {
TableData tableData = ((MultiResultTableDataNameWrapper) (((NameObject) tmpNode.getUserObject()).getObject())).getTableData();
setStoreProcedureTree((MultiResultTableData<?>) tableData, tmpNode);
serverlist.add(tmpNode);
}
}
@ -176,8 +181,8 @@ public class TableDataSourceOP implements UserObjectOP<TableDataWrapper> {
for (int i = 0; i < getNodeArrayFromMap(dataMap).length; i++) {
ExpandMutableTreeNode tmpNode = getNodeArrayFromMap(dataMap)[i];
TableData tableData = ((TableDataWrapper) (((NameObject) tmpNode.getUserObject()).getObject())).getTableData();
if (tableData instanceof StoreProcedure) {
setStoreProcedureTree(tableData, tmpNode);
if (tableData instanceof MultiResultTableData<?>) {
setStoreProcedureTree((MultiResultTableData<?>) tableData, tmpNode);
dataList.add(tmpNode);
} else {
dataList.add(tmpNode);
@ -185,39 +190,57 @@ public class TableDataSourceOP implements UserObjectOP<TableDataWrapper> {
}
}
protected void setStoreProcedureTree(TableData tableData, ExpandMutableTreeNode tmpNode) {
protected void setStoreProcedureTree(MultiResultTableData<?> tableData, ExpandMutableTreeNode tmpNode) {
ArrayList<String> nodeName = new ArrayList<>();
StoreProcedure storeProcedure = (StoreProcedure) tableData;
String name = ((NameObject) tmpNode.getUserObject()).getName();
StoreProcedureParameter[] parameters = StoreProcedure.getSortPara(storeProcedure.getParameters());
List<String> resultNames = storeProcedure.getResultNames();
List<String> resultNames = tableData.getResultNames();
boolean hasChild = false;
tmpNode.remove(0);
TableDataWrapper tdw = new StoreProcedureNameWrapper(name + "_Table1", storeProcedure);
TableDataWrapper tdw = new MultiResultTableDataNameWrapper(name + "_Table1", tableData);
ExpandMutableTreeNode childNode = new ExpandMutableTreeNode(new NameObject("Table", tdw));
childNode.add(new ExpandMutableTreeNode());
tmpNode.add(childNode);
for (StoreProcedureParameter parameter : parameters) {
if (parameter.getSchema() != StoreProcedureConstants.IN) {
if (!nodeName.contains(parameter.getName())) {
nodeName.add(parameter.getName());
hasChild = true;
String parameterName = name + "_" + parameter.getName();
TableDataWrapper newTwd = new StoreProcedureDataWrapper(storeProcedure, name, parameterName, false);
ExpandMutableTreeNode newChildNode = new ExpandMutableTreeNode(new NameObject(parameter.getName(), newTwd));
newChildNode.add(new ExpandMutableTreeNode());
tmpNode.add(newChildNode);
if (tableData instanceof StoreProcedure) {
StoreProcedure storeProcedure = (StoreProcedure) tableData;
StoreProcedureParameter[] parameters = StoreProcedure.getSortPara(storeProcedure.getParameters());
for (StoreProcedureParameter parameter : parameters) {
if (parameter.getSchema() != StoreProcedureConstants.IN) {
if (!nodeName.contains(parameter.getName())) {
nodeName.add(parameter.getName());
hasChild = true;
String parameterName = name + "_" + parameter.getName();
TableDataWrapper newTwd = new MultiResultTableDataWrapper(tableData, name, parameterName, false);
ExpandMutableTreeNode newChildNode = new ExpandMutableTreeNode(new NameObject(parameter.getName(), newTwd));
newChildNode.add(new ExpandMutableTreeNode());
tmpNode.add(newChildNode);
}
}
}
} else {
if (tableData.getDataModelList().size() > 1) {
for (NameDataModel nameDataModel : tableData.getDataModelList()) {
if (!nodeName.contains(nameDataModel.getName())) {
nodeName.add(nameDataModel.getName());
hasChild = true;
String parameterName = name + "_" + nameDataModel.getName();
TableDataWrapper newTwd = new MultiResultTableDataWrapper(tableData, name, parameterName, false);
ExpandMutableTreeNode newChildNode = new ExpandMutableTreeNode(new NameObject(nameDataModel.getName(), newTwd));
newChildNode.add(new ExpandMutableTreeNode());
tmpNode.add(newChildNode);
}
}
}
}
if (!resultNames.isEmpty()) {
for (String resultName : resultNames) {
if (!nodeName.contains(resultName)) {
nodeName.add(resultName);
hasChild = true;
String parameterName = name + "_" + resultName;
TableDataWrapper newTwd = new StoreProcedureDataWrapper(storeProcedure, name, parameterName, false);
TableDataWrapper newTwd = new MultiResultTableDataWrapper(tableData, name, parameterName, false);
ExpandMutableTreeNode newChildNode = new ExpandMutableTreeNode(new NameObject(resultName, newTwd));
newChildNode.add(new ExpandMutableTreeNode());
tmpNode.add(newChildNode);

4
designer-base/src/main/java/com/fr/design/data/datapane/TableDataTree.java

@ -1,7 +1,7 @@
package com.fr.design.data.datapane;
import com.fr.base.BaseUtils;
import com.fr.data.impl.storeproc.StoreProcedure;
import com.fr.data.MultiResultTableData;
import com.fr.design.constants.UIConstants;
import com.fr.design.data.datapane.management.search.TableDataTreeSearchManager;
import com.fr.design.data.tabledata.wrapper.AbstractTableDataWrapper;
@ -462,7 +462,7 @@ public class TableDataTree extends UserObjectRefreshJTree<TableDataSourceOP> {
if (userObject instanceof NameObject) {
NameObject nameObject = (NameObject) userObject;
TableDataWrapper tableDataWrapper = (TableDataWrapper) nameObject.getObject();
return tableDataWrapper.getTableData() instanceof StoreProcedure;
return tableDataWrapper.getTableData() instanceof MultiResultTableData<?>;
}
return false;
}

10
designer-base/src/main/java/com/fr/design/data/datapane/management/search/control/common/TableDataSearchTask.java

@ -3,7 +3,7 @@ package com.fr.design.data.datapane.management.search.control.common;
import com.fr.design.data.datapane.management.search.control.TreeSearchCallback;
import com.fr.design.data.datapane.management.search.control.TreeSearchResult;
import com.fr.design.data.datapane.management.search.control.TreeSearchTask;
import com.fr.design.data.tabledata.wrapper.StoreProcedureDataWrapper;
import com.fr.design.data.tabledata.wrapper.MultiResultTableDataWrapper;
import com.fr.design.data.tabledata.wrapper.TableDataWrapper;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.StringUtils;
@ -39,7 +39,7 @@ public class TableDataSearchTask implements TreeSearchTask {
TreeSearchResult result;
try {
if (isTableDataStoreProcedure(tableDataWrapper)) {
result = dealWithStoreProcedureTableDataWrapper((StoreProcedureDataWrapper) tableDataWrapper);
result = dealWithStoreProcedureTableDataWrapper((MultiResultTableDataWrapper) tableDataWrapper);
} else {
result = dealWithCommonTableDataWrapper(tableDataWrapper);
}
@ -87,11 +87,11 @@ public class TableDataSearchTask implements TreeSearchTask {
*
* @param procedureDataWrapper
*/
private TreeSearchResult dealWithStoreProcedureTableDataWrapper(StoreProcedureDataWrapper procedureDataWrapper) {
private TreeSearchResult dealWithStoreProcedureTableDataWrapper(MultiResultTableDataWrapper procedureDataWrapper) {
// 存储过程数据集名称,例如 Proc1_Table1
String tableDataName = procedureDataWrapper.getTableDataName();
// 存储过程名称,例如 Proc1
String storeProcedureName = procedureDataWrapper.getStoreprocedureName();
String storeProcedureName = procedureDataWrapper.getTableDataName();
// 存储过程子表名称,例如 Table1
String tableName = tableDataName.replaceFirst(storeProcedureName, StringUtils.EMPTY).replaceFirst("_", StringUtils.EMPTY);
boolean isStoreProcedureNameMatch = isMatchSearch(storeProcedureName, searchText);
@ -132,7 +132,7 @@ public class TableDataSearchTask implements TreeSearchTask {
* @return
*/
private boolean isTableDataStoreProcedure(TableDataWrapper tableDataWrapper) {
return tableDataWrapper instanceof StoreProcedureDataWrapper;
return tableDataWrapper instanceof MultiResultTableDataWrapper;
}
/**

25
designer-base/src/main/java/com/fr/design/data/datapane/preview/PreviewTablePane.java

@ -8,7 +8,8 @@ import com.fr.base.TableData;
import com.fr.data.TableDataSource;
import com.fr.data.impl.DBTableData;
import com.fr.data.impl.EmbeddedTableData;
import com.fr.data.impl.storeproc.ProcedureDataModel;
import com.fr.data.impl.NameDataModel;
import com.fr.data.operator.DataOperator;
import com.fr.design.DesignerEnvManager;
import com.fr.design.data.DesignTableDataManager;
@ -28,6 +29,7 @@ import com.fr.design.mainframe.DesignerContext;
import com.fr.design.ui.util.UIUtil;
import com.fr.function.TIME;
import com.fr.general.FRFont;
import com.fr.general.data.DataModel;
import com.fr.log.FineLoggerFactory;
import javax.swing.BorderFactory;
@ -55,6 +57,7 @@ import java.awt.event.MouseEvent;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.CancellationException;
/**
@ -62,13 +65,13 @@ import java.util.concurrent.CancellationException;
*/
public class PreviewTablePane extends BasicPane {
private TableData tableData;
private ProcedureDataModel storeProcedureDataModel;
private static UINumberField maxPreviewNumberField;
private NameDataModel dataModel;
private UINumberField maxPreviewNumberField;
private UINumberField currentRowsField;
private JTable preveiwTable;
private static AutoProgressBar progressBar;
private AutoProgressBar connectionBar;
private java.util.List<LoadedEventListener> listeners = new ArrayList<LoadedEventListener>();
private List<LoadedEventListener> listeners = new ArrayList<LoadedEventListener>();
private BasicDialog dialog;
private SwingWorker worker;
@ -152,7 +155,7 @@ public class PreviewTablePane extends BasicPane {
refreshLabel.setBackground(java.awt.Color.WHITE);
try {
populate(tableData);
if (storeProcedureDataModel != null) {
if (dataModel != null) {
populateStoreDataSQL();
}
} catch (Exception e1) {
@ -423,7 +426,7 @@ public class PreviewTablePane extends BasicPane {
*
* @param storeProcedureDataModel storeProcedureDataModel
*/
public static void previewStoreData(ProcedureDataModel storeProcedureDataModel) {
public static void previewStoreData(NameDataModel storeProcedureDataModel) {
previewStoreData(storeProcedureDataModel, -1, -1);
}
@ -434,9 +437,9 @@ public class PreviewTablePane extends BasicPane {
* @param keyIndex 实际值
* @param valueIndex 显示值
*/
public static void previewStoreData(final ProcedureDataModel storeProcedureDataModel, final int keyIndex, final int valueIndex) {
public static void previewStoreData(final NameDataModel storeProcedureDataModel, final int keyIndex, final int valueIndex) {
final PreviewTablePane previewTablePane = new PreviewTablePane();
previewTablePane.storeProcedureDataModel = storeProcedureDataModel;
previewTablePane.dataModel = storeProcedureDataModel;
previewTablePane.setBorder(BorderFactory.createTitledBorder(Toolkit.i18nText("Fine-Design_Basic_Data")));
try {
@ -462,12 +465,12 @@ public class PreviewTablePane extends BasicPane {
*
* @param storeProcedureDataModels storeProcedureDataModels
*/
public static void previewStoreDataWithAllDs(ProcedureDataModel[] storeProcedureDataModels) {
public static void previewStoreDataWithAllDs(NameDataModel[] storeProcedureDataModels) {
UITabbedPane tabPreviewpane = new UITabbedPane();
int tableSize = storeProcedureDataModels.length;
for (int i = 0; i < tableSize; i++) {
PreviewTablePane previewTablePane = new PreviewTablePane();
previewTablePane.storeProcedureDataModel = storeProcedureDataModels[i];
previewTablePane.dataModel = storeProcedureDataModels[i];
previewTablePane.setBorder(BorderFactory.createTitledBorder(Toolkit.i18nText("Fine-Design_Basic_Data")));
try {
previewTablePane.populateStoreDataSQL();
@ -493,7 +496,7 @@ public class PreviewTablePane extends BasicPane {
private void populateStoreDataSQL() throws Exception {
PreviewTableModel previewModel;
try {
previewModel = new PreviewTableModel(storeProcedureDataModel, (int) maxPreviewNumberField.getValue());
previewModel = new PreviewTableModel(dataModel, (int) maxPreviewNumberField.getValue());
} catch (Exception e) {
previewModel = new PreviewTableModel((int) maxPreviewNumberField.getValue());
}

8
designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/ProcedureDataPane.java

@ -19,7 +19,7 @@ import com.fr.design.data.datapane.connect.ConnectionTableProcedurePane.DoubleCl
import com.fr.design.data.datapane.sqlpane.SQLEditPane;
import com.fr.design.data.tabledata.ResponseDataSourceChange;
import com.fr.design.data.tabledata.StoreProcedureWorkerListener;
import com.fr.design.data.tabledata.wrapper.StoreProcedureDataWrapper;
import com.fr.design.data.tabledata.wrapper.MultiResultTableDataWrapper;
import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.gui.icheckbox.UICheckBox;
import com.fr.design.gui.icontainer.UIScrollPane;
@ -290,7 +290,7 @@ public class ProcedureDataPane extends AbstractTableDataPane<StoreProcedure> imp
protected Void doInBackground() throws Exception {
DesignTableDataManager.setThreadLocal(DesignTableDataManager.NO_PARAMETER);
sp.setCalculating(true);
ProcedureDataModel[] dataModels = DesignTableDataManager.createLazyDataModel(sp, false);
ProcedureDataModel[] dataModels = (ProcedureDataModel[]) DesignTableDataManager.createLazyDataModel(sp, false);
sp.refreshDataModelListAndResultNames(dataModels);
return null;
}
@ -382,8 +382,8 @@ public class ProcedureDataPane extends AbstractTableDataPane<StoreProcedure> imp
@Override
public void actionPerformed(ActionEvent evt) {
StoreProcedure sp = updateBeanWithOutExecute();
StoreProcedureDataWrapper storeProcedureDataWrapper = new StoreProcedureDataWrapper(this.procedureDataPane, sp, StringUtils.EMPTY, queryText.getText());
storeProcedureDataWrapper.previewData(StoreProcedureDataWrapper.PREVIEW_ALL);
MultiResultTableDataWrapper wrapper = new MultiResultTableDataWrapper(this.procedureDataPane, sp, StringUtils.EMPTY, queryText.getText());
wrapper.previewData(MultiResultTableDataWrapper.PREVIEW_ALL);
}
}

150
designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/MultiResultTableDataNameWrapper.java

@ -0,0 +1,150 @@
package com.fr.design.data.tabledata.wrapper;
import com.fr.base.BaseUtils;
import com.fr.base.TableData;
import com.fr.data.MultiResultTableData;
import com.fr.data.impl.NameDataModel;
import com.fr.design.data.DesignTableDataManager;
import com.fr.design.data.datapane.TableDataCreatorProducer;
import com.fr.design.data.datapane.TableDataNameObjectCreator;
import com.fr.design.data.datapane.preview.PreviewTablePane;
import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode;
import com.fr.log.FineLoggerFactory;
import com.fr.workspace.WorkContext;
import javax.swing.Icon;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* 多结果数据集-结果包装
*
* @author rinoux
* @version 11.0
* Created by rinoux on 2022/8/12
*/
public final class MultiResultTableDataNameWrapper implements TableDataWrapper {
private NameDataModel dataModel;
private final String name;
private final MultiResultTableData<?> tableData;
private List<String> columnNameList;
/**
* @param name 存储过程本身名字
* @param storeProcedure 存储过程
*/
public MultiResultTableDataNameWrapper(String name, MultiResultTableData<?> storeProcedure) {
this.name = name;
this.tableData = storeProcedure;
}
/**
* 生成子节点
*
* @return 子节点
*/
public ExpandMutableTreeNode[] load() {
List<String> namelist = calculateColumnNameList();
ExpandMutableTreeNode[] res = new ExpandMutableTreeNode[namelist.size()];
for (int i = 0; i < res.length; i++) {
res[i] = new ExpandMutableTreeNode(namelist.get(i));
}
return res;
}
@Override
public String getTableDataName() {
return name;
}
@Override
public TableData getTableData() {
return tableData;
}
@Override
public Icon getIcon() {
// TODO
for (TableDataNameObjectCreator creator : TableDataCreatorProducer.getInstance().createReportTableDataCreator()) {
if (creator.createObject().getClass() == this.tableData.getClass()) {
return BaseUtils.readIcon(creator.getIconPath());
}
}
return BaseUtils.readIcon("/com/fr/design/images/data/store_procedure.png");
}
private void createResult(boolean needLoadingBar) {
try {
dataModel = DesignTableDataManager.createLazyDataModel(tableData, needLoadingBar)[0];
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
/**
* 数据集执行结果返回的所有字段
* <p/>
* TODO:要不要加上Exception呢个人感觉很有必要
*
* @return 字段
*/
public List<String> calculateColumnNameList() {
if (columnNameList != null) {
return columnNameList;
}
columnNameList = new ArrayList<String>();
if (!WorkContext.getCurrent().isLocal()) {
try {
createResult(false);
columnNameList = Arrays.asList(dataModel.getColumnNames());
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
} else {
if (dataModel == null) {
createResult(false);
}
if (dataModel != null) {
columnNameList = Arrays.asList(dataModel.getColumnNames());
}
}
return columnNameList;
}
/**
* 预览数据集
*/
public void previewData() {
if (dataModel == null) {
createResult(true);
}
PreviewTablePane.previewStoreData(dataModel);
}
/**
* 预览数据集带有显示值和实际值的标记结果
*
* @param keyIndex 显示值Index
* @param valueIndex 实际值index
*/
public void previewData(int keyIndex, int valueIndex) {
if (dataModel == null) {
createResult(true);
}
PreviewTablePane.previewStoreData(dataModel, keyIndex, valueIndex);
}
/**
* 是否异常
*
* @return 异常返回true
*/
public boolean isUnusual() {
return false;
}
}

296
designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/MultiResultTableDataWrapper.java

@ -0,0 +1,296 @@
package com.fr.design.data.tabledata.wrapper;
import com.fr.base.BaseUtils;
import com.fr.base.TableData;
import com.fr.data.MultiResultTableData;
import com.fr.data.impl.NameDataModel;
import com.fr.data.impl.storeproc.StoreProcedure;
import com.fr.data.operator.DataOperator;
import com.fr.design.data.DesignTableDataManager;
import com.fr.design.data.datapane.TableDataCreatorProducer;
import com.fr.design.data.datapane.TableDataNameObjectCreator;
import com.fr.design.data.datapane.preview.PreviewTablePane;
import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.gui.iprogressbar.AutoProgressBar;
import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode;
import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.DesignerContext;
import com.fr.general.ComparatorUtils;
import com.fr.log.FineLoggerFactory;
import javax.swing.Icon;
import javax.swing.JFrame;
import javax.swing.SwingWorker;
import java.awt.Component;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CancellationException;
/**
* 多结果数据集包装
*
* @author rinoux
* @version 11.0
* Created by rinoux on 2022/8/12
*/
public final class MultiResultTableDataWrapper implements TableDataWrapper {
public static final int PREVIEW_ALL = 0;
public static final int PREVIEW_ONE = 1;
public static AutoProgressBar loadingBar;
private NameDataModel dataModel;
private final String dsName;
private final String tableDataName;
private final MultiResultTableData<?> tableData;
private List<String> columnNameList;
private AutoProgressBar connectionBar;
private NameDataModel[] dataModels;
private SwingWorker<?, ?> worker;
private int previewModel;
public MultiResultTableDataWrapper(MultiResultTableData<?> tableData, String tableDataName, String dsName) {
this(null, tableData, tableDataName, dsName, true);
}
public MultiResultTableDataWrapper(MultiResultTableData<?> tableData, String tableDataName, String dsName, boolean needLoad) {
this(null, tableData, tableDataName, dsName, needLoad);
}
public MultiResultTableDataWrapper(Component component, MultiResultTableData<?> tableData, String tableDataName, String dsName) {
this(component, tableData, tableDataName, dsName, true);
}
/**
* @param component loadingBar的父弹框如果不设置父弹框的话可能出现loadingBar隐藏在一个弹框后的情况
* @param tableData 存储过程
* @param tableDataName 存储过程的名字(某些情况下可以为空)
* @param dsName 存储过程一个返回数据集的名字
* @param needLoad 是否要加载
**/
public MultiResultTableDataWrapper(Component component, MultiResultTableData<?> tableData, String tableDataName, String dsName, boolean needLoad) {
this.dsName = dsName;
this.tableData = tableData;
this.tableData.setCalculating(false);
this.tableDataName = tableDataName;
if (component == null) {
component = new JFrame();
}
if (needLoad) {
setWorker(component);
}
loadingBar = new AutoProgressBar(component, Toolkit.i18nText("Fine-Design_Basic_Loading_Data"), "", 0, 100) {
@Override
public void doMonitorCanceled() {
getWorker().cancel(true);
}
};
}
/**
* 数据集执行结果返回的所有字段
*
* @return 数据集执行结果返回的所有字段
* @date 2014-12-3-下午7:43:17
*/
@Override
public List<String> calculateColumnNameList() {
if (columnNameList != null) {
return columnNameList;
}
try {
createResults(false);
} catch (Exception e) {
FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Basic_Engine_No_TableData"));
return new ArrayList<String>();
}
columnNameList = Arrays.asList(dataModel.getColumnNames());
return columnNameList;
}
/**
* 生成子节点
*
* @return 节点数组
* @date 2014-12-3-下午7:06:47
*/
@Override
public ExpandMutableTreeNode[] load() {
List<String> namelist;
if (tableData.isCalculating()) {
namelist = Arrays.asList(new String[0]);
} else {
namelist = calculateColumnNameList();
}
ExpandMutableTreeNode[] res = new ExpandMutableTreeNode[namelist.size()];
for (int i = 0; i < res.length; i++) {
res[i] = new ExpandMutableTreeNode(namelist.get(i));
}
return res;
}
private void createResults(boolean needLoadingBar) throws Exception {
dataModels = DesignTableDataManager.createLazyDataModel(tableData, needLoadingBar);
if (dataModels != null && dataModels.length != 0) {
for (NameDataModel dataModel : dataModels) {
if (ComparatorUtils.equals(this.dsName, tableDataName + "_" + dataModel.getName())) {
this.dataModel = dataModel;
break;
}
}
}
}
@Override
public Icon getIcon() {
for (TableDataNameObjectCreator creator : TableDataCreatorProducer.getInstance().createReportTableDataCreator()) {
if (creator.createObject().getClass() == this.tableData.getClass()) {
return BaseUtils.readIcon(creator.getIconPath());
}
}
return BaseUtils.readIcon("/com/fr/design/images/data/store_procedure.png");
}
/**
* 预览数据
*
* @param previewModel 预览模式, 全部还是一个
* @date 2014-12-3-下午7:05:50
*/
public void previewData(final int previewModel) {
this.previewModel = previewModel;
connectionBar = new AutoProgressBar(new JFrame(), Toolkit.i18nText("Fine-Design_Basic_Utils_Now_Create_Connection"), "", 0, 100) {
@Override
public void doMonitorCanceled() {
connectionBar.close();
worker.cancel(true);
}
};
worker.execute();
}
private void setWorker(final Component parent) {
worker = new SwingWorker<Void, Void>() {
@Override
protected Void doInBackground() throws Exception {
loadingBar.close();
PreviewTablePane.resetPreviewTable();
connectionBar.start();
if (tableData instanceof StoreProcedure) {
boolean status = DataOperator.getInstance().testConnection(((StoreProcedure) getTableData()).getDatabaseConnection());
if (!status) {
connectionBar.close();
throw new Exception(Toolkit.i18nText("Fine-Design_Basic_Database_Connection_Failed"));
}
}
connectionBar.close();
tableData.resetDataModelList();
createResults(true);
return null;
}
@Override
public void done() {
try {
get();
loadingBar.close();
switch (previewModel) {
case MultiResultTableDataWrapper.PREVIEW_ALL:
PreviewTablePane.previewStoreDataWithAllDs(dataModels);
break;
case MultiResultTableDataWrapper.PREVIEW_ONE:
previewData();
break;
default:
break;
}
} catch (Exception e) {
loadingBar.close();
if (!(e instanceof CancellationException)) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
FineJOptionPane.showMessageDialog(parent, e.getMessage());
}
}
}
};
}
private SwingWorker getWorker() {
return this.worker;
}
// august:这个只是预览返回的一个数据集
/**
* 预览返回的一个数据集
*
* @date 2014-12-3-下午7:42:53
*/
@Override
public void previewData() {
previewData(-1, -1);
}
// august:这个只是预览返回的一个数据集
/**
* 预览返回的一个数据集带有显示值和实际值的标记结果
*
* @param keyIndex 实际值
* @param valueIndex 显示值
* @date 2014-12-3-下午7:42:27
*/
@Override
public void previewData(final int keyIndex, final int valueIndex) {
PreviewTablePane.previewStoreData(dataModel, keyIndex, valueIndex);
}
/**
* 预览返回的所有数据集只有在编辑存储过程时才用到
*/
public void previewAllTable() {
if (dataModel == null) {
try {
createResults(true);
} catch (Exception e) {
return;
}
}
PreviewTablePane.previewStoreDataWithAllDs(dataModels);
}
@Override
public String getTableDataName() {
return dsName;
}
@Override
public TableData getTableData() {
return tableData;
}
/**
* 是否异常
*
* @return 是否异常
*/
@Override
public boolean isUnusual() {
return false;
}
@Override
public boolean equals(Object obj) {
return obj instanceof MultiResultTableDataWrapper
&& ComparatorUtils.equals(this.dsName, ((MultiResultTableDataWrapper) obj).getTableDataName())
&& ComparatorUtils.equals(this.tableData, ((MultiResultTableDataWrapper) obj).getTableData())
&& ComparatorUtils.equals(this.tableDataName, ((MultiResultTableDataWrapper) obj).getTableDataName());
}
}

3
designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/StoreProcedureDataWrapper.java

@ -37,6 +37,7 @@ import java.util.concurrent.CancellationException;
* @author zhou
* @since 2012-4-12上午10:29:15
*/
@Deprecated
public final class StoreProcedureDataWrapper implements TableDataWrapper {
public static final int PREVIEW_ALL = 0;
public static final int PREVIEW_ONE = 1;
@ -135,7 +136,7 @@ public final class StoreProcedureDataWrapper implements TableDataWrapper {
}
private void createStore(boolean needLoadingBar) throws Exception {
dataModels = DesignTableDataManager.createLazyDataModel(storeProcedure, needLoadingBar);
dataModels = (ProcedureDataModel[]) DesignTableDataManager.createLazyDataModel(storeProcedure, needLoadingBar);
if (dataModels != null && dataModels.length != 0) {
for (ProcedureDataModel dataModel : dataModels) {
if (ComparatorUtils.equals(this.dsName, storeprocedureName + "_" + dataModel.getName())) {

3
designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/StoreProcedureNameWrapper.java

@ -28,6 +28,7 @@ import java.util.List;
* @author zhou
* @since 2012-4-12上午10:29:15
*/
@Deprecated
public final class StoreProcedureNameWrapper implements TableDataWrapper {
private ProcedureDataModel procedureDataModel;
private String name;
@ -74,7 +75,7 @@ public final class StoreProcedureNameWrapper implements TableDataWrapper {
private void createStore(boolean needLoadingBar) {
try {
procedureDataModel = DesignTableDataManager.createLazyDataModel(storeProcedure, needLoadingBar)[0];
procedureDataModel = (ProcedureDataModel) DesignTableDataManager.createLazyDataModel(storeProcedure, needLoadingBar)[0];
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}

Loading…
Cancel
Save