Browse Source

REPORT-137542 - 远程设计下长时间设计后切换模板卡慢

fbp/master
Destiny.Lin 1 month ago
parent
commit
5d0c6c1305
  1. 5
      designer-base/src/main/java/com/fr/design/actions/server/GlobalTableDataAction.java
  2. 3
      designer-base/src/main/java/com/fr/design/data/datapane/TreeTableDataComboBox.java
  3. 6
      designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionComboBoxPanel.java
  4. 4
      designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionListPane.java
  5. 73
      designer-base/src/main/java/com/fr/design/data/datapane/preview/ConnectionInfoBeanHelper.java
  6. 5
      designer-base/src/main/java/com/fr/design/data/datapane/preview/TableDataBeanHelper.java
  7. 5
      designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/TableDataFactory.java

5
designer-base/src/main/java/com/fr/design/actions/server/GlobalTableDataAction.java

@ -24,11 +24,8 @@ import com.fr.design.menu.MenuKeySet;
import com.fr.esd.event.DSMapping;
import com.fr.esd.event.DsNameTarget;
import com.fr.esd.event.StrategyEventsNotifier;
import com.fr.log.FineLoggerFactory;
import com.fr.report.LockItem;
import com.fr.security.encryption.transmission.TransmissionEncryptionManager;
import com.fr.workspace.server.repository.connection.ConnectionRepository;
import com.fr.workspace.server.repository.tabledata.TableDataRepository;
import javax.swing.KeyStroke;
@ -85,7 +82,7 @@ public class GlobalTableDataAction extends UpdateAction implements ResponseDataS
// 锁定成功,执行后续操作
final DesignerFrame designerFrame = DesignerContext.getDesignerFrame();
final List<ServerDataSetBean> beans = TableDataRepository.getInstance().getAllTableData();
final Map<String, Connection> connectionMap = ConnectionInfoBeanHelper.createConnectionMap(ConnectionRepository.getInstance().getAll());
final Map<String, Connection> connectionMap = ConnectionInfoBeanHelper.getCurrentConnectionMap();
final Map<String, TableData> tableDataMap = new HashMap<>();
for (ServerDataSetBean bean : beans) {
try {

3
designer-base/src/main/java/com/fr/design/data/datapane/TreeTableDataComboBox.java

@ -14,7 +14,6 @@ import com.fr.design.data.tabledata.wrapper.TemplateTableDataWrapper;
import com.fr.design.gui.icombobox.UIComboBox;
import com.fr.design.gui.icombobox.UIComboBoxRenderer;
import com.fr.stable.StringUtils;
import com.fr.workspace.server.repository.connection.ConnectionRepository;
import com.fr.workspace.server.repository.tabledata.TableDataRepository;
import javax.swing.*;
@ -70,7 +69,7 @@ public class TreeTableDataComboBox extends UIComboBox {
// 全局数据集
List<ServerDataSetBean> beans = TableDataRepository.getInstance().getAllTableData();
Map<String, TableData> map = new HashMap<>();
final Map<String, Connection> connectionMap = ConnectionInfoBeanHelper.createConnectionMap(ConnectionRepository.getInstance().getAll());
final Map<String, Connection> connectionMap = ConnectionInfoBeanHelper.getCurrentConnectionMap();
try {
for (ServerDataSetBean bean : beans) {
map.put(bean.getDatasetName() , TableDataBeanHelper.getTableDataSet(connectionMap, bean.getDatasetType(), bean.getDatasetData()));

6
designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionComboBoxPanel.java

@ -1,8 +1,6 @@
package com.fr.design.data.datapane.connect;
import com.fanruan.config.impl.data.ConnectionConfigProviderFactory;
import com.fine.theme.icon.LazyIcon;
import com.fr.base.svg.IconUtils;
import com.fr.data.impl.AbstractDatabaseConnection;
import com.fr.data.impl.Connection;
import com.fr.data.impl.NameDatabaseConnection;
@ -15,9 +13,7 @@ import com.fr.design.gui.ibutton.UILockButton;
import com.fr.report.LockItem;
import com.fr.stable.StringUtils;
import com.fr.workspace.WorkContext;
import com.fr.workspace.server.entity.connection.ConnectionBean;
import com.fr.workspace.server.repository.authority.RemoteAuthorityRepository;
import com.fr.workspace.server.repository.connection.ConnectionRepository;
import javax.swing.SwingUtilities;
import java.awt.Dimension;
@ -91,7 +87,7 @@ public class ConnectionComboBoxPanel extends ItemEditableComboBoxPanel {
if (noAuthConnections == null) {
return nameList.iterator();
}
final Map<String, Connection> connectionMap = ConnectionInfoBeanHelper.createConnectionMap(ConnectionRepository.getInstance().getAll());
final Map<String, Connection> connectionMap = ConnectionInfoBeanHelper.getCurrentConnectionMap();
for (Map.Entry<String, Connection> connectionEntry : connectionMap.entrySet()) {
String conName = connectionEntry.getKey();
if (noAuthConnections.contains(conName)) {

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

@ -207,7 +207,7 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh
public void populate(Map<String, Connection> connectionMap) {
List<NameObject> nameObjectList = new ArrayList<NameObject>();
populatedConnectionsSnapshot.clear();
final Map<String, Connection> map = ConnectionInfoBeanHelper.createConnectionMap(ConnectionRepository.getInstance().getAll());
final Map<String, Connection> map = ConnectionInfoBeanHelper.getCurrentConnectionMap();
for (Map.Entry<String, Connection> entry : map.entrySet()) {
nameObjectList.add(new NameObject(entry.getKey(), entry.getValue()));
try {
@ -369,7 +369,7 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh
public static void showDialog(Window parent) {
try {
final Map<String, Connection> connectionMap = ConnectionInfoBeanHelper.createConnectionMap(ConnectionRepository.getInstance().getAll());
final Map<String, Connection> connectionMap = ConnectionInfoBeanHelper.getCurrentConnectionMap();
final ConnectionManagerPane connectionManagerPane = new ConnectionManagerPane() {
@Override
public void complete() {

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

@ -22,20 +22,30 @@ import com.fr.decision.webservice.bean.datasource.JDBCConnectionBean;
import com.fr.decision.webservice.utils.DecisionServiceConstants;
import com.fr.decision.webservice.v10.datasource.connection.processor.impl.ConnectionProcessorFactory;
import com.fr.decision.webservice.v10.datasource.connection.processor.impl.JDBCConnectionProcessor;
import com.fr.event.Event;
import com.fr.event.EventDispatcher;
import com.fr.event.Listener;
import com.fr.event.Null;
import com.fr.log.FineLoggerFactory;
import com.fr.module.tool.ActivatorToolBox;
import com.fr.security.encryption.transmission.TransmissionEncryptionManager;
import com.fr.stable.Constants;
import com.fr.stable.StringUtils;
import com.fr.third.fasterxml.jackson.databind.ObjectMapper;
import com.fr.third.guava.cache.CacheBuilder;
import com.fr.third.guava.cache.CacheLoader;
import com.fr.third.guava.cache.LoadingCache;
import com.fr.third.springframework.beans.BeanUtils;
import com.fr.workspace.server.repository.WorkplaceConstants;
import com.fr.workspace.server.repository.connection.ConnectionCacheEvent;
import com.fr.workspace.server.repository.connection.ConnectionRepository;
import com.fr.workspace.server.repository.tabledata.DataEncryptionHelper;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
/**
* 数据连接传输工具类
@ -50,19 +60,38 @@ public class ConnectionInfoBeanHelper {
private static final int ORACLE_DEFAULT_FETCH_SIZE = 128;
private static final int DB2_DEFAULT_FETCH_SIZE = 50;
private static final int POSTGRE_DEFAULT_FETCH_SIZE = 10000;
public static final int CACHE_MAX_SIZE = 1;
public static final String VALUE = "value";
private static LoadingCache<String, Map<String, Connection>> cache = CacheBuilder.newBuilder()
// 缓存容量1
.maximumSize(CACHE_MAX_SIZE)
// 默认写入过60S后过期
.expireAfterWrite(60, TimeUnit.SECONDS)
.build(new CacheLoader<String, Map<String, Connection>>() {
@Override
public Map<String, Connection> load(String s) throws Exception {
return updateCache();
}
});
static {
FETCH_SIZE_MAP.put("oracle", ORACLE_DEFAULT_FETCH_SIZE);
FETCH_SIZE_MAP.put("ibm-db2", DB2_DEFAULT_FETCH_SIZE);
FETCH_SIZE_MAP.put("postgresql", POSTGRE_DEFAULT_FETCH_SIZE);
// 监听数据连接缓存失效
EventDispatcher.listen(ConnectionCacheEvent.REMOVE, new Listener<Null>() {
@Override
public void on(Event event, Null aNull) {
cache.invalidateAll();
}
});
}
/**
* 获取连接Map
*/
public static Map<String, Connection> createConnectionMap(ConnectionInfoBean[] beans) {
private static Map<String, Connection> updateCache() {
Map<String, Connection> ans = new HashMap<>();
ConnectionInfoBean[] beans = ConnectionRepository.getInstance().getAll();
for (ConnectionInfoBean infoBean : beans) {
try {
if (JDBCConnectionProcessor.KEY.acceptConnectionTypes().contains(infoBean.getConnectionType())) {
@ -77,23 +106,33 @@ public class ConnectionInfoBeanHelper {
return ans;
}
/**
* 获取连接Map
*/
public static Map<String, Connection> getCurrentConnectionMap() {
try {
return cache.get(VALUE);
} catch (ExecutionException e) {
throw new RuntimeException(e);
}
}
/**
* 根据bean创建连接
*/
public static Connection createConnection(ConnectionInfoBean infoBean) {
Connection connection = null;
try {
if (JDBCConnectionProcessor.KEY.acceptConnectionTypes().contains(infoBean.getConnectionType())) {
connection = createJDBCConnection(infoBean);
} else {
connection = ConnectionProcessorFactory.createConnection(infoBean, true);
}
connection.setConnectionName(infoBean.getConnectionName());
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
return connection;
}
return connection;
try {
Connection connection = cache.get(VALUE).get(infoBean.getConnectionName());
if (connection != null) {
connection.setConnectionName(infoBean.getConnectionName());
}
return connection;
} catch (ExecutionException e) {
throw new RuntimeException(e);
}
}
/**

5
designer-base/src/main/java/com/fr/design/data/datapane/preview/TableDataBeanHelper.java

@ -25,13 +25,10 @@ import com.fr.general.sql.SqlUtils;
import com.fr.json.JSONObject;
import com.fr.log.FineLoggerFactory;
import com.fr.script.Calculator;
import com.fr.security.encryption.transmission.TransmissionEncryptionManager;
import com.fr.stable.ParameterProvider;
import com.fr.stable.StringUtils;
import com.fr.workspace.server.repository.connection.ConnectionRepository;
import com.fr.workspace.server.repository.tabledata.DataEncryptionHelper;
import com.fr.workspace.server.repository.tabledata.TableDataRepository;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.HashMap;
@ -52,7 +49,7 @@ public class TableDataBeanHelper {
*/
public static Map<String, TableData> getServerTableDatas() {
final List<ServerDataSetBean> beans = TableDataRepository.getInstance().getAllTableData();
final Map<String, Connection> connectionMap = ConnectionInfoBeanHelper.createConnectionMap(ConnectionRepository.getInstance().getAll());
final Map<String, Connection> connectionMap = ConnectionInfoBeanHelper.getCurrentConnectionMap();
final Map<String, TableData> tableDataMap = new HashMap<>();
try {
for (ServerDataSetBean bean : beans) {

5
designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/TableDataFactory.java

@ -31,7 +31,6 @@ import com.fr.design.data.tabledata.tabledatapane.TreeTableDataPane;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.ArrayUtils;
import com.fr.stable.StringUtils;
import com.fr.workspace.server.repository.connection.ConnectionRepository;
import com.fr.workspace.server.repository.tabledata.TableDataRepository;
import javax.swing.Icon;
@ -205,7 +204,7 @@ public abstract class TableDataFactory {
clearAll();
try {
List<ServerDataSetBean> beans = TableDataRepository.getInstance().getAllTableData();
final Map<String, Connection> connectionMap = ConnectionInfoBeanHelper.createConnectionMap(ConnectionRepository.getInstance().getAll());
final Map<String, Connection> connectionMap = ConnectionInfoBeanHelper.getCurrentConnectionMap();
Map<String, TableData> tableDataMap = new HashMap<>();
for (ServerDataSetBean bean : beans) {
tableDataMap.put(bean.getDatasetName(), TableDataBeanHelper.getTableDataSet(connectionMap, bean.getDatasetType(), bean.getDatasetData()));
@ -229,7 +228,7 @@ public abstract class TableDataFactory {
Map<String, TableData> tableDataMap = new HashMap<>();
try {
List<ServerDataSetBean> beans = TableDataRepository.getInstance().getAllTableData();
final Map<String, Connection> connectionMap = ConnectionInfoBeanHelper.createConnectionMap(ConnectionRepository.getInstance().getAll());
final Map<String, Connection> connectionMap = ConnectionInfoBeanHelper.getCurrentConnectionMap();
for (ServerDataSetBean bean : beans) {
tableDataMap.put(bean.getDatasetName(), TableDataBeanHelper.getTableDataSet(connectionMap, bean.getDatasetType(), bean.getDatasetData()));
}

Loading…
Cancel
Save