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/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())); + } 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