Browse Source

Pull request #9628: REPORT-77217 ConnectionProvider-修改之后数据连接信息无法保存 同步10.0

Merge in DESIGN/design from ~YVAN/design:final/10.0 to final/10.0

* commit 'a919ce7c27804b3ca96bcc6d37424d5df5cc89cd':
  REPORT-77217 ConnectionProvider-修改之后数据连接信息无法保存 同步10.0 【问题原因】产生假保存的原因是,在保存的时候会判断现有的Connection与以前存储的Connection是否有不同,如果不同就代表需要更新。实际上插件中的Connection相关类没有写equals方法,然后新旧Connection被认为是相同了,就没有走后面的更新配置的逻辑 【改动方案】拉rinoux、vito、hugh一起沟通了下方案,暂时主代码里做个兼容,让主代码内置的两种Connection去判断是否要更新,其余的Connection(插件Connection)都必须更新 【review建议】同步10.0
Yvan 2 years ago
parent
commit
45067de975
  1. 42
      designer-base/src/main/java/com/fr/design/data/MapCompareUtils.java
  2. 26
      designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionListPane.java

42
designer-base/src/main/java/com/fr/design/data/MapCompareUtils.java

@ -16,6 +16,8 @@ public final class MapCompareUtils {
/** /**
* 对比两个map 查找出相比origother中有哪些是新增的删除的或者被修改的并分别进行处理 * 对比两个map 查找出相比origother中有哪些是新增的删除的或者被修改的并分别进行处理
* *
* 对比时默认用equals方法来判断是否为 EntryEventKind#UPDATED
*
* @param orig 原始map * @param orig 原始map
* @param other 参考的新map * @param other 参考的新map
* @param eventHandler 有区别时的事件处理器 * @param eventHandler 有区别时的事件处理器
@ -24,12 +26,29 @@ public final class MapCompareUtils {
*/ */
public static <K, V> void contrastMapEntries(@NotNull Map<K, V> orig, @NotNull Map<K, V> other, @NotNull EventHandler<K, V> eventHandler) { public static <K, V> void contrastMapEntries(@NotNull Map<K, V> orig, @NotNull Map<K, V> other, @NotNull EventHandler<K, V> eventHandler) {
contrastMapEntries(orig, other, eventHandler, UpdateRule.DEFAULT);
}
/**
* 对比两个map 查找出相比origother中有哪些是新增的删除的或者被修改的并分别进行处理
*
* 对比时用自定义的规则来判断是否为 EntryEventKind#UPDATED
*
* @param orig 原始map
* @param other 参考的新map
* @param eventHandler 有区别时的事件处理器
* @param updateRule 自定义的Update事件判定规则
* @param <K>
* @param <V>
*/
public static <K, V> void contrastMapEntries(@NotNull Map<K, V> orig, @NotNull Map<K, V> other, @NotNull EventHandler<K, V> eventHandler, @NotNull UpdateRule<K, V> updateRule) {
Map<K, V> copiedOrig = new LinkedHashMap<>(orig); Map<K, V> copiedOrig = new LinkedHashMap<>(orig);
other.forEach((k, v) -> { other.forEach((k, v) -> {
V existedV = copiedOrig.remove(k); V existedV = copiedOrig.remove(k);
if (existedV != null) { if (existedV != null) {
if (!v.equals(existedV)) { if (updateRule.needUpdate(existedV, v)) {
eventHandler.on(EntryEventKind.UPDATED, k, v); eventHandler.on(EntryEventKind.UPDATED, k, v);
} }
} else { } else {
@ -41,10 +60,31 @@ public final class MapCompareUtils {
} }
/**
* 事件处理器对应比较后的三种结果的事件处理
* @param <K>
* @param <V>
*/
public interface EventHandler<K, V> { public interface EventHandler<K, V> {
void on(EntryEventKind entryEventKind, K k, V v); void on(EntryEventKind entryEventKind, K k, V v);
} }
/**
* 判定 数据被修改 的判定规则
* @param <K>
* @param <V>
*/
public interface UpdateRule<K, V> {
EntryEventKind eventKind = EntryEventKind.UPDATED;
UpdateRule DEFAULT = new UpdateRule() {};
default boolean needUpdate(V origin, V v) {
return !v.equals(origin);
}
}
public enum EntryEventKind { public enum EntryEventKind {
ADDED, ADDED,
REMOVED, REMOVED,

26
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: default:
break; break;
} }
}, new MapCompareUtils.UpdateRule<String, Connection>() {
@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); this.validateConnections(addedOrUpdatedConnections);

Loading…
Cancel
Save