diff --git a/designer-base/src/main/java/com/fr/design/backup/EnvBackupHelper.java b/designer-base/src/main/java/com/fr/design/backup/EnvBackupHelper.java index 6ea52fd764..bb9575ea19 100644 --- a/designer-base/src/main/java/com/fr/design/backup/EnvBackupHelper.java +++ b/designer-base/src/main/java/com/fr/design/backup/EnvBackupHelper.java @@ -5,6 +5,7 @@ import com.fanruan.config.realm.ConfigRepositoryFactory; import com.fanruan.config.realm.local.LocalConfigRepositoryBuilder; import com.fr.design.ConfigHelper; import com.fr.design.mem.MemConfigBackupManager; +import com.fr.design.mem.MemConfigRepositoryBuilder; import com.fr.log.FineLoggerFactory; import com.fr.workspace.WorkContext; import com.fr.workspace.Workspace; @@ -71,6 +72,10 @@ public class EnvBackupHelper { } else { // 如果是切到远程,先暂时用备份的内存配置,成功后再转到新配置,失败则切回原内存配置 MemConfigBackupManager.getInstance().startSwitch(); + if (local) { + // 原来不是远程,需要先切一下内存配置框架 + ConfigRepositoryFactory.getInstance().registerConfigRepositoryBuilder(new MemConfigRepositoryBuilder()); + } } } diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionComboBoxPanel.java b/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionComboBoxPanel.java index 28f9b0d507..cafae19695 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionComboBoxPanel.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionComboBoxPanel.java @@ -13,8 +13,8 @@ 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.connection.DBConnectAuth; import com.fr.workspace.server.repository.authority.RemoteAuthorityRepository; +import com.fr.workspace.server.repository.connection.ConnectionRepository; import javax.swing.SwingUtilities; import java.awt.Dimension; @@ -80,7 +80,7 @@ public class ConnectionComboBoxPanel extends ItemEditableComboBoxPanel { * 刷新ComboBox.items */ protected Iterator items() { - Iterator nameIt = ConnectionConfigProviderFactory.getConfigProvider().getConnections().keySet().iterator(); + Iterator nameIt = ConnectionRepository.getInstance().getConnNames().iterator(); Collection noAuthConnections = RemoteAuthorityRepository.getInstance().getNoAuthConnections(); @@ -94,7 +94,7 @@ public class ConnectionComboBoxPanel extends ItemEditableComboBoxPanel { if (noAuthConnections.contains(conName)) { continue; } - Connection connection = ConnectionConfigProviderFactory.getConfigProvider().getConnection(conName); + Connection connection = ConnectionRepository.getInstance().getByName(conName).getConnection(); // nameList依赖items方法初始化,父类ItemEditableComboBoxPanel里异步执行item方法 filterConnection(connection, conName, nameList); } diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionListPane.java b/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionListPane.java index fd10c25fdf..94debc6c5b 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionListPane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionListPane.java @@ -3,12 +3,11 @@ package com.fr.design.data.datapane.connect; import com.fanruan.config.impl.data.ConnectionConfigProviderFactory; import com.fanruan.config.impl.data.ConnectionConfigWriterFactory; import com.fr.config.remote.RemoteConfigEvent; -import com.fr.data.driver.DriverClassNotFoundException; import com.fr.data.impl.Connection; import com.fr.data.impl.JDBCDatabaseConnection; import com.fr.data.impl.JNDIDatabaseConnection; -import com.fr.data.metric.utils.DatabaseConnectionMetricHandler; -import com.fr.data.operator.DataOperator; +import com.fr.decision.webservice.bean.datasource.ConnectionInfoBean; +import com.fr.decision.webservice.v10.datasource.connection.processor.impl.ConnectionProcessorFactory; import com.fr.design.ExtraDesignClassManager; import com.fr.design.data.MapCompareUtils; import com.fr.design.dialog.BasicDialog; @@ -219,27 +218,25 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh Arrays.stream(res).map(n -> (NameObject) n).forEach(no -> updatedMap.put(no.getName(), (Connection) no.getObject())); List removedConnNames = new ArrayList<>(); - List addConnections = new ArrayList<>(); - List updateConnection = new ArrayList<>(); + List addConnections = new ArrayList<>(); + List updateConnection = new ArrayList<>(); MapCompareUtils.contrastMapEntries(populatedConnectionsSnapshot, updatedMap, (entryEventKind, s, connection) -> { - switch (entryEventKind) { - case REMOVED: - removedConnNames.add(s); - break; - case ADDED: - addConnections.add(new ConnectionBean(connection, s)); - if (connection instanceof JDBCDatabaseConnection) { - DatabaseConnectionMetricHandler.handleSaveConnection((JDBCDatabaseConnection) connection, null); - } - break; - case UPDATED: - updateConnection.add(new ConnectionBean(connection, s)); - if (connection instanceof JDBCDatabaseConnection) { - DatabaseConnectionMetricHandler.handleSaveConnection((JDBCDatabaseConnection) connection, null); - } - break; - default: - break; + try { + switch (entryEventKind) { + case REMOVED: + removedConnNames.add(s); + break; + case ADDED: + addConnections.add(ConnectionProcessorFactory.createConnectionInfoBean(s, connection)); + break; + case UPDATED: + updateConnection.add(ConnectionProcessorFactory.createConnectionInfoBean(s, connection)); + break; + default: + break; + } + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); } }, new MapCompareUtils.UpdateRule() { @Override @@ -269,23 +266,22 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh } }); - List validateBeans = new ArrayList<>(); + List validateBeans = new ArrayList<>(); validateBeans.addAll(addConnections); validateBeans.addAll(updateConnection); this.validateDatabaseType(validateBeans); - this.validateConnections(validateBeans); - this.alterConnections(new BatchConnectionModifyBean(addConnections, removedConnNames, updateConnection)); + this.alterConnections(addConnections, removedConnNames, updateConnection); } /** * 校验是否支持所有新增和修改数据连接的数据库类型 */ - public void validateDatabaseType(@NotNull List addedOrUpdatedConnections) { + public void validateDatabaseType(@NotNull List addedOrUpdatedConnections) throws Exception { Set notSupportedConnections = new HashSet<>(); if (!addedOrUpdatedConnections.isEmpty()) { - for (ConnectionBean bean : addedOrUpdatedConnections) { - Connection connection = bean.getConnection(); - // 仅校验jdbc连接,其他插件数据连接不进行校验 + for (ConnectionInfoBean bean : addedOrUpdatedConnections) { + Connection connection = ConnectionProcessorFactory.createConnection(bean); + // 仅校验jdbc连接,其他插件数据连接不进行校验; if (connection instanceof JDBCDatabaseConnection) { DBTypes dataBaseTypePoint = DataBaseTypePointManager.getInstance().getDataBaseTypePoint(connection.getDriver(), connection.feature()); if (connectionIsNotSupported(connection, dataBaseTypePoint)) { @@ -322,25 +318,18 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh } - private void validateConnections(List addedOrUpdatedConnections) throws Exception { - - for (ConnectionBean connectionBean : addedOrUpdatedConnections) { - Connection connection = connectionBean.getConnection(); - try { - ConnectionRepository.getInstance().validSettings(new com.fr.workspace.server.entity.connection.ConnectionBean(connection)); - } catch (DriverClassNotFoundException e) { - FineLoggerFactory.getLogger().info(e.getMessage()); - } catch (Exception e) { - throw new SQLException(Toolkit.i18nText("Fine-Design_Basic_Database_Connection_Invalid_Config", connectionBean.getName()) + ", " + e.getMessage(), e.getCause()); - } - } - - } - - private void alterConnections(BatchConnectionModifyBean bean) { + private void alterConnections(List addConnections, List removedConnNames, List updateConnection) { try { - ConnectionRepository.getInstance().save(bean); + for (ConnectionInfoBean bean : addConnections) { + ConnectionRepository.getInstance().add(bean); + } + for (ConnectionInfoBean bean : updateConnection) { + ConnectionRepository.getInstance().update(bean); + } + for (String name : removedConnNames) { + ConnectionRepository.getInstance().delete(new ConnectionInfoBean(name)); + } // hades:远程环境时,由于时直接RPC调用远程修改,因此设计器本地配置需要失效 if (!WorkContext.getCurrent().isLocal()) { EventDispatcher.fire(RemoteConfigEvent.EDIT, "ConnectionConfig"); diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/connect/JDBCDefPane.java b/designer-base/src/main/java/com/fr/design/data/datapane/connect/JDBCDefPane.java index e8c7c17b8e..988ad0c94a 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/connect/JDBCDefPane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/connect/JDBCDefPane.java @@ -451,8 +451,8 @@ public class JDBCDefPane extends JPanel { jdbcDatabase.setPassword(new String(this.passwordTextField.getPassword()).trim()); jdbcDatabase.setOriginalCharsetName(this.originalCharSet); if (this.charSetComboBox.getSelectedIndex() == 0) { - jdbcDatabase.setNewCharsetName(null); - jdbcDatabase.setOriginalCharsetName(null); + jdbcDatabase.setNewCharsetName(StringUtils.EMPTY); + jdbcDatabase.setOriginalCharsetName(StringUtils.EMPTY); } else { jdbcDatabase.setNewCharsetName(EncodeConstants.ENCODING_GBK); jdbcDatabase.setOriginalCharsetName(((String) this.charSetComboBox.getSelectedItem())); diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/connect/LocalConnectionSource.java b/designer-base/src/main/java/com/fr/design/data/datapane/connect/LocalConnectionSource.java new file mode 100644 index 0000000000..0935de229d --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/data/datapane/connect/LocalConnectionSource.java @@ -0,0 +1,67 @@ +package com.fr.design.data.datapane.connect; + +import com.fr.data.driver.DriverClassNotFoundException; +import com.fr.data.impl.Connection; +import com.fr.decision.webservice.bean.datasource.ConnectionInfoBean; +import com.fr.decision.webservice.v10.datasource.connection.processor.impl.ConnectionProcessorFactory; +import com.fr.design.i18n.Toolkit; +import com.fr.log.FineLoggerFactory; +import com.fr.workspace.server.repository.connection.BaseConnectionSource; +import java.sql.SQLException; + +/** + * 本地Connection资源操作 + * + * @author Destiny.Lin + * @since 11.0 + * Created on 2024/5/29 + */ +public class LocalConnectionSource extends BaseConnectionSource { + + @Override + public void add(ConnectionInfoBean bean) throws Exception { + Connection connection = ConnectionProcessorFactory.createConnection(bean); + validate(bean.getConnectionName(), connection); + ConnectionProcessorFactory.addConnection(bean); + } + + @Override + public void delete(ConnectionInfoBean bean) throws Exception { + ConnectionProcessorFactory.deleteConnection(bean.getConnectionName()); + } + + @Override + public void update(ConnectionInfoBean bean) throws Exception { + Connection connection = ConnectionProcessorFactory.createConnection(bean); + validate(bean.getConnectionName(), connection); + ConnectionProcessorFactory.updateConnection(bean.getConnectionName(), bean); + } + + @Override + public boolean lock(String str) { + // 本地默认锁定成功,让其执行后续动作 + return true; + } + + @Override + public boolean unlock(String str) { + // 本地默认解锁成功 + return true; + } + + @Override + public boolean isLock(String str) { + // 本地默认未锁定 + return false; + } + + private void validate(String name, Connection connection) throws SQLException { + try { + connection.validateSettings(); + } catch (DriverClassNotFoundException e) { + FineLoggerFactory.getLogger().info(e.getMessage()); + } catch (Exception e) { + throw new SQLException(Toolkit.i18nText("Fine-Design_Basic_Database_Connection_Invalid_Config", name) + ", " + e.getMessage(), e.getCause()); + } + } +} diff --git a/designer-base/src/main/java/com/fr/design/gui/ilist/TableViewList.java b/designer-base/src/main/java/com/fr/design/gui/ilist/TableViewList.java index ab5c67678e..83b7008a7e 100644 --- a/designer-base/src/main/java/com/fr/design/gui/ilist/TableViewList.java +++ b/designer-base/src/main/java/com/fr/design/gui/ilist/TableViewList.java @@ -15,6 +15,8 @@ import com.fr.general.ComparatorUtils; import com.fr.log.FineLoggerFactory; import com.fr.stable.ArrayUtils; import com.fr.stable.StringUtils; +import com.fr.workspace.server.entity.connection.ConnectionBean; +import com.fr.workspace.server.repository.connection.ConnectionRepository; import javax.swing.DefaultListCellRenderer; import javax.swing.DefaultListModel; @@ -95,13 +97,18 @@ public class TableViewList extends UIList { @Override protected DefaultListModel doInBackground() throws Exception { - Connection datasource = ConnectionConfigProviderFactory.getConfigProvider().getConnection(databaseName); + Connection datasource = ConnectionRepository.getInstance().getByName(databaseName).getConnection(); boolean status = false; int count = 3; //总共给3次连接的机会 while (!status && count > 0) { - status = DataOperator.getInstance().testConnection(datasource); - count--; + try { + ConnectionRepository.getInstance().testConnection(new ConnectionBean(datasource)); + status = true; + break; + } catch (Exception e) { + count--; + } } if (!status) { throw new Exception(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Database_Connection_Failed")); diff --git a/designer-realize/src/main/java/com/fanruan/boot/env/DesignEnvComponent.java b/designer-realize/src/main/java/com/fanruan/boot/env/DesignEnvComponent.java index 0621a6a7ae..700fc12258 100644 --- a/designer-realize/src/main/java/com/fanruan/boot/env/DesignEnvComponent.java +++ b/designer-realize/src/main/java/com/fanruan/boot/env/DesignEnvComponent.java @@ -26,6 +26,7 @@ import com.fanruan.kv.factory.KVStoreFactory; import com.fanruan.kv.manager.CarinaKVManager; import com.fanruan.kv.store.KVStore; import com.fanruan.kv.store.KVStoreHolder; +import com.fanruan.workplace.http.RepositoryManager; import com.fr.cbb.dialect.security.InsecurityElementFactory; import com.fr.cluster.ClusterBridge; import com.fr.cluster.lock.ClusterLock; @@ -48,11 +49,6 @@ import com.fr.config.holder.ValidateConfigManger; import com.fr.config.impl.ConfConfigProviderImpl; import com.fr.config.impl.ConfigInsecurityElementProviderImpl; import com.fr.decision.service.context.ServiceContext; -import com.fr.decision.webservice.v10.datasource.connection.processor.impl.ConnectionPluginProcessor; -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.JDYConnectionProcessor; -import com.fr.decision.webservice.v10.datasource.connection.processor.impl.JNDIConnectionProcessor; import com.fr.design.backup.EnvBackupHelper; import com.fr.env.detect.EnvDetectorCenter; import com.fr.event.EventDispatcher; @@ -79,6 +75,7 @@ import com.fr.scheduler.QuartzContext; import com.fr.scheduler.SchedulerEvent; import com.fr.scheduler.tenant.ScheduleThreadCurrentTenantProvider; import com.fr.security.encryption.EncryptionInitialization; +import com.fr.security.encryption.SystemEncryptionManager; import com.fr.security.encryption.core.EncryptionScaffold; import com.fr.security.encryption.provider.SecuritySeedProvider; import com.fr.security.encryption.storage.keys.LoadSeedSecurityKey; @@ -273,11 +270,11 @@ public class DesignEnvComponent { private void startFileServer() throws Exception { if (WorkContext.getCurrent().isLocal()) { // 设计器远程下不需要文件系统,走PublicRepo的接口,本地下走基础的磁盘读写 - LocalFileRepository localFileRepository = new LocalFileRepository(ProjectConstants.LOCAL_ENV, ServiceContext.getWebInfPath()); + LocalFileRepository.getSingleton().setWorkRoot(ServiceContext.getWebInfPath()); ResourceRepository realRepo = RepositoryFactory.getRepo(); FSProperties fsProperties = Carina.properties(FSProperties.class); FileServer.init( - new ResourceRepositoryWrapper(localFileRepository, StringUtils.EMPTY), + new ResourceRepositoryWrapper(LocalFileRepository.getSingleton(), StringUtils.EMPTY), new ResourceRepositoryWrapper(realRepo, StringUtils.EMPTY), new ResourceRepositoryWrapper(realRepo, StringUtils.EMPTY), new ResourceRepositoryWrapper(realRepo.generateTenantsSharedRepo(fsProperties.getTenantsSharedNamespace()), StringUtils.EMPTY)); @@ -383,6 +380,9 @@ public class DesignEnvComponent { } }); LoadSeedSecurityKey.getInstance().init(); + } else { + // 远程也先写死加解密,放在内存中就好,fbp那边暂时没有提供扩展,两边都是写死的,等他们提供扩展后设计器再适配 + SystemEncryptionManager.getInstance().restore(); } } @@ -403,5 +403,10 @@ public class DesignEnvComponent { private void startEnvPrepare() { EnvDetectorCenter.getInstance().init(); + if (WorkContext.getCurrent().isLocal()) { + // 如果是切回本地,要初始化成本地仓库 + // 如果是切回远程,会在用户创建的时候就同步初始化远程仓库 + RepositoryManager.getInstance().initLocalRepository(); + } } } diff --git a/designer-realize/src/main/java/com/fanruan/boot/env/function/DesignDatasourceComponent.java b/designer-realize/src/main/java/com/fanruan/boot/env/function/DesignDatasourceComponent.java index c6f277535d..a4a84e1063 100644 --- a/designer-realize/src/main/java/com/fanruan/boot/env/function/DesignDatasourceComponent.java +++ b/designer-realize/src/main/java/com/fanruan/boot/env/function/DesignDatasourceComponent.java @@ -15,7 +15,9 @@ import com.fr.decision.webservice.v10.datasource.connection.processor.impl.Conne import com.fr.decision.webservice.v10.datasource.connection.processor.impl.JDBCConnectionProcessor; import com.fr.decision.webservice.v10.datasource.connection.processor.impl.JDYConnectionProcessor; import com.fr.decision.webservice.v10.datasource.connection.processor.impl.JNDIConnectionProcessor; +import com.fr.design.data.datapane.connect.LocalConnectionSource; import com.fr.workspace.server.repository.connection.ConnectionWriterShell; +import com.fr.workspace.server.repository.connection.LocalConnectionShell; /** @@ -40,6 +42,7 @@ public class DesignDatasourceComponent extends DatasourceComponent { ConnectionProcessorFactory.register(JNDIConnectionProcessor.KEY); ConnectionProcessorFactory.register(ConnectionPluginProcessor.KEY); ConnectionProcessorFactory.register(JDYConnectionProcessor.KEY); + Carina.getApplicationContext().singleton(LocalConnectionShell.class).set(new LocalConnectionSource()); } /**