From 8d4fb7256fcfc88df9eeb3bf67eccef373f9f17a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Levy=2EXie-=E8=A7=A3=E5=AE=89=E6=A3=AE?= Date: Fri, 20 Sep 2024 17:00:17 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-133133=20&=20REPORT-134138=20fix:?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E8=BF=9E=E6=8E=A5=E5=BC=82=E5=B8=B8=E6=8A=A5?= =?UTF-8?q?=E9=94=99=E5=9C=BA=E6=99=AF=E5=BC=B9=E7=AA=97=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../datapane/connect/ConnectionListPane.java | 76 ++++++++++++++----- 1 file changed, 57 insertions(+), 19 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 ed96b2697e..9879fd700c 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 @@ -13,6 +13,8 @@ import com.fr.design.ExtraDesignClassManager; import com.fr.design.data.MapCompareUtils; import com.fr.design.data.datapane.preview.ConnectionInfoBeanHelper; import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.FineJOptionPane; +import com.fr.design.editlock.EditLockUtils; import com.fr.design.fun.ConnectionProvider; import com.fr.design.gui.controlpane.JListControlPane; import com.fr.design.gui.controlpane.NameObjectCreator; @@ -25,18 +27,21 @@ import com.fr.general.NameObject; import com.fr.license.database.DBTypes; import com.fr.license.database.DataBaseTypePointManager; import com.fr.license.exception.DataBaseNotSupportedException; +import com.fr.locale.InterProviderFactory; import com.fr.log.FineLoggerFactory; +import com.fr.report.LockItem; import com.fr.stable.ArrayUtils; import com.fr.stable.Nameable; import com.fr.stable.StringUtils; import com.fr.stable.core.PropertyChangeAdapter; import com.fr.workspace.WorkContext; +import com.fr.workspace.engine.exception.DriverUnExistException; import com.fr.workspace.server.database.DataBaseTypeOperator; import com.fr.workspace.server.entity.connection.ConnectionBean; import com.fr.workspace.server.repository.connection.ConnectionRepository; import org.jetbrains.annotations.NotNull; -import javax.swing.SwingWorker; +import javax.swing.*; import java.awt.Window; import java.util.ArrayList; import java.util.Arrays; @@ -345,18 +350,23 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh private void alterConnections(List addConnections, List removedConnNames, List updateConnection) throws Exception { - try { - for (ConnectionInfoBean bean : addConnections) { + // 处理新增 connections + processConnections(addConnections, bean -> { ConnectionRepository.getInstance().add(bean); - } - for (ConnectionInfoBean bean : updateConnection) { + }, "add"); + + // 处理更新 connections + processConnections(updateConnection, bean -> { ConnectionRepository.getInstance().update(bean); - } - for (String name : removedConnNames) { + }, "update"); + + // 处理移除 connections + processConnections(removedConnNames, name -> { ConnectionRepository.getInstance().delete(new ConnectionInfoBean(name)); - } - // hades:远程环境时,由于时直接RPC调用远程修改,因此设计器本地配置需要失效 + }, "delete"); + + // 远程环境处理逻辑 if (!WorkContext.getCurrent().isLocal()) { EventDispatcher.fire(RemoteConfigEvent.EDIT, "ConnectionConfig"); } @@ -366,18 +376,46 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh } } + private void processConnections(List connections, ThrowingConsumer action, String actionType) throws Exception { + for (T item : connections) { + try { + action.accept(item); + } catch (Exception e) { + String errorConnectionName = (item instanceof ConnectionInfoBean) + ? ((ConnectionInfoBean) item).getConnectionName() + : item.toString(); + if (e instanceof DriverUnExistException) { + throw new DriverUnExistException(InterProviderFactory.getProvider().getLocText("Fine-Core_Data_Connection") + errorConnectionName + + InterProviderFactory.getProvider().getLocText("Fine-Core_Driver_Not_Found")); + } + throw e; + } + } + } + + @FunctionalInterface + interface ThrowingConsumer { + void accept(T t) throws Exception; + } public static void showDialog(Window parent) { - final Map connectionMap = ConnectionInfoBeanHelper.createConnectionMap(ConnectionRepository.getInstance().getAll()); - final ConnectionManagerPane connectionManagerPane = new ConnectionManagerPane() { - @Override - public void complete() { - populate(connectionMap); - } - }; - final BasicDialog connectionListDialog = connectionManagerPane.showLargeWindow(parent, null); - connectionListDialog.addDialogActionListener(new ConnectionListDialogActionAdapter(connectionManagerPane, connectionListDialog, connectionMap)); - connectionListDialog.setVisible(true); + try { + final Map connectionMap = ConnectionInfoBeanHelper.createConnectionMap(ConnectionRepository.getInstance().getAll()); + final ConnectionManagerPane connectionManagerPane = new ConnectionManagerPane() { + @Override + public void complete() { + populate(connectionMap); + } + }; + final BasicDialog connectionListDialog = connectionManagerPane.showLargeWindow(parent, null); + connectionListDialog.addDialogActionListener(new ConnectionListDialogActionAdapter(connectionManagerPane, connectionListDialog, connectionMap)); + connectionListDialog.setVisible(true); + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + FineJOptionPane.showMessageDialog(null, Toolkit.i18nText("Fine-Design_Remote_Data_Error"), + Toolkit.i18nText("Fine-Design_Basic_Error"), JOptionPane.ERROR_MESSAGE); + EditLockUtils.unlock(LockItem.CONNECTION); + } } @Override