From a919ce7c27804b3ca96bcc6d37424d5df5cc89cd Mon Sep 17 00:00:00 2001 From: Yvan Date: Mon, 1 Aug 2022 18:42:42 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-77217=20ConnectionProvider-=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E4=B9=8B=E5=90=8E=E6=95=B0=E6=8D=AE=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E6=97=A0=E6=B3=95=E4=BF=9D=E5=AD=98=20?= =?UTF-8?q?=E5=90=8C=E6=AD=A510.0=20=E3=80=90=E9=97=AE=E9=A2=98=E5=8E=9F?= =?UTF-8?q?=E5=9B=A0=E3=80=91=E4=BA=A7=E7=94=9F=E5=81=87=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E7=9A=84=E5=8E=9F=E5=9B=A0=E6=98=AF=EF=BC=8C=E5=9C=A8=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E7=9A=84=E6=97=B6=E5=80=99=E4=BC=9A=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E7=8E=B0=E6=9C=89=E7=9A=84Connection=E4=B8=8E=E4=BB=A5?= =?UTF-8?q?=E5=89=8D=E5=AD=98=E5=82=A8=E7=9A=84Connection=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E6=9C=89=E4=B8=8D=E5=90=8C=EF=BC=8C=E5=A6=82=E6=9E=9C?= =?UTF-8?q?=E4=B8=8D=E5=90=8C=E5=B0=B1=E4=BB=A3=E8=A1=A8=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E3=80=82=E5=AE=9E=E9=99=85=E4=B8=8A=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E4=B8=AD=E7=9A=84Connection=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E7=B1=BB=E6=B2=A1=E6=9C=89=E5=86=99equals=E6=96=B9=E6=B3=95?= =?UTF-8?q?=EF=BC=8C=E7=84=B6=E5=90=8E=E6=96=B0=E6=97=A7Connection?= =?UTF-8?q?=E8=A2=AB=E8=AE=A4=E4=B8=BA=E6=98=AF=E7=9B=B8=E5=90=8C=E4=BA=86?= =?UTF-8?q?=EF=BC=8C=E5=B0=B1=E6=B2=A1=E6=9C=89=E8=B5=B0=E5=90=8E=E9=9D=A2?= =?UTF-8?q?=E7=9A=84=E6=9B=B4=E6=96=B0=E9=85=8D=E7=BD=AE=E7=9A=84=E9=80=BB?= =?UTF-8?q?=E8=BE=91=20=E3=80=90=E6=94=B9=E5=8A=A8=E6=96=B9=E6=A1=88?= =?UTF-8?q?=E3=80=91=E6=8B=89rinoux=E3=80=81vito=E3=80=81hugh=E4=B8=80?= =?UTF-8?q?=E8=B5=B7=E6=B2=9F=E9=80=9A=E4=BA=86=E4=B8=8B=E6=96=B9=E6=A1=88?= =?UTF-8?q?=EF=BC=8C=E6=9A=82=E6=97=B6=E4=B8=BB=E4=BB=A3=E7=A0=81=E9=87=8C?= =?UTF-8?q?=E5=81=9A=E4=B8=AA=E5=85=BC=E5=AE=B9=EF=BC=8C=E8=AE=A9=E4=B8=BB?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=86=85=E7=BD=AE=E7=9A=84=E4=B8=A4=E7=A7=8D?= =?UTF-8?q?Connection=E5=8E=BB=E5=88=A4=E6=96=AD=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E8=A6=81=E6=9B=B4=E6=96=B0=EF=BC=8C=E5=85=B6=E4=BD=99=E7=9A=84?= =?UTF-8?q?Connection=EF=BC=88=E6=8F=92=E4=BB=B6Connection=EF=BC=89?= =?UTF-8?q?=E9=83=BD=E5=BF=85=E9=A1=BB=E6=9B=B4=E6=96=B0=20=E3=80=90review?= =?UTF-8?q?=E5=BB=BA=E8=AE=AE=E3=80=91=E5=90=8C=E6=AD=A510.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/data/MapCompareUtils.java | 42 ++++++++++++++++++- .../datapane/connect/ConnectionListPane.java | 26 ++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/designer-base/src/main/java/com/fr/design/data/MapCompareUtils.java b/designer-base/src/main/java/com/fr/design/data/MapCompareUtils.java index f7492aefcc..57fba61780 100644 --- a/designer-base/src/main/java/com/fr/design/data/MapCompareUtils.java +++ b/designer-base/src/main/java/com/fr/design/data/MapCompareUtils.java @@ -16,6 +16,8 @@ public final class MapCompareUtils { /** * 对比两个map 查找出相比orig,other中有哪些是新增的、删除的或者被修改的,并分别进行处理 * + * 对比时默认用equals方法来判断是否为 EntryEventKind#UPDATED + * * @param orig 原始map * @param other 参考的新map * @param eventHandler 有区别时的事件处理器 @@ -24,12 +26,29 @@ public final class MapCompareUtils { */ public static void contrastMapEntries(@NotNull Map orig, @NotNull Map other, @NotNull EventHandler eventHandler) { + contrastMapEntries(orig, other, eventHandler, UpdateRule.DEFAULT); + } + + /** + * 对比两个map 查找出相比orig,other中有哪些是新增的、删除的或者被修改的,并分别进行处理 + * + * 对比时用自定义的规则来判断是否为 EntryEventKind#UPDATED + * + * @param orig 原始map + * @param other 参考的新map + * @param eventHandler 有区别时的事件处理器 + * @param updateRule 自定义的Update事件判定规则 + * @param + * @param + */ + public static void contrastMapEntries(@NotNull Map orig, @NotNull Map other, @NotNull EventHandler eventHandler, @NotNull UpdateRule updateRule) { + Map copiedOrig = new LinkedHashMap<>(orig); other.forEach((k, v) -> { V existedV = copiedOrig.remove(k); if (existedV != null) { - if (!v.equals(existedV)) { + if (updateRule.needUpdate(existedV, v)) { eventHandler.on(EntryEventKind.UPDATED, k, v); } } else { @@ -41,10 +60,31 @@ public final class MapCompareUtils { } + /** + * 事件处理器,对应比较后的三种结果的事件处理 + * @param + * @param + */ public interface EventHandler { void on(EntryEventKind entryEventKind, K k, V v); } + /** + * 判定 数据被修改 的判定规则 + * @param + * @param + */ + public interface UpdateRule { + + EntryEventKind eventKind = EntryEventKind.UPDATED; + + UpdateRule DEFAULT = new UpdateRule() {}; + + default boolean needUpdate(V origin, V v) { + return !v.equals(origin); + } + } + public enum EntryEventKind { ADDED, REMOVED, 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 9d18031b09..63a4a47cbf 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 @@ -178,6 +178,32 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh default: break; } + }, new MapCompareUtils.UpdateRule() { + @Override + public boolean needUpdate(Connection origin, Connection connection) { + return needUpdate0(origin, connection); + } + + /** + * 是否需要更新处理 + * 1. Connection本身equals为false,代表字段修改 + * 2. 非内置的Connection,即插件提供的Connection + * todo 原本一个equals方法就可以搞定,但是插件里面没有实现equals,结果导致不能正确判断,只能主代码里做兼容,很恶心,先记个todo,以后看有没有办法改掉 + * @param origin + * @param connection + * @return + */ + private boolean needUpdate0(Connection origin, Connection connection) { + return !connection.equals(origin) || !isEmbedConnection(connection); + } + + /** + * 是否是主工程里内置的Connection + * @return + */ + private boolean isEmbedConnection(Connection connection) { + return connection instanceof JDBCDatabaseConnection || connection instanceof JNDIDatabaseConnection; + } }); this.validateConnections(addedOrUpdatedConnections);