Browse Source

REPORT-133442 【fr-fbp回归】【数据集】数据连接驱动选择自定义,保存后二次编辑,仍选择默认驱动

fbp/release
Destiny.Lin 3 months ago
parent
commit
b7fc167970
  1. 11
      designer-base/src/main/java/com/fr/design/actions/server/GlobalTableDataAction.java
  2. 2
      designer-base/src/main/java/com/fr/design/data/datapane/TableDataPaneListPane.java
  3. 10
      designer-base/src/main/java/com/fr/design/data/datapane/TreeTableDataComboBox.java
  4. 10
      designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionComboBoxPanel.java
  5. 14
      designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionListPane.java
  6. 19
      designer-base/src/main/java/com/fr/design/data/datapane/connect/LocalConnectionSource.java
  7. 140
      designer-base/src/main/java/com/fr/design/data/datapane/preview/ConnectionInfoBeanHelper.java
  8. 198
      designer-base/src/main/java/com/fr/design/data/datapane/preview/TableDataBeanHelper.java
  9. 34
      designer-base/src/main/java/com/fr/design/data/tabledata/LocalTableDataSource.java
  10. 16
      designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/TableDataFactory.java

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

@ -8,7 +8,8 @@ import com.fr.design.DesignModelAdapter;
import com.fr.design.actions.UpdateAction; import com.fr.design.actions.UpdateAction;
import com.fr.design.data.DesignTableDataManager; import com.fr.design.data.DesignTableDataManager;
import com.fr.design.data.datapane.TableDataTreePane; import com.fr.design.data.datapane.TableDataTreePane;
import com.fr.workspace.server.repository.tabledata.TableDataBeanHelper; import com.fr.design.data.datapane.preview.ConnectionInfoBeanHelper;
import com.fr.design.data.datapane.preview.TableDataBeanHelper;
import com.fr.design.data.tabledata.ResponseDataSourceChange; import com.fr.design.data.tabledata.ResponseDataSourceChange;
import com.fr.design.data.tabledata.tabledatapane.TableDataManagerPane; import com.fr.design.data.tabledata.tabledatapane.TableDataManagerPane;
import com.fr.design.dialog.BasicDialog; import com.fr.design.dialog.BasicDialog;
@ -24,10 +25,8 @@ import com.fr.esd.event.DSMapping;
import com.fr.esd.event.DsNameTarget; import com.fr.esd.event.DsNameTarget;
import com.fr.esd.event.StrategyEventsNotifier; import com.fr.esd.event.StrategyEventsNotifier;
import com.fr.file.TableDataConfig;
import com.fr.report.LockItem; import com.fr.report.LockItem;
import com.fr.security.encryption.transmission.TransmissionEncryptionManager; import com.fr.security.encryption.transmission.TransmissionEncryptionManager;
import com.fr.workspace.server.entity.connection.ConnectionBean;
import com.fr.workspace.server.repository.connection.ConnectionRepository; import com.fr.workspace.server.repository.connection.ConnectionRepository;
import com.fr.workspace.server.repository.tabledata.TableDataRepository; import com.fr.workspace.server.repository.tabledata.TableDataRepository;
@ -85,11 +84,7 @@ public class GlobalTableDataAction extends UpdateAction implements ResponseDataS
// 锁定成功,执行后续操作 // 锁定成功,执行后续操作
final DesignerFrame designerFrame = DesignerContext.getDesignerFrame(); final DesignerFrame designerFrame = DesignerContext.getDesignerFrame();
final List<ServerDataSetBean> beans = TableDataRepository.getInstance().getAllTableData(); final List<ServerDataSetBean> beans = TableDataRepository.getInstance().getAllTableData();
final List<ConnectionBean> connectionInfoBeans = ConnectionRepository.getInstance().getAll(); final Map<String, Connection> connectionMap = ConnectionInfoBeanHelper.createConnectionMap(ConnectionRepository.getInstance().getAll());
final Map<String, Connection> connectionMap = new HashMap<>();
for (ConnectionBean bean : connectionInfoBeans) {
connectionMap.put(bean.getName(), bean.getConnection());
}
final Map<String, TableData> tableDataMap = new HashMap<>(); final Map<String, TableData> tableDataMap = new HashMap<>();
try { try {
TransmissionEncryptionManager.setTransEncryptionLevel(1); TransmissionEncryptionManager.setTransEncryptionLevel(1);

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

@ -10,7 +10,7 @@ import com.fr.decision.webservice.bean.dataset.ServerDataSetBean;
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.data.MapCompareUtils;
import com.fr.workspace.server.repository.tabledata.TableDataBeanHelper; import com.fr.design.data.datapane.preview.TableDataBeanHelper;
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;

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

@ -6,7 +6,8 @@ import com.fr.data.impl.Connection;
import com.fr.data.impl.RecursionTableData; import com.fr.data.impl.RecursionTableData;
import com.fr.decision.webservice.bean.dataset.ServerDataSetBean; import com.fr.decision.webservice.bean.dataset.ServerDataSetBean;
import com.fr.design.data.DesignTableDataManager; import com.fr.design.data.DesignTableDataManager;
import com.fr.workspace.server.repository.tabledata.TableDataBeanHelper; import com.fr.design.data.datapane.preview.ConnectionInfoBeanHelper;
import com.fr.design.data.datapane.preview.TableDataBeanHelper;
import com.fr.design.data.tabledata.wrapper.ServerTableDataWrapper; import com.fr.design.data.tabledata.wrapper.ServerTableDataWrapper;
import com.fr.design.data.tabledata.wrapper.TableDataWrapper; import com.fr.design.data.tabledata.wrapper.TableDataWrapper;
import com.fr.design.data.tabledata.wrapper.TemplateTableDataWrapper; import com.fr.design.data.tabledata.wrapper.TemplateTableDataWrapper;
@ -14,7 +15,6 @@ import com.fr.design.gui.icombobox.UIComboBox;
import com.fr.design.gui.icombobox.UIComboBoxRenderer; import com.fr.design.gui.icombobox.UIComboBoxRenderer;
import com.fr.security.encryption.transmission.TransmissionEncryptionManager; import com.fr.security.encryption.transmission.TransmissionEncryptionManager;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import com.fr.workspace.server.entity.connection.ConnectionBean;
import com.fr.workspace.server.repository.connection.ConnectionRepository; import com.fr.workspace.server.repository.connection.ConnectionRepository;
import com.fr.workspace.server.repository.tabledata.TableDataRepository; import com.fr.workspace.server.repository.tabledata.TableDataRepository;
@ -71,11 +71,7 @@ public class TreeTableDataComboBox extends UIComboBox {
// 全局数据集 // 全局数据集
List<ServerDataSetBean> beans = TableDataRepository.getInstance().getAllTableData(); List<ServerDataSetBean> beans = TableDataRepository.getInstance().getAllTableData();
Map<String, TableData> map = new HashMap<>(); Map<String, TableData> map = new HashMap<>();
final List<ConnectionBean> connectionInfoBeans = ConnectionRepository.getInstance().getAll(); final Map<String, Connection> connectionMap = ConnectionInfoBeanHelper.createConnectionMap(ConnectionRepository.getInstance().getAll());
final Map<String, Connection> connectionMap = new HashMap<>();
for (ConnectionBean bean : connectionInfoBeans) {
connectionMap.put(bean.getName(), bean.getConnection());
}
try { try {
TransmissionEncryptionManager.setTransEncryptionLevel(1); TransmissionEncryptionManager.setTransEncryptionLevel(1);
for (ServerDataSetBean bean : beans) { for (ServerDataSetBean bean : beans) {

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

@ -7,6 +7,7 @@ import com.fr.data.impl.AbstractDatabaseConnection;
import com.fr.data.impl.Connection; import com.fr.data.impl.Connection;
import com.fr.data.impl.NameDatabaseConnection; import com.fr.data.impl.NameDatabaseConnection;
import com.fr.design.DesignerEnvManager; import com.fr.design.DesignerEnvManager;
import com.fr.design.data.datapane.preview.ConnectionInfoBeanHelper;
import com.fr.design.editlock.ConnectionLockChangeChecker; import com.fr.design.editlock.ConnectionLockChangeChecker;
import com.fr.design.editlock.EditLockUtils; import com.fr.design.editlock.EditLockUtils;
import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ibutton.UIButton;
@ -28,6 +29,7 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* 选择数据连接的下拉框 * 选择数据连接的下拉框
@ -89,13 +91,13 @@ public class ConnectionComboBoxPanel extends ItemEditableComboBoxPanel {
if (noAuthConnections == null) { if (noAuthConnections == null) {
return nameList.iterator(); return nameList.iterator();
} }
List<ConnectionBean> beans = ConnectionRepository.getInstance().getAll(); final Map<String, Connection> connectionMap = ConnectionInfoBeanHelper.createConnectionMap(ConnectionRepository.getInstance().getAll());
for (ConnectionBean bean : beans) { for (Map.Entry<String, Connection> connectionEntry : connectionMap.entrySet()) {
String conName = bean.getName(); String conName = connectionEntry.getKey();
if (noAuthConnections.contains(conName)) { if (noAuthConnections.contains(conName)) {
continue; continue;
} }
filterConnection(bean.getConnection(), conName, nameList); filterConnection(connectionEntry.getValue(), conName, nameList);
} }
return nameList.iterator(); return nameList.iterator();
} }

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

@ -190,11 +190,11 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh
public void populate(Map<String, Connection> connectionMap) { public void populate(Map<String, Connection> connectionMap) {
List<NameObject> nameObjectList = new ArrayList<NameObject>(); List<NameObject> nameObjectList = new ArrayList<NameObject>();
populatedConnectionsSnapshot.clear(); populatedConnectionsSnapshot.clear();
List<com.fr.workspace.server.entity.connection.ConnectionBean> beans = ConnectionRepository.getInstance().getAll(); final Map<String, Connection> map = ConnectionInfoBeanHelper.createConnectionMap(ConnectionRepository.getInstance().getAll());
for (com.fr.workspace.server.entity.connection.ConnectionBean entry : beans) { for (Map.Entry<String, Connection> entry : map.entrySet()) {
nameObjectList.add(new NameObject(entry.getName(), entry.getConnection())); nameObjectList.add(new NameObject(entry.getKey(), entry.getValue()));
try { try {
populatedConnectionsSnapshot.put(entry.getName(), (Connection) entry.getConnection().clone()); populatedConnectionsSnapshot.put(entry.getKey(), (Connection) entry.getValue().clone());
} catch (Exception e) { } catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e); FineLoggerFactory.getLogger().error(e.getMessage(), e);
} }
@ -365,11 +365,7 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh
} }
public static void showDialog(Window parent) { public static void showDialog(Window parent) {
List<ConnectionBean> beans = ConnectionRepository.getInstance().getAll(); final Map<String, Connection> connectionMap = ConnectionInfoBeanHelper.createConnectionMap(ConnectionRepository.getInstance().getAll());
Map<String, Connection> connectionMap = new HashMap<>();
for (ConnectionBean bean : beans) {
connectionMap.put(bean.getName(), bean.getConnection());
}
final ConnectionManagerPane connectionManagerPane = new ConnectionManagerPane() { final ConnectionManagerPane connectionManagerPane = new ConnectionManagerPane() {
@Override @Override
public void complete() { public void complete() {

19
designer-base/src/main/java/com/fr/design/data/datapane/connect/LocalConnectionSource.java

@ -1,16 +1,21 @@
package com.fr.design.data.datapane.connect; package com.fr.design.data.datapane.connect;
import com.fanruan.config.impl.data.ConnectionConfigProviderFactory;
import com.fr.data.driver.DriverClassNotFoundException; import com.fr.data.driver.DriverClassNotFoundException;
import com.fr.data.impl.Connection; import com.fr.data.impl.Connection;
import com.fr.decision.webservice.bean.datasource.ConnectionInfoBean; import com.fr.decision.webservice.bean.datasource.ConnectionInfoBean;
import com.fr.decision.webservice.exception.general.DriverNotFoundException; import com.fr.decision.webservice.exception.general.DriverNotFoundException;
import com.fr.decision.webservice.v10.datasource.connection.processor.impl.ConnectionProcessorFactory; import com.fr.decision.webservice.v10.datasource.connection.processor.impl.ConnectionProcessorFactory;
import com.fr.design.data.datapane.preview.ConnectionInfoBeanHelper;
import com.fr.design.i18n.Toolkit; import com.fr.design.i18n.Toolkit;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
import com.fr.security.encryption.transmission.TransmissionEncryptionManager; import com.fr.security.encryption.transmission.TransmissionEncryptionManager;
import com.fr.workspace.engine.exception.DriverUnExistException; import com.fr.workspace.engine.exception.DriverUnExistException;
import com.fr.workspace.server.repository.connection.BaseConnectionSource; import com.fr.workspace.server.repository.connection.BaseConnectionSource;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/** /**
* 本地Connection资源操作 * 本地Connection资源操作
@ -21,6 +26,20 @@ import java.sql.SQLException;
*/ */
public class LocalConnectionSource extends BaseConnectionSource { public class LocalConnectionSource extends BaseConnectionSource {
@Override
public ConnectionInfoBean[] getAll(){
Map<String, Connection> map = ConnectionConfigProviderFactory.getConfigProvider().getConnections();
List<ConnectionInfoBean> beans = new ArrayList<>();
for (String name : map.keySet()) {
try {
beans.add(ConnectionInfoBeanHelper.createConnectionInfoBean(name, map.get(name)));
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
return beans.toArray(new ConnectionInfoBean[0]);
}
@Override @Override
public void testConnection(ConnectionInfoBean database) throws Exception { public void testConnection(ConnectionInfoBean database) throws Exception {
try { try {

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

@ -3,6 +3,7 @@ package com.fr.design.data.datapane.preview;
import com.fr.data.auth.AuthenticationType; import com.fr.data.auth.AuthenticationType;
import com.fr.data.auth.kerberos.KerberosAuthentication; import com.fr.data.auth.kerberos.KerberosAuthentication;
import com.fr.data.auth.kerberos.KerberosUtils; import com.fr.data.auth.kerberos.KerberosUtils;
import com.fr.data.core.db.dialect.DialectFactory;
import com.fr.data.impl.Connection; import com.fr.data.impl.Connection;
import com.fr.data.impl.JDBCDatabaseConnection; import com.fr.data.impl.JDBCDatabaseConnection;
import com.fr.data.impl.NameDatabaseConnection; import com.fr.data.impl.NameDatabaseConnection;
@ -10,7 +11,9 @@ import com.fr.data.pool.DBCPConnectionPoolAttr;
import com.fr.data.security.ssh.BaseSsh; import com.fr.data.security.ssh.BaseSsh;
import com.fr.data.security.ssh.SshType; import com.fr.data.security.ssh.SshType;
import com.fr.data.security.ssh.impl.KeyVerifySsh; import com.fr.data.security.ssh.impl.KeyVerifySsh;
import com.fr.data.security.ssh.impl.NormalSsh;
import com.fr.data.security.ssl.BaseSsl; import com.fr.data.security.ssl.BaseSsl;
import com.fr.data.security.ssl.Ssl;
import com.fr.data.security.ssl.SslType; import com.fr.data.security.ssl.SslType;
import com.fr.data.security.ssl.impl.NormalSsl; import com.fr.data.security.ssl.impl.NormalSsl;
import com.fr.decision.privilege.TransmissionTool; import com.fr.decision.privilege.TransmissionTool;
@ -19,11 +22,21 @@ import com.fr.decision.webservice.bean.datasource.JDBCConnectionBean;
import com.fr.decision.webservice.utils.DecisionServiceConstants; 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.ConnectionProcessorFactory;
import com.fr.decision.webservice.v10.datasource.connection.processor.impl.JDBCConnectionProcessor; import com.fr.decision.webservice.v10.datasource.connection.processor.impl.JDBCConnectionProcessor;
import com.fr.log.FineLoggerFactory;
import com.fr.module.tool.ActivatorToolBox;
import com.fr.security.encryption.transmission.TransmissionEncryptionManager; import com.fr.security.encryption.transmission.TransmissionEncryptionManager;
import com.fr.stable.Constants;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import com.fr.third.fasterxml.jackson.core.JsonProcessingException;
import com.fr.third.fasterxml.jackson.databind.ObjectMapper; import com.fr.third.fasterxml.jackson.databind.ObjectMapper;
import com.fr.third.springframework.beans.BeanUtils;
import com.fr.workspace.server.repository.WorkplaceConstants; import com.fr.workspace.server.repository.WorkplaceConstants;
import com.fr.workspace.server.repository.connection.ConnectionRepository; 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;
/** /**
* 数据连接传输工具类 * 数据连接传输工具类
@ -34,6 +47,36 @@ import com.fr.workspace.server.repository.connection.ConnectionRepository;
*/ */
public class ConnectionInfoBeanHelper { public class ConnectionInfoBeanHelper {
private static ObjectMapper objectMapper = new ObjectMapper(); private static ObjectMapper objectMapper = new ObjectMapper();
private static final Map<String, Integer> FETCH_SIZE_MAP = ActivatorToolBox.sandbox(new HashMap<String, Integer>());
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;
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);
}
/**
* 获取连接Map
*/
public static Map<String, Connection> createConnectionMap(ConnectionInfoBean[] beans) {
Map<String, Connection> ans = new HashMap<>();
for (ConnectionInfoBean infoBean : beans) {
try {
if (JDBCConnectionProcessor.KEY.acceptConnectionTypes().contains(infoBean.getConnectionType())) {
ans.put(infoBean.getConnectionName(), createJDBCConnection(infoBean));
} else {
ans.put(infoBean.getConnectionName(), ConnectionProcessorFactory.createConnection(infoBean, true));
}
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
return ans;
}
/** /**
* 创建数据连接Bean可自定义是否携带密码 * 创建数据连接Bean可自定义是否携带密码
@ -137,4 +180,101 @@ public class ConnectionInfoBeanHelper {
return TransmissionEncryptionManager.getInstance().getEncryption(WorkplaceConstants.getEncryptionMode()).encrypt(password, WorkplaceConstants.getEncryptionKey()); return TransmissionEncryptionManager.getInstance().getEncryption(WorkplaceConstants.getEncryptionMode()).encrypt(password, WorkplaceConstants.getEncryptionKey());
} }
private static Connection createJDBCConnection(ConnectionInfoBean connectionInfoBean) throws Exception {
String name = connectionInfoBean.getConnectionName();
if (StringUtils.isNotEmpty(connectionInfoBean.getConnectionId())) {
name = connectionInfoBean.getConnectionId();
}
JDBCDatabaseConnection connection = new JDBCDatabaseConnection();
JDBCConnectionBean bean = objectMapper.readValue(connectionInfoBean.getConnectionData(), JDBCConnectionBean.class);
if (StringUtils.isNotEmpty(name)) {
bean.setConnectionName(name);
}
DBCPConnectionPoolAttr connectionPoolAttr = new DBCPConnectionPoolAttr();
BeanUtils.copyProperties(bean.getConnectionPoolAttr(), connectionPoolAttr);
connectionPoolAttr.setValidationQuery(DataEncryptionHelper.decrypt(connectionPoolAttr.getValidationQuery()));
connectionPoolAttr.setMinEvictableIdleTimeMillis(bean.getConnectionPoolAttr().getMinEvictableIdleTimeMillis() * Constants.MILLS_PER_SECOND);
connectionPoolAttr.setMaxEvictableIdleTimeMillis((long) bean.getConnectionPoolAttr().getMaxEvictableIdleTimeMillis() * Constants.MILLS_PER_SECOND);
connection.setDatabase(bean.getDatabase());
connection.setSchema(bean.getSchema());
connection.setDriver(bean.getDriver());
connection.setURL(bean.getUrl());
connection.setOriginalCharsetName(StringUtils.isEmpty(bean.getOriginalCharsetName()) ? null : bean.getOriginalCharsetName());
connection.setNewCharsetName(StringUtils.isEmpty(bean.getNewCharsetName()) ? null : bean.getNewCharsetName());
connection.setCreator(bean.getCreator());
connection.setDriverSource(bean.getDriverSource());
connection.setDbcpAttr(connectionPoolAttr);
if (StringUtils.isNotEmpty(bean.getAuthType())) {
connection.setAuthentication(new KerberosAuthentication(bean.getPrincipal(), bean.getKeyPath(), bean.isUseJaas()));
}
connection.setUser(bean.getUser());
TransmissionEncryptionManager.getInstance().setCurrentEncryptionMode(WorkplaceConstants.getDecryptionMode());
connection.setPassword(DataEncryptionHelper.decrypt(bean.getPassword()));
connection.setProperties(bean.getProperties());
setFetchSize(bean, connection);
if (bean.getIdentity() != null) {
connection.setIdentity(bean.getIdentity());
}
BaseSsh baseSsh;
String sshType = bean.getSshType();
if (SshType.KEY.toString().equals(sshType)) {
baseSsh = new KeyVerifySsh();
((KeyVerifySsh) baseSsh).setPrivateKeyPath(bean.getSshPrivateKeyPath());
} else {
baseSsh = new NormalSsh();
}
baseSsh.setIp(bean.getSshIp());
baseSsh.setUsingSsh(bean.isUsingSsh());
baseSsh.setPort(bean.getSshPort());
baseSsh.setUser(bean.getSshUser());
baseSsh.setRedirectIp(bean.getRedirectIp());
baseSsh.setRedirectPort(bean.getRedirectPort());
baseSsh.setSecret(DataEncryptionHelper.decrypt(bean.getSshSecret()));
baseSsh.setKeepAlive(bean.getSshKeepAlive());
baseSsh.setTimeOut(bean.getSshTimeOut());
connection.setSsh(baseSsh);
connection.setSsl(createSsl(bean));
return connection;
}
private static Ssl createSsl(JDBCConnectionBean bean) {
//目前只有NormalSsl
BaseSsl baseSsl = new NormalSsl();
if (SslType.NORMAL.toString().equals(bean.getSslType())) {
((NormalSsl) baseSsl).setVerifyCa(bean.isVerifyCa());
((NormalSsl) baseSsl).setCipher(bean.getSslCipher());
}
baseSsl.setUsingSsl(bean.isUsingSsl());
baseSsl.setClientCertificate(bean.getSslClientCertificate());
baseSsl.setClientPrivateKey(bean.getSslClientPrivateKey());
baseSsl.setCaCertificate(bean.getCaCertificate());
return baseSsl;
}
/**
* 前端客户设置了一个fetchSize
* 1. 如果是合法值(>0)就使用
* 2. 如果是非法值(<=0)
* 2.1 如果我们对这种数据库有默认的fetchSize就用默认的
* 2.2 如果没有默认值就不进行任何设置
* @param bean bean
* @param connection connection
*/
private static void setFetchSize(JDBCConnectionBean bean, Connection connection) {
int connectionBeanFetchSize = bean.getFetchSize();
String connectionBeanDatabaseName = bean.getDatabase();
if (DialectFactory.isValidFetchSize(connectionBeanFetchSize)) {
connection.setFetchSize(connectionBeanFetchSize);
} else if (FETCH_SIZE_MAP.containsKey(connectionBeanDatabaseName)) {
Optional.ofNullable(FETCH_SIZE_MAP.get(connectionBeanDatabaseName)).ifPresent(connection::setFetchSize);
}
FineLoggerFactory.getLogger().info("[Connection] fetchSize set to {} for connection {}", connection.getFetchSize(), bean.getConnectionName());
}
} }

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

@ -0,0 +1,198 @@
package com.fr.design.data.datapane.preview;
import com.fr.base.DataSetProcessors;
import com.fr.base.Parameter;
import com.fr.base.ParameterHelper;
import com.fr.base.ParameterTypeHandler;
import com.fr.base.StoreProcedureParameter;
import com.fr.base.TableData;
import com.fr.data.impl.Connection;
import com.fr.data.impl.DBTableData;
import com.fr.data.impl.NameDatabaseConnection;
import com.fr.data.impl.storeproc.StoreProcedure;
import com.fr.decision.fun.UniversalServerTableDataProvider;
import com.fr.decision.webservice.bean.dataset.ParameterBean;
import com.fr.decision.webservice.bean.dataset.ParameterExternal;
import com.fr.decision.webservice.bean.dataset.SQLDataSetBean;
import com.fr.decision.webservice.bean.dataset.ServerDataSetBean;
import com.fr.decision.webservice.bean.dataset.StoreProcedureBean;
import com.fr.decision.webservice.v10.datasource.dataset.processor.impl.SQLDataSetProcessor;
import com.fr.decision.webservice.v10.datasource.dataset.processor.impl.StoreProcedureProcessor;
import com.fr.general.GeneralUtils;
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 java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 数据集bean工具类
*
* @author Destiny.Lin
* @since 11.0
* Created on 2024/8/9
*/
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, TableData> tableDataMap = new HashMap<>();
try {
TransmissionEncryptionManager.setTransEncryptionLevel(1);
for (ServerDataSetBean bean : beans) {
tableDataMap.put(bean.getDatasetName() , TableDataBeanHelper.getTableDataSet(connectionMap, bean.getDatasetType(), bean.getDatasetData()));
}
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
TransmissionEncryptionManager.removeTransEncryptionLevel();
}
return tableDataMap;
}
/**
* 根据序列化数据生成tabledata
*/
public static TableData getTableDataSet(Map<String, Connection> connectionMap, String type, String tableDataSetData) throws Exception {
if (DataSetProcessors.getProcessors().containsKey(type)) {
if (StringUtils.equals(SQLDataSetProcessor.TYPE, type)) {
return deserialize4SQL(connectionMap, null, new JSONObject(tableDataSetData));
} else if (StringUtils.equals(StoreProcedureProcessor.TYPE, type)) {
return deserialize4Procedure(connectionMap, null, new JSONObject(tableDataSetData));
} else {
UniversalServerTableDataProvider processor = DataSetProcessors.getProcessors().get(type);
return (TableData) processor.deserialize(null, new JSONObject(tableDataSetData));
}
}
return null;
}
private static TableData deserialize4Procedure(Map<String, Connection> connectionMap, DBTableData oldDataSet, JSONObject object) {
StoreProcedure storeProcedure = new StoreProcedure();
StoreProcedureBean bean = object.mapTo(StoreProcedureBean.class);
storeProcedure.setShare(bean.isShare());
storeProcedure.setMaxMemRowCount(bean.getMaxMemRowCount());
storeProcedure.setQuery(bean.getQuery());
if (StringUtils.isNotEmpty(bean.getDatabase())) {
Connection connection = connectionMap.get(bean.getDatabase());
if (connection != null) {
storeProcedure.setDatabaseConnection(new NameDatabaseConnection(bean.getDatabase()));
} else {
FineLoggerFactory.getLogger().info("not find conn by {}", bean.getDatabase());
}
}
Parameter[] parameters = new Parameter[bean.getParameters().size()];
for (int i = 0; i < parameters.length; i++) {
ParameterBean parameterBean = bean.getParameters().get(i);
parameters[i] = (Parameter) ParameterTypeHandler.getInstance().parseParameter(parameterBean, new Parameter(parameterBean.getName()));
}
List<ParameterExternal> externals = bean.getStoreProcedureParameterBeanList();
StoreProcedureParameter[] procedureParameters = new StoreProcedureParameter[bean.getParameters().size()];
for (int i = 0; i < procedureParameters.length; i++) {
StoreProcedureParameter storeProcedureParameter = new StoreProcedureParameter();
storeProcedureParameter.setName(parameters[i].getName());
storeProcedureParameter.setValue(parameters[i].getValue());
storeProcedureParameter.setSchema(externals.get(i).getSchema());
storeProcedureParameter.setType(externals.get(i).getTypeInt());
procedureParameters[i] = storeProcedureParameter;
}
storeProcedure.setParameters(procedureParameters);
return storeProcedure;
}
/**
* 获取服务器数据集传输的bean
*/
public static ServerDataSetBean getServerDataSetBean(String name, TableData tableData) {
for (UniversalServerTableDataProvider processor : DataSetProcessors.getProcessors().values()) {
if (SQLDataSetProcessor.KEY.classForTableData() == tableData.getClass()) {
return serialize4SQL(name, tableData);
} else if (processor.classForTableData() == tableData.getClass()) {
ServerDataSetBean bean = new ServerDataSetBean();
try {
bean.setDatasetData(processor.serialize(tableData).toString());
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
bean.setDatasetData(StringUtils.EMPTY);
}
bean.setDatasetName(name);
bean.setDatasetId(name);
bean.setDatasetType(processor.nameForTableData());
return bean;
}
}
return new ServerDataSetBean(name);
}
private static ServerDataSetBean serialize4SQL(String name, TableData tableData) {
ServerDataSetBean bean = new ServerDataSetBean();
try {
bean.setDatasetData(serialize4SQL0((DBTableData) tableData).toString());
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
bean.setDatasetData(StringUtils.EMPTY);
}
bean.setDatasetName(name);
bean.setDatasetId(name);
bean.setDatasetType(SQLDataSetProcessor.KEY.nameForTableData());
return bean;
}
private static Object serialize4SQL0(DBTableData dataSet) {
SQLDataSetBean bean = new SQLDataSetBean();
if (dataSet.getDatabase() instanceof NameDatabaseConnection) {
bean.setDatabase(((NameDatabaseConnection) dataSet.getDatabase()).getName());
}
bean.setQuery(DataEncryptionHelper.encrypt(dataSet.getQuery()));
List<ParameterBean> parameterBeans = new ArrayList<>();
ParameterProvider[] parameters = dataSet.getParameters(Calculator.createCalculator());
for (ParameterProvider parameter : parameters) {
parameterBeans.add(new ParameterBean(parameter.getValue().getClass().getSimpleName(), parameter.getName(), GeneralUtils.objectToString(parameter.getValue())));
}
bean.setParameters(parameterBeans);
return JSONObject.mapFrom(bean);
}
private static TableData deserialize4SQL(Map<String, Connection> connectionMap, DBTableData oldDataSet, JSONObject object) {
DBTableData tableData = new DBTableData();
SQLDataSetBean bean = object.mapTo(SQLDataSetBean.class);
tableData.setQuery(DataEncryptionHelper.decrypt(bean.getQuery()));
Connection connection = connectionMap.get(bean.getDatabase());
if (connection != null) {
tableData.setDatabase(new NameDatabaseConnection(bean.getDatabase()));
} else {
FineLoggerFactory.getLogger().info("not find conn by {}", bean.getDatabase());
}
String sql = SqlUtils.clearSqlComments(DataEncryptionHelper.decrypt(bean.getQuery()));
Parameter[] parameters = new Parameter[bean.getParameters().size()];
for (int i = 0; i < parameters.length; i++) {
ParameterBean parameterBean = bean.getParameters().get(i);
parameters[i] = (Parameter) ParameterTypeHandler.getInstance().parseParameter(parameterBean, new Parameter(parameterBean.getName()));
}
tableData.setParameters(ParameterHelper.analyzeAndUnionSameParameters(new String[]{sql}, parameters));
if (oldDataSet != null) {
tableData.setMaxMemRowCount(oldDataSet.getMaxMemRowCount());
tableData.setPageQuerySql(oldDataSet.getPageQuerySql());
tableData.setShare(oldDataSet.isShare());
tableData.setDataQueryProcessor(oldDataSet.getDataQueryProcessor());
}
return tableData;
}
}

34
designer-base/src/main/java/com/fr/design/data/tabledata/LocalTableDataSource.java

@ -1,13 +1,18 @@
package com.fr.design.data.tabledata; package com.fr.design.data.tabledata;
import com.fanruan.config.impl.data.ConnectionConfigProviderFactory;
import com.fanruan.config.impl.data.TableDataConfigProviderFactory; import com.fanruan.config.impl.data.TableDataConfigProviderFactory;
import com.fr.base.TableData;
import com.fr.decision.webservice.bean.dataset.FileDataSetBean; import com.fr.decision.webservice.bean.dataset.FileDataSetBean;
import com.fr.decision.webservice.bean.dataset.ServerDataSetBean;
import com.fr.decision.webservice.bean.entry.FileNodeBean; import com.fr.decision.webservice.bean.entry.FileNodeBean;
import com.fr.decision.webservice.v10.datasource.dataset.processor.impl.FileProcessor; import com.fr.decision.webservice.v10.datasource.dataset.processor.impl.FileProcessor;
import com.fr.design.data.datapane.preview.TableDataBeanHelper;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import com.fr.workspace.server.repository.tabledata.BaseTableDataSource; import com.fr.workspace.server.repository.tabledata.BaseTableDataSource;
import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -61,4 +66,33 @@ public class LocalTableDataSource extends BaseTableDataSource {
return false; return false;
} }
} }
@Override
public List<ServerDataSetBean> getAllTableData() {
List<ServerDataSetBean> beans = new ArrayList<>();
TableData[] tableDatas = TableDataConfigProviderFactory.getInstance().getTableDatas().values().toArray(new TableData[0]);
for (TableData data : tableDatas) {
beans.add(TableDataBeanHelper.getServerDataSetBean(data.getName(), data));
}
return beans;
}
@Override
public void add(ServerDataSetBean bean) throws Exception {
TableDataConfigProviderFactory.getInstance().addTableData(bean.getDatasetName(), TableDataBeanHelper.getTableDataSet(ConnectionConfigProviderFactory.getConfigProvider().getConnections(), bean.getDatasetType(), bean.getDatasetData()));
}
@Override
public void delete(ServerDataSetBean bean) throws Exception {
TableDataConfigProviderFactory.getInstance().removeTableData(bean.getDatasetName());
}
@Override
public void update(ServerDataSetBean bean) throws Exception {
TableDataConfigProviderFactory.getInstance().updateTableData(bean.getDatasetName(), TableDataBeanHelper.getTableDataSet(ConnectionConfigProviderFactory.getConfigProvider().getConnections(), bean.getDatasetType(), bean.getDatasetData()));
}
} }

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

@ -15,6 +15,7 @@ import com.fr.data.impl.storeproc.StoreProcedure;
import com.fr.datacenters.tabledata.DCTableData; import com.fr.datacenters.tabledata.DCTableData;
import com.fr.decision.webservice.bean.dataset.ServerDataSetBean; import com.fr.decision.webservice.bean.dataset.ServerDataSetBean;
import com.fr.design.data.datapane.TableDataNameObjectCreator; import com.fr.design.data.datapane.TableDataNameObjectCreator;
import com.fr.design.data.datapane.preview.ConnectionInfoBeanHelper;
import com.fr.design.data.tabledata.datacenter.DCTableDataPane; import com.fr.design.data.tabledata.datacenter.DCTableDataPane;
import com.fr.design.data.tabledata.tabledatapane.AbstractTableDataPane; import com.fr.design.data.tabledata.tabledatapane.AbstractTableDataPane;
import com.fr.design.data.tabledata.tabledatapane.ClassTableDataPane; import com.fr.design.data.tabledata.tabledatapane.ClassTableDataPane;
@ -29,9 +30,8 @@ import com.fr.general.ComparatorUtils;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
import com.fr.stable.ArrayUtils; import com.fr.stable.ArrayUtils;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import com.fr.workspace.server.entity.connection.ConnectionBean;
import com.fr.workspace.server.repository.connection.ConnectionRepository; import com.fr.workspace.server.repository.connection.ConnectionRepository;
import com.fr.workspace.server.repository.tabledata.TableDataBeanHelper; import com.fr.design.data.datapane.preview.TableDataBeanHelper;
import com.fr.workspace.server.repository.tabledata.TableDataRepository; import com.fr.workspace.server.repository.tabledata.TableDataRepository;
import javax.swing.Icon; import javax.swing.Icon;
@ -205,11 +205,7 @@ public abstract class TableDataFactory {
clearAll(); clearAll();
try { try {
List<ServerDataSetBean> beans = TableDataRepository.getInstance().getAllTableData(); List<ServerDataSetBean> beans = TableDataRepository.getInstance().getAllTableData();
final List<ConnectionBean> connectionInfoBeans = ConnectionRepository.getInstance().getAll(); final Map<String, Connection> connectionMap = ConnectionInfoBeanHelper.createConnectionMap(ConnectionRepository.getInstance().getAll());
final Map<String, Connection> connectionMap = new HashMap<>();
for (ConnectionBean bean : connectionInfoBeans) {
connectionMap.put(bean.getName(), bean.getConnection());
}
Map<String, TableData> tableDataMap = new HashMap<>(); Map<String, TableData> tableDataMap = new HashMap<>();
for (ServerDataSetBean bean : beans) { for (ServerDataSetBean bean : beans) {
tableDataMap.put(bean.getDatasetName(), TableDataBeanHelper.getTableDataSet(connectionMap, bean.getDatasetType(), bean.getDatasetData())); tableDataMap.put(bean.getDatasetName(), TableDataBeanHelper.getTableDataSet(connectionMap, bean.getDatasetType(), bean.getDatasetData()));
@ -233,11 +229,7 @@ public abstract class TableDataFactory {
Map<String, TableData> tableDataMap = new HashMap<>(); Map<String, TableData> tableDataMap = new HashMap<>();
try { try {
List<ServerDataSetBean> beans = TableDataRepository.getInstance().getAllTableData(); List<ServerDataSetBean> beans = TableDataRepository.getInstance().getAllTableData();
final List<ConnectionBean> connectionInfoBeans = ConnectionRepository.getInstance().getAll(); final Map<String, Connection> connectionMap = ConnectionInfoBeanHelper.createConnectionMap(ConnectionRepository.getInstance().getAll());
final Map<String, Connection> connectionMap = new HashMap<>();
for (ConnectionBean bean : connectionInfoBeans) {
connectionMap.put(bean.getName(), bean.getConnection());
}
for (ServerDataSetBean bean : beans) { for (ServerDataSetBean bean : beans) {
tableDataMap.put(bean.getDatasetName(), TableDataBeanHelper.getTableDataSet(connectionMap, bean.getDatasetType(), bean.getDatasetData())); tableDataMap.put(bean.getDatasetName(), TableDataBeanHelper.getTableDataSet(connectionMap, bean.getDatasetType(), bean.getDatasetData()));
} }

Loading…
Cancel
Save