diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/ChoosePane.java b/designer-base/src/main/java/com/fr/design/data/datapane/ChoosePane.java index 4229b54036..49af47f2ca 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/ChoosePane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/ChoosePane.java @@ -332,7 +332,7 @@ public class ChoosePane extends BasicBeanPane implements Refresha List authConnections = getHasAuthConnections(); for (String name : authConnections) { if (ComparatorUtils.equals(selectedDSName, name)) { - return ConnectionRepository.getInstance().getByName(name).getConnection(); + return ConnectionInfoBeanHelper.createConnection(ConnectionRepository.getInstance().getByName(name)); } } return null; @@ -442,7 +442,7 @@ public class ChoosePane extends BasicBeanPane implements Refresha boolean connect = false; com.fr.data.impl.Connection database = null; try { - database = ConnectionRepository.getInstance().getByName(paras.getDatabaseName()).getConnection(); + database = ConnectionInfoBeanHelper.createConnection(ConnectionRepository.getInstance().getByName(paras.getDatabaseName())); } catch (Exception e) { FineLoggerFactory.getLogger().info(e.getMessage(), e); } 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 index bfad0a1850..1aaa2fb46a 100644 --- 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 @@ -41,11 +41,20 @@ public class LocalConnectionSource extends BaseConnectionSource { } @Override - public void testConnection(ConnectionInfoBean database) throws Exception { + public ConnectionInfoBean getByName(String name) { + try { + return ConnectionInfoBeanHelper.createConnectionInfoBean(name, ConnectionConfigProviderFactory.getConfigProvider().getConnection(name)); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + @Override + public String[] testConnection(ConnectionInfoBean database) throws Exception { try { // 暂时这么处理,后续最好拉到外层包装一下 TransmissionEncryptionManager.setTransEncryptionLevel(1); - ConnectionProcessorFactory.testConnectionWithSchemaReturn(database); + return ConnectionProcessorFactory.testConnectionWithSchemaReturn(database); } catch (DriverNotFoundException e) { throw new DriverUnExistException(); } finally { diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/preview/ConnectionInfoBeanHelper.java b/designer-base/src/main/java/com/fr/design/data/datapane/preview/ConnectionInfoBeanHelper.java index 6ad25c57c6..26ae869fcd 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/preview/ConnectionInfoBeanHelper.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/preview/ConnectionInfoBeanHelper.java @@ -78,13 +78,29 @@ public class ConnectionInfoBeanHelper { return ans; } + /** + * 根据bean创建连接 + */ + public static Connection createConnection(ConnectionInfoBean infoBean) { + try { + if (JDBCConnectionProcessor.KEY.acceptConnectionTypes().contains(infoBean.getConnectionType())) { + return createJDBCConnection(infoBean); + } else { + return ConnectionProcessorFactory.createConnection(infoBean, true); + } + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + return null; + } + } + /** * 创建数据连接Bean,可自定义是否携带密码 */ public static ConnectionInfoBean createConnectionInfoBean(String name, Connection connection, boolean withPassword) throws Exception { if (connection instanceof NameDatabaseConnection) { name = ((NameDatabaseConnection) connection).getName(); - connection = ConnectionRepository.getInstance().getByName(name).getConnection(); + connection = createConnection(ConnectionRepository.getInstance().getByName(name)); } if (JDBCConnectionProcessor.KEY.acceptConnections().contains(connection.getClass())) { ConnectionInfoBean bean = new ConnectionInfoBean(); diff --git a/designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/ProcedureDataPane.java b/designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/ProcedureDataPane.java index a5ced9dfe0..e1d9263c90 100644 --- a/designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/ProcedureDataPane.java +++ b/designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/ProcedureDataPane.java @@ -20,6 +20,7 @@ import com.fr.design.data.DesignTableDataManager; import com.fr.design.data.datapane.TableDataTreePane; import com.fr.design.data.datapane.connect.ConnectionTableProcedurePane; import com.fr.design.data.datapane.connect.ConnectionTableProcedurePane.DoubleClickSelectedNodeOnTreeListener; +import com.fr.design.data.datapane.preview.ConnectionInfoBeanHelper; import com.fr.design.data.datapane.sqlpane.SQLEditPane; import com.fr.design.data.tabledata.ResponseDataSourceChange; import com.fr.design.data.tabledata.StoreProcedureWorkerListener; @@ -187,8 +188,7 @@ public class ProcedureDataPane extends AbstractTableDataPane imp } private boolean isAutoParameterDatabase() { - ConnectionBean bean = ConnectionRepository.getInstance().getByName(connectionTableProcedurePane.getSelectedDatabaseConnnectonName()); - Connection connection = bean == null ? null : bean.getConnection(); + Connection connection = ConnectionInfoBeanHelper.createConnection(ConnectionRepository.getInstance().getByName(connectionTableProcedurePane.getSelectedDatabaseConnnectonName())); return connection != null && ArrayUtils.contains(DRIVERS, connection.getDriver()); } 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 b0483dfdd3..682e68be7d 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 @@ -104,7 +104,7 @@ public class TableViewList extends UIList { @Override protected DefaultListModel doInBackground() throws Exception { - Connection datasource = ConnectionRepository.getInstance().getByName(databaseName).getConnection(); + Connection datasource = ConnectionInfoBeanHelper.createConnection(ConnectionRepository.getInstance().getByName(databaseName)); boolean status = false; int count = 3; //总共给3次连接的机会 @@ -168,7 +168,7 @@ public class TableViewList extends UIList { */ private DefaultListModel processDataInAnotherThread(String databaseName, String searchFilter, String... typesFilter) throws Exception { DefaultListModel defaultListModel = new DefaultListModel(); - Connection datasource = ConnectionRepository.getInstance().getByName(databaseName).getConnection(); + Connection datasource = ConnectionInfoBeanHelper.createConnection(ConnectionRepository.getInstance().getByName(databaseName)); if (datasource == null) { return defaultListModel; } diff --git a/designer-base/src/main/java/com/fr/design/present/dict/DatabaseDictPane.java b/designer-base/src/main/java/com/fr/design/present/dict/DatabaseDictPane.java index 2c1f46a4a1..aa126574ea 100644 --- a/designer-base/src/main/java/com/fr/design/present/dict/DatabaseDictPane.java +++ b/designer-base/src/main/java/com/fr/design/present/dict/DatabaseDictPane.java @@ -15,6 +15,7 @@ import com.fr.design.data.DesignTableDataManager; import com.fr.design.data.datapane.ChoosePane; import com.fr.design.data.datapane.DataBaseItems; import com.fr.design.data.datapane.VerticalChoosePane; +import com.fr.design.data.datapane.preview.ConnectionInfoBeanHelper; import com.fr.design.data.datapane.preview.PreviewLabel.Previewable; import com.fr.design.editor.DoubleDeckValueEditorPane; import com.fr.design.editor.editor.ColumnIndexEditor; @@ -178,7 +179,7 @@ public class DatabaseDictPane extends FurtherBasicBeanPane i if (StringUtils.isBlank(para.getDatabaseName())) { dbDict.setDatabaseConnection(null); } else { - Connection connection = ConnectionRepository.getInstance().getByName(para.getDatabaseName()).getConnection(); + Connection connection = ConnectionInfoBeanHelper.createConnection(ConnectionRepository.getInstance().getByName(para.getDatabaseName())); if (connection != null) { database = new NameDatabaseConnection(para.getDatabaseName()); dbDict.setDatabaseConnection(database); diff --git a/designer-base/src/main/java/com/fr/file/FILEChooserPane.java b/designer-base/src/main/java/com/fr/file/FILEChooserPane.java index 2cf1016c48..8b6d645fb3 100644 --- a/designer-base/src/main/java/com/fr/file/FILEChooserPane.java +++ b/designer-base/src/main/java/com/fr/file/FILEChooserPane.java @@ -1092,7 +1092,29 @@ public class FILEChooserPane extends BasicPane { String lastDirectoryPath = DesignerEnvManager.getEnvManager().getDialogCurrentDirectory(); String prefix = DesignerEnvManager.getEnvManager().getCurrentDirectoryPrefix(); FILE lastDirectory = FILEFactory.createFolder(prefix + lastDirectoryPath); + dealCurrentDirectory(model, lastDirectory) ; + } + + + + private void setPlaceListModel4DataFile(AbstractPlaceListModel model) { + if (placesList == null) { + return; + } + placesList.setModel(model); + String lastDirectoryPath = FILEFactory.ENV_PREFIX; + String prefix = ProjectConstants.REPORTLETS_NAME; + FILE lastDirectory; + if (model instanceof FileDataPlaceListModel) { + FileDataFILE file = new FileDataFILE(new FileNode(), false, StringUtils.EMPTY, ((FileDataPlaceListModel) model).getType()); + lastDirectory = FILEFactory.createFolder(file, prefix + lastDirectoryPath); + } else { + lastDirectory = FILEFactory.createFolder(prefix + lastDirectoryPath); + } + dealCurrentDirectory(model, lastDirectory); + } + private void dealCurrentDirectory(AbstractPlaceListModel model, FILE lastDirectory) { model.setCD(lastDirectory); if (currentDirectory != null) { @@ -1109,6 +1131,7 @@ public class FILEChooserPane extends BasicPane { } } + private void setPlaceListModel() { if (placesList == null) { return; @@ -1140,7 +1163,7 @@ public class FILEChooserPane extends BasicPane { if (placesList == null) { return; } - setPlaceListModel(new FileDataPlaceListModel(type)); + setPlaceListModel4DataFile(new FileDataPlaceListModel(type)); } protected void setFileCAPlaceListModel() { diff --git a/designer-realize/src/main/java/com/fanruan/data/ConnectionConfigWrapper.java b/designer-realize/src/main/java/com/fanruan/data/ConnectionConfigWrapper.java index 8dd3ea86e5..68516dd7b8 100644 --- a/designer-realize/src/main/java/com/fanruan/data/ConnectionConfigWrapper.java +++ b/designer-realize/src/main/java/com/fanruan/data/ConnectionConfigWrapper.java @@ -3,6 +3,7 @@ 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.design.data.datapane.preview.ConnectionInfoBeanHelper; import com.fr.file.ConnectionConfig; import com.fr.log.FineLoggerFactory; import com.fr.transaction.Configurations; @@ -108,7 +109,7 @@ public class ConnectionConfigWrapper implements ConnectionConfigProvider, Connec @Override public @Nullable Connection getConnection(@NotNull String connectionName) { - Connection connection = WorkContext.getCurrent().isLocal() ? ConnectionConfig.getInstance().getConnection(connectionName) : ConnectionRepository.getInstance().getByName(connectionName).getConnection(); + Connection connection = WorkContext.getCurrent().isLocal() ? ConnectionConfig.getInstance().getConnection(connectionName) : ConnectionInfoBeanHelper.createConnection(ConnectionRepository.getInstance().getByName(connectionName));; if (connection != null) { connection.setConnectionName(connectionName); }