Browse Source

Merge pull request #1370 in DESIGN/design from ~HADES/design:release/10.0 to release/10.0

* commit 'cf7bd5c4e738724fe2b37d835ea00d3e54ef92d5':
  REPORT-24141 内存数据库snappydata下拉展示数据列表,以及切换过滤的时候,速度很慢
feature/big-screen
Hades 5 years ago
parent
commit
d73d53bd7b
  1. 45
      designer-base/src/main/java/com/fr/design/data/DesignTableDataManager.java
  2. 2
      designer-base/src/main/java/com/fr/design/data/datapane/TableDataTreePane.java
  3. 1
      designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/AbstractTableDataWrapper.java
  4. 47
      designer-base/src/test/java/com/fr/design/data/DesignTableDataManagerTest.java

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

@ -83,6 +83,7 @@ public abstract class DesignTableDataManager {
//用于记录是否要弹出参数框
private static ThreadLocal<String> threadLocal = new ThreadLocal<String>();
private static Map<TableDataSource, Map<String, String[]>> columnCache = new HashMap<>();
/**
* 清除全局 数据集缓存.
@ -113,11 +114,13 @@ public abstract class DesignTableDataManager {
public static void closeTemplate(JTemplate<?, ?> template) {
if (template != null) {
columnCache.remove(getEditingTableDataSource());
dsListenersMap.remove(template.getPath());
}
}
public static void envChange() {
columnCache.clear();
dsListenersMap.clear();
dsNameChangedMap.clear();
clearGlobalDs();
@ -197,7 +200,47 @@ public abstract class DesignTableDataManager {
java.util.Map<String, TableDataWrapper> resMap = getAllEditingDataSet(source);
java.util.Map<String, TableDataWrapper> dsMap = getAllDataSetIncludingProcedure(resMap);
TableDataWrapper tabledataWrapper = dsMap.get(dsName);
return tabledataWrapper == null ? new String[0] : tabledataWrapper.calculateColumnNameList().toArray(new String[0]);
if (tabledataWrapper == null) {
return new String[0];
} else {
return getSelectedColumnNamesFromCache(source, dsName, tabledataWrapper);
}
}
private static String[] getSelectedColumnNamesFromCache(TableDataSource dataSource, String dsName, TableDataWrapper tableDataWrapper) {
Map<String, String[]> map = columnCache.get(dataSource);
if (map == null) {
map = new HashMap<>();
String[] columnNames = tableDataWrapper.calculateColumnNameList().toArray(new String[0]);
map.put(dsName, columnNames);
columnCache.put(dataSource, map);
return columnNames;
} else {
String[] columnNames = map.get(dsName);
if (columnNames == null) {
columnNames = tableDataWrapper.calculateColumnNameList().toArray(new String[0]);
map.put(dsName, columnNames);
return columnNames;
} else {
return columnNames;
}
}
}
public static void removeSelectedColumnNames(String dsName) {
columnCache.get(getEditingTableDataSource()).remove(dsName);
}
public static void addDsColumnNames(String dsName, String[] columnNames) {
TableDataSource dataSource = getEditingTableDataSource();
Map<String, String[]> map = columnCache.get(dataSource);
if (map == null) {
map = new HashMap<>();
map.put(dsName, columnNames);
columnCache.put(dataSource, map);
} else {
map.put(dsName, columnNames);
}
}
/**

2
designer-base/src/main/java/com/fr/design/data/datapane/TableDataTreePane.java

@ -244,6 +244,7 @@ public class TableDataTreePane extends BasicTableDataTreePane {
if (selectedNO == null) {
return;
}
DesignTableDataManager.removeSelectedColumnNames(selectedNO.getName());
dgEdit(((AbstractTableDataWrapper) selectedNO.getObject()).creatTableDataPane(), selectedNO.getName(), false);
}
}
@ -275,6 +276,7 @@ public class TableDataTreePane extends BasicTableDataTreePane {
dataTree.setSelectionRow(dataTree.getRowCount() - 1);
fireDSChanged();
checkButtonEnabled();
DesignTableDataManager.removeSelectedColumnNames(selectedNO.getName());
}
}
}

1
designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/AbstractTableDataWrapper.java

@ -65,6 +65,7 @@ public abstract class AbstractTableDataWrapper implements TableDataWrapper {
}
}
columnNameList = DesignTableDataManager.getColumnNamesByTableData(embeddedTableData);
DesignTableDataManager.addDsColumnNames(name, columnNameList.toArray(new String[0]));
return columnNameList;
}

47
designer-base/src/test/java/com/fr/design/data/DesignTableDataManagerTest.java

@ -1,11 +1,14 @@
package com.fr.design.data;
import com.fr.base.TableData;
import com.fr.data.TableDataSource;
import com.fr.data.impl.storeproc.StoreProcedure;
import com.fr.design.data.tabledata.wrapper.TableDataFactory;
import com.fr.design.data.tabledata.wrapper.TableDataWrapper;
import com.fr.design.data.tabledata.wrapper.TemplateTableDataWrapper;
import com.fr.file.ProcedureConfig;
import com.fr.file.TableDataConfig;
import com.fr.invoke.Reflect;
import org.easymock.EasyMock;
import org.junit.Assert;
import org.junit.Test;
@ -23,6 +26,7 @@ import java.util.Map;
@SuppressStaticInitializationFor({"com.fr.design.data.tabledata.wrapper.TableDataFactory"})
public class DesignTableDataManagerTest {
@Test
public void testFireDataChange() {
@ -99,4 +103,47 @@ public class DesignTableDataManagerTest {
}
@Test
public void testGetSelectedColumnNames() throws Exception {
PowerMock.mockStatic(TableDataConfig.class);
PowerMock.mockStatic(TemplateTableDataWrapper.class);
TableDataConfig config = EasyMock.mock(TableDataConfig.class);
TableData td1 = EasyMock.mock(TableData.class);
TableData td2 = EasyMock.mock(TableData.class);
TableDataSource dataSource = EasyMock.mock(TableDataSource.class);
EasyMock.expect(config.getTableData("ds1")).andReturn(td1).anyTimes();
EasyMock.expect(config.getTableData("ds2")).andReturn(td2).anyTimes();
EasyMock.expect(dataSource.getTableData("ds1")).andReturn(td1).anyTimes();
EasyMock.expect(dataSource.getTableData("ds2")).andReturn(td2).anyTimes();
EasyMock.expect(TableDataConfig.getInstance()).andReturn(config).anyTimes();
PowerMock.mockStatic(TableDataFactory.class);
EasyMock.expect(TableDataFactory.getSortOfChineseNameOfServerData(config))
.andReturn(new String[]{"ds1", "ds2"}).anyTimes();
EasyMock.expect(TableDataFactory.getSortOfChineseNameOfTemplateData(dataSource))
.andReturn(new String[]{"ds1", "ds2"});
Map<TableDataSource, Map<String, String[]>> cache = Reflect.on(DesignTableDataManager.class).field(
"columnCache").get();
Map<String, String[]> map = new HashMap<>();
map.put("ds1", new String[]{"a", "b", "c"});
cache.put(dataSource, map);
ProcedureConfig proConfig = EasyMock.mock(ProcedureConfig.class);
Map<String, StoreProcedure> procedureMap = new HashMap<>();
EasyMock.expect(proConfig.getProcedures()).andReturn(procedureMap).anyTimes();
PowerMock.mockStatic(ProcedureConfig.class);
EasyMock.expect(ProcedureConfig.getInstance()).andReturn(proConfig).anyTimes();
EasyMock.replay(config, proConfig, dataSource);
PowerMock.replay(TableDataFactory.class, TableDataConfig.class, ProcedureConfig.class,
TemplateTableDataWrapper.class);
Assert.assertEquals(new String[]{"a", "b", "c"},
DesignTableDataManager.getSelectedColumnNames(dataSource, "ds1"));
}
@Test
public void testAddDsColumnNames() {
DesignTableDataManager.addDsColumnNames("ds1", new String[]{"a", "b", "c"});
Map<TableDataSource, Map<String, String[]>> map = Reflect.on(DesignTableDataManager.class).field(
"columnCache").get();
Assert.assertEquals(new String[]{"a", "b", "c"}, map.get(null).get("ds1"));
}
}

Loading…
Cancel
Save