From b0c8f2fefa66497c4ae2f6ceb99cb36edc55cecb Mon Sep 17 00:00:00 2001 From: "Destiny.Lin" Date: Tue, 30 Jul 2024 17:05:12 +0800 Subject: [PATCH 1/2] =?UTF-8?q?REPORT-114392=20FR-FBP=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E6=9C=AC=E5=9C=B0=E8=AE=BE=E8=AE=A1=E9=80=82=E9=85=8D=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=95=B0=E6=8D=AE=E8=BF=9E=E6=8E=A5=E4=B8=8E?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E9=9B=86=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../function/DesignDatasourceComponent.java | 18 +- .../fanruan/data/ConnectionConfigWrapper.java | 158 ++++++++++++++++++ 2 files changed, 175 insertions(+), 1 deletion(-) create mode 100644 designer-realize/src/main/java/com/fanruan/data/ConnectionConfigWrapper.java 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 a4a84e1063..d849febf51 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 @@ -10,12 +10,19 @@ import com.fanruan.carina.annotions.Supplemental; import com.fanruan.config.impl.data.ConnectionConfigProviderFactory; import com.fanruan.config.impl.data.ConnectionConfigWriter; import com.fanruan.config.impl.data.ConnectionConfigWriterFactory; +import com.fanruan.config.impl.data.TableDataConfigProviderFactory; +import com.fanruan.data.ConnectionConfigWrapper; +import com.fr.data.driver.classloader.DriverClassLoaderHelper; +import com.fr.data.driver.classloader.impl.ChildFirstDriverClassLoader; +import com.fr.data.driver.classloader.impl.ChildOnlyDriverClassLoader; +import com.fr.data.driver.constants.DriverLoaderStrategies; 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.data.datapane.connect.LocalConnectionSource; +import com.fr.file.TableDataConfigWrapper; import com.fr.workspace.server.repository.connection.ConnectionWriterShell; import com.fr.workspace.server.repository.connection.LocalConnectionShell; @@ -50,11 +57,20 @@ public class DesignDatasourceComponent extends DatasourceComponent { */ @Start public void start() { - super.start(); + // 服务器数据集与数据连接设计器这边先手动切为finedb存储,后续数据中心适配后再切为他们提供的wrapper + ConnectionConfigProviderFactory.registerConnectionConfigProvider(ConnectionConfigWrapper.getInstance()); + TableDataConfigProviderFactory.getInstance().registerTableDataConfigProvider(new TableDataConfigWrapper()); + registerDriverClassLoader(); ConnectionConfigWriterFactory.registerConnectionConfigWriter((ConnectionConfigWriter) ConnectionConfigProviderFactory.getConfigProvider()); Carina.getApplicationContext().singleton(ConnectionWriterShell.class).set(ConnectionConfigWriterFactory.getConfigWriter()); } + private void registerDriverClassLoader() { + DriverClassLoaderHelper.INSTANCE.register(DriverLoaderStrategies.CHILD_FIRST, ChildFirstDriverClassLoader.class); + DriverClassLoaderHelper.INSTANCE.register(DriverLoaderStrategies.CHILD_ONLY, ChildOnlyDriverClassLoader.class); + } + + /** * stop */ diff --git a/designer-realize/src/main/java/com/fanruan/data/ConnectionConfigWrapper.java b/designer-realize/src/main/java/com/fanruan/data/ConnectionConfigWrapper.java new file mode 100644 index 0000000000..ac898903e8 --- /dev/null +++ b/designer-realize/src/main/java/com/fanruan/data/ConnectionConfigWrapper.java @@ -0,0 +1,158 @@ +package com.fanruan.data; + +import com.fanruan.config.impl.data.ConnectionConfigProvider; +import com.fanruan.config.impl.data.ConnectionConfigWriter; +import com.fr.data.impl.Connection; +import com.fr.file.ConnectionConfig; +import com.fr.transaction.Configurations; +import com.fr.transaction.WorkerAdaptor; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.HashMap; +import java.util.Map; + +/** + * 对数据连接的配置封装,包装了事务 + * + * @author Destiny.Lin + * @since 11.0 + * Created on 2024/7/30 + */ +public class ConnectionConfigWrapper implements ConnectionConfigProvider, ConnectionConfigWriter { + + private static final ConnectionConfigWrapper INSTANCE = new ConnectionConfigWrapper(); + + private ConnectionConfigWrapper() { + + } + + public static ConnectionConfigWrapper getInstance() { + return INSTANCE; + } + + @Override + public Map getConnections() { + Map connectionMap = new HashMap<>(ConnectionConfig.getInstance().getConnections()); + for (Map.Entry entry : connectionMap.entrySet()) { + entry.getValue().setConnectionName(entry.getKey()); + } + return connectionMap; + } + + @Override + public Map getConnectionsWithoutCheck() { + Map connectionMap = new HashMap<>(ConnectionConfig.getInstance().getConnectionsWithoutCheck()); + for (Map.Entry entry : connectionMap.entrySet()) { + entry.getValue().setConnectionName(entry.getKey()); + } + return connectionMap; + } + + @Override + public Map getDesignateConnections(Class clazz) { + Map connectionMap = new HashMap<>(ConnectionConfig.getInstance().getDesignateConnections(clazz)); + for (Map.Entry entry : connectionMap.entrySet()) { + entry.getValue().setConnectionName(entry.getKey()); + } + return connectionMap; + } + + @Override + public void addConnection(String connectionName, Connection connection) { + Configurations.update(new WorkerAdaptor(ConnectionConfig.class) { + @Override + public void run() { + ConnectionConfig.getInstance().addConnection(connectionName, connection); + } + }); + } + + @Override + public int getRemainingCon(int remove, int add) { + return ConnectionConfig.getInstance().getRemainingCon(remove, add); + } + + @Override + public void addConnectionWithoutCheck(String connectionName, Connection connection) { + Configurations.update(new WorkerAdaptor(ConnectionConfig.class) { + @Override + public void run() { + ConnectionConfig.getInstance().addConnectionWithoutCheck(connectionName, connection); + } + }); + } + + @Override + public void removeConnection(String connectionName) { + Configurations.update(new WorkerAdaptor(ConnectionConfig.class) { + @Override + public void run() { + ConnectionConfig.getInstance().removeConnection(connectionName); + } + }); + } + + @Override + public void renameConnection(String oldName, String newName) { + Configurations.update(new WorkerAdaptor(ConnectionConfig.class) { + @Override + public void run() { + ConnectionConfig.getInstance().renameConnection(oldName, newName); + } + }); + } + + @Override + public @Nullable Connection getConnection(@NotNull String connectionName) { + Connection connection = ConnectionConfig.getInstance().getConnection(connectionName); + if (connection != null) { + connection.setConnectionName(connectionName); + } + return connection; + } + + @Override + public @Nullable Connection getConnectionWithoutCheck(String connectionName) { + Connection connection = ConnectionConfig.getInstance().getConnectionWithoutCheck(connectionName); + if (connection != null) { + connection.setConnectionName(connectionName); + } + return connection; + } + + @Override + public void removeAllConnection() { + Configurations.update(new WorkerAdaptor(ConnectionConfig.class) { + @Override + public void run() { + ConnectionConfig.getInstance().removeAllConnection(); + } + }); + } + + @Override + public void updateConnection(String connName, Connection connection) { + Configurations.update(new WorkerAdaptor(ConnectionConfig.class) { + @Override + public void run() { + ConnectionConfig.getInstance().addConnection(connName, connection); + } + }); + } + + @Override + public boolean isPutPermitted() { + return ConnectionConfig.getInstance().isPutPermitted(); + } + + @Override + public void safeRemoveAll() { + Configurations.update(new WorkerAdaptor(ConnectionConfig.class) { + @Override + public void run() { + ConnectionConfig.getInstance().safeRemoveAll(); + } + }); + } +} \ No newline at end of file From 46e55e1af2d30ad247c32b9057e5cc2912822d2f Mon Sep 17 00:00:00 2001 From: kerry Date: Wed, 31 Jul 2024 13:48:30 +0800 Subject: [PATCH 2/2] =?UTF-8?q?REPORT-126235=20=20=E6=94=BE=E5=BC=80?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=E7=9A=84classFinder?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fanruan/boot/init/DesignPreLoadComponent.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/designer-realize/src/main/java/com/fanruan/boot/init/DesignPreLoadComponent.java b/designer-realize/src/main/java/com/fanruan/boot/init/DesignPreLoadComponent.java index 575ed1cace..6773531811 100644 --- a/designer-realize/src/main/java/com/fanruan/boot/init/DesignPreLoadComponent.java +++ b/designer-realize/src/main/java/com/fanruan/boot/init/DesignPreLoadComponent.java @@ -45,6 +45,7 @@ import com.fr.locale.LocaleScope; import com.fr.locale.LocaleUtils; import com.fr.log.FineLoggerFactory; import com.fr.measure.DBMeterFactory; +import com.fr.plugin.manage.PluginManager; import com.fr.record.DefaultDBMeter; import com.fr.record.analyzer.EnableMetrics; import com.fr.record.analyzer.Metrics; @@ -56,6 +57,7 @@ import com.fr.stable.bridge.StableFactory; import com.fr.stable.fun.WebLocaleProvider; import com.fr.stable.plugin.ExtraClassManagerProvider; import com.fr.stable.project.ProjectConstants; +import com.fr.stable.resource.ResourceLoader; import com.fr.stable.xml.StableXMLUtils; import com.fr.start.DesignerProcessType; import com.fr.start.module.StartupArgs; @@ -216,6 +218,10 @@ public class DesignPreLoadComponent { } return Class.forName(className, true, urlClassLoader); }); + + ClassFactory.getInstance().addFinder(className -> ResourceLoader.classForName(className)); + ClassFactory.getInstance().addFinder(className -> Class.forName(className, true, PluginManager.getController().getClass().getClassLoader())); + }