From e9e97d907a6bdb0d9dac8af085dae6cb04fc5e8d Mon Sep 17 00:00:00 2001 From: rinoux Date: Tue, 29 Mar 2022 16:24:01 +0800 Subject: [PATCH 1/4] =?UTF-8?q?REPORT-68607=20=E6=95=B0=E6=8D=AE=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=E9=85=8D=E7=BD=AE=E6=93=8D=E4=BD=9C=E6=94=BE=E4=BA=8B?= =?UTF-8?q?=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../datapane/connect/ConnectionListPane.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) 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 c0d23ed46..1913ee880 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 @@ -20,6 +20,8 @@ import com.fr.stable.ArrayUtils; import com.fr.stable.Nameable; import com.fr.stable.StringUtils; import com.fr.stable.core.PropertyChangeAdapter; +import com.fr.transaction.Configurations; +import com.fr.transaction.WorkerFacade; import javax.swing.SwingUtilities; import java.util.ArrayList; @@ -163,18 +165,29 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh Map updatedMap = new LinkedHashMap<>(); Arrays.stream(res).map(n -> (NameObject) n).forEach(no -> updatedMap.put(no.getName(), (Connection) no.getObject())); + List removedConnNames = new ArrayList<>(); + Map addedOrUpdatedConnections = new LinkedHashMap<>(); MapCompareUtils.contrastMapEntries(populatedConnectionsSnapshot, updatedMap, (entryEventKind, s, connection) -> { switch (entryEventKind) { case REMOVED: - connectionConfig.removeConnection(s); + removedConnNames.add(s); break; case ADDED: case UPDATED: - connectionConfig.addConnection(s, connection); + addedOrUpdatedConnections.put(s, connection); default: break; } }); + + // 之前丢有可能是因为没有放事务里吧 + Configurations.modify(new WorkerFacade(ConnectionConfig.class) { + @Override + public void run() { + removedConnNames.forEach(n -> ConnectionConfig.getInstance().removeConnection(n)); + addedOrUpdatedConnections.forEach((name, conn) -> ConnectionConfig.getInstance().addConnection(name, conn)); + } + }); } @Override From f8a3043edae0781255f3ecadce139eaa5ad46d90 Mon Sep 17 00:00:00 2001 From: rinoux Date: Thu, 12 May 2022 10:19:11 +0800 Subject: [PATCH 2/4] =?UTF-8?q?REPORT-69285=20=E6=95=B0=E6=8D=AE=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=E5=AE=89=E5=85=A8=E5=85=B3=E9=94=AE=E5=AD=97=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E6=8B=A6=E6=88=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../datapane/connect/ConnectionListPane.java | 34 +++++++++++++------ .../connect/ConnectionManagerPane.java | 7 ++-- .../datapane/connect/ConnectionShowPane.java | 2 +- 3 files changed, 28 insertions(+), 15 deletions(-) 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 1913ee880..0336c1ce0 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 @@ -1,5 +1,6 @@ package com.fr.design.data.datapane.connect; +import com.fr.data.core.db.JDBCSecurityChecker; import com.fr.data.impl.Connection; import com.fr.data.impl.JDBCDatabaseConnection; import com.fr.data.impl.JNDIDatabaseConnection; @@ -20,10 +21,9 @@ import com.fr.stable.ArrayUtils; import com.fr.stable.Nameable; import com.fr.stable.StringUtils; import com.fr.stable.core.PropertyChangeAdapter; -import com.fr.transaction.Configurations; -import com.fr.transaction.WorkerFacade; import javax.swing.SwingUtilities; +import java.sql.SQLException; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -159,7 +159,7 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh /** * Update. */ - public void update(ConnectionConfig connectionConfig) { + public void update(ConnectionConfig connectionConfig) throws Exception { // Nameable[]居然不能强转成NameObject[],一定要这么写... Nameable[] res = this.update(); Map updatedMap = new LinkedHashMap<>(); @@ -180,14 +180,28 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh } }); - // 之前丢有可能是因为没有放事务里吧 - Configurations.modify(new WorkerFacade(ConnectionConfig.class) { - @Override - public void run() { - removedConnNames.forEach(n -> ConnectionConfig.getInstance().removeConnection(n)); - addedOrUpdatedConnections.forEach((name, conn) -> ConnectionConfig.getInstance().addConnection(name, conn)); + this.checkSecurity(addedOrUpdatedConnections); + alterConnections(removedConnNames, addedOrUpdatedConnections); + } + + private void alterConnections(List removedConnNames, Map addedOrUpdatedConnections) { + removedConnNames.forEach(n -> ConnectionConfig.getInstance().removeConnection(n)); + addedOrUpdatedConnections.forEach((name, conn) -> ConnectionConfig.getInstance().addConnection(name, conn)); + } + + private void checkSecurity(Map addedOrUpdatedConnections) throws Exception { + + for (Map.Entry entry : addedOrUpdatedConnections.entrySet()) { + Connection connection = entry.getValue(); + if (connection instanceof JDBCDatabaseConnection) { + try { + JDBCSecurityChecker.checkURL(((JDBCDatabaseConnection) connection).getURL()); + JDBCSecurityChecker.checkValidationQuery(((JDBCDatabaseConnection) connection).getDbcpAttr().getValidationQuery()); + } catch (SQLException e) { + throw new SQLException(Toolkit.i18nText("Fine-Design_Basic_Database_Connection_Invalid_Config", entry.getKey()) + ", " + e.getMessage(), e.getCause()); + } } - }); + } } @Override diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionManagerPane.java b/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionManagerPane.java index 6c768145f..eadf456e0 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionManagerPane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionManagerPane.java @@ -4,9 +4,8 @@ import com.fr.design.gui.frpane.LoadingBasicPane; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.file.ConnectionConfig; - -import javax.swing.*; -import java.awt.*; +import javax.swing.JPanel; +import java.awt.BorderLayout; import java.util.HashMap; public class ConnectionManagerPane extends LoadingBasicPane implements ConnectionShowPane { @@ -39,7 +38,7 @@ public class ConnectionManagerPane extends LoadingBasicPane implements Connectio this.connectionListPane.populate(datasourceManager); } - public void update(ConnectionConfig datasourceManager) { + public void update(ConnectionConfig datasourceManager) throws Exception { this.connectionListPane.update(datasourceManager); } diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionShowPane.java b/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionShowPane.java index b5ae09be8..2b74ddcf9 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionShowPane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionShowPane.java @@ -7,7 +7,7 @@ import com.fr.file.ConnectionConfig; * 数据链接显示面板 */ public interface ConnectionShowPane { - void update(ConnectionConfig connectionConfig); + void update(ConnectionConfig connectionConfig) throws Exception; void populate(ConnectionConfig connectionConfig); From 06346c31cd43bbde5d575c71242e53f74fed0494 Mon Sep 17 00:00:00 2001 From: rinoux Date: Thu, 12 May 2022 11:09:28 +0800 Subject: [PATCH 3/4] =?UTF-8?q?REPORT-69285=20=E6=95=B0=E6=8D=AE=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=E5=AE=89=E5=85=A8=E5=85=B3=E9=94=AE=E5=AD=97=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E6=8B=A6=E6=88=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../design/os/impl/DatabaseDialogAction.java | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/os/impl/DatabaseDialogAction.java b/designer-base/src/main/java/com/fr/design/os/impl/DatabaseDialogAction.java index 057b561fa..669ef6ef4 100644 --- a/designer-base/src/main/java/com/fr/design/os/impl/DatabaseDialogAction.java +++ b/designer-base/src/main/java/com/fr/design/os/impl/DatabaseDialogAction.java @@ -3,19 +3,26 @@ package com.fr.design.os.impl; import com.fr.design.data.datapane.connect.ConnectionManagerPane; import com.fr.design.dialog.BasicDialog; import com.fr.design.dialog.DialogActionAdapter; +import com.fr.design.dialog.FineJOptionPane; import com.fr.design.editlock.EditLockUtils; +import com.fr.design.i18n.Toolkit; import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.DesignerFrame; import com.fr.file.ConnectionConfig; +import com.fr.report.LockItem; import com.fr.stable.os.support.OSBasedAction; import com.fr.transaction.CallBackAdaptor; import com.fr.transaction.Configurations; import com.fr.transaction.WorkerFacade; -import com.fr.report.LockItem; + +import javax.swing.JOptionPane; +import java.util.concurrent.atomic.AtomicBoolean; + import static com.fr.design.actions.server.ConnectionListAction.doWithDatasourceManager; /** * 数据连接窗口 + * * @author pengda * @date 2019/10/9 */ @@ -52,10 +59,17 @@ public class DatabaseDialogAction implements OSBasedAction { databaseListDialog.setDoOKSucceed(false); return; } + + AtomicBoolean saved = new AtomicBoolean(true); Configurations.modify(new WorkerFacade(ConnectionConfig.class) { @Override public void run() { - databaseManagerPane.update(datasourceManager); + try { + databaseManagerPane.update(datasourceManager); + } catch (Exception e) { + saved.set(false); + FineJOptionPane.showMessageDialog(databaseManagerPane, e.getMessage(), Toolkit.i18nText("Fine-Design_Basic_Error"), JOptionPane.ERROR_MESSAGE); + } } }.addCallBack(new CallBackAdaptor() { @Override @@ -66,9 +80,13 @@ public class DatabaseDialogAction implements OSBasedAction { @Override public void afterCommit() { - DesignerContext.getDesignerBean("databasename").refreshBeanElement(); - // 定义数据连接弹窗关闭后,解锁 - EditLockUtils.unlock(LockItem.CONNECTION); + if (saved.get()) { + DesignerContext.getDesignerBean("databasename").refreshBeanElement(); + // 定义数据连接弹窗关闭后,解锁 + EditLockUtils.unlock(LockItem.CONNECTION); + } else { + databaseListDialog.setDoOKSucceed(false); + } } })); } From 6a9c978a391e10b76d87cd5953e285ce2ed502c5 Mon Sep 17 00:00:00 2001 From: rinoux Date: Thu, 12 May 2022 11:09:34 +0800 Subject: [PATCH 4/4] =?UTF-8?q?REPORT-69285=20=E6=95=B0=E6=8D=AE=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=E5=AE=89=E5=85=A8=E5=85=B3=E9=94=AE=E5=AD=97=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E6=8B=A6=E6=88=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../connect/ConnectionComboBoxPanel.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) 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 5ee6654d4..c0e8ef023 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 @@ -8,10 +8,12 @@ import com.fr.design.DesignerEnvManager; import com.fr.design.actions.server.ConnectionListAction; import com.fr.design.dialog.BasicDialog; import com.fr.design.dialog.DialogActionAdapter; +import com.fr.design.dialog.FineJOptionPane; import com.fr.design.editlock.ConnectionLockChangeChecker; import com.fr.design.editlock.EditLockUtils; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ibutton.UILockButton; +import com.fr.design.i18n.Toolkit; import com.fr.design.mainframe.DesignerContext; import com.fr.file.ConnectionConfig; import com.fr.report.LockItem; @@ -22,6 +24,7 @@ import com.fr.transaction.WorkerFacade; import com.fr.workspace.WorkContext; import com.fr.workspace.server.connection.DBConnectAuth; +import javax.swing.JOptionPane; import javax.swing.SwingUtilities; import java.awt.Dimension; import java.awt.event.ActionEvent; @@ -32,6 +35,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; /** * 选择数据连接的下拉框 @@ -145,10 +149,16 @@ public class ConnectionComboBoxPanel extends ItemEditableComboBoxPanel { connectionListDialog.setDoOKSucceed(false); return; } + AtomicBoolean saved = new AtomicBoolean(true); Configurations.modify(new WorkerFacade(ConnectionConfig.class) { @Override public void run() { - connectionListPane.update(connectionConfig); + try { + connectionListPane.update(connectionConfig); + } catch (Exception e) { + saved.set(false); + FineJOptionPane.showMessageDialog(connectionListPane, e.getMessage(), Toolkit.i18nText("Fine-Design_Basic_Error"), JOptionPane.ERROR_MESSAGE); + } } }.addCallBack(new CallBackAdaptor() { @Override @@ -159,9 +169,13 @@ public class ConnectionComboBoxPanel extends ItemEditableComboBoxPanel { @Override public void afterCommit() { - DesignerContext.getDesignerBean("databasename").refreshBeanElement(); - // 关闭定义数据连接页面,为其解锁 - EditLockUtils.unlock(LockItem.CONNECTION); + if (saved.get()) { + DesignerContext.getDesignerBean("databasename").refreshBeanElement(); + // 定义数据连接弹窗关闭后,解锁 + EditLockUtils.unlock(LockItem.CONNECTION); + } else { + connectionListDialog.setDoOKSucceed(false); + } } }));