Browse Source

Merge pull request #9637 in DESIGN/design from release/11.0 to bugfix/11.0

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

18
designer-base/src/main/java/com/fr/design/DesignerEnvManager.java

@ -20,6 +20,7 @@ import com.fr.design.locale.impl.ProductImproveMark;
import com.fr.design.login.DesignerLoginType; import com.fr.design.login.DesignerLoginType;
import com.fr.design.login.config.DesignerLoginConfigManager; import com.fr.design.login.config.DesignerLoginConfigManager;
import com.fr.design.mainframe.ComponentReuseNotifyUtil; import com.fr.design.mainframe.ComponentReuseNotifyUtil;
import com.fr.design.mainframe.simple.SimpleDesignerConfig;
import com.fr.design.mainframe.reuse.ComponentReuseNotificationInfo; import com.fr.design.mainframe.reuse.ComponentReuseNotificationInfo;
import com.fr.design.mainframe.vcs.VcsConfigManager; import com.fr.design.mainframe.vcs.VcsConfigManager;
import com.fr.design.notification.SnapChatConfig; import com.fr.design.notification.SnapChatConfig;
@ -226,6 +227,8 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
private boolean propertiesUsable; private boolean propertiesUsable;
private SimpleDesignerConfig fvsDesignerConfig = SimpleDesignerConfig.getInstance("FvsDesignerConfig");
/** /**
* DesignerEnvManager. * DesignerEnvManager.
*/ */
@ -1012,6 +1015,10 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
this.designerStartupConfig.setEnabled(enabled); this.designerStartupConfig.setEnabled(enabled);
} }
public SimpleDesignerConfig getFvsDesignerConfig() {
return fvsDesignerConfig;
}
/** /**
* 返回环境名称迭代器 * 返回环境名称迭代器
*/ */
@ -1863,6 +1870,8 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
readSnapChatConfig(reader); readSnapChatConfig(reader);
} else if (name.equals(DesignerLoginConfigManager.XML_TAG)) { } else if (name.equals(DesignerLoginConfigManager.XML_TAG)) {
readDesignerLoginAttr(reader); readDesignerLoginAttr(reader);
} else if (name.equals(fvsDesignerConfig.getName())) {
readFvsDesignerConfig(reader);
} else { } else {
readLayout(reader, name); readLayout(reader, name);
} }
@ -2113,6 +2122,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
writeSnapChatConfig(writer); writeSnapChatConfig(writer);
writeComponentReuseNotificationInfo(writer); writeComponentReuseNotificationInfo(writer);
writeDesignerLoginAttr(writer); writeDesignerLoginAttr(writer);
writeFvsDesignerConfig(writer);
writer.end(); writer.end();
} }
@ -2419,6 +2429,14 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
this.designerLoginConfigManager.writeXML(writer); this.designerLoginConfigManager.writeXML(writer);
} }
private void readFvsDesignerConfig(XMLableReader reader) {
reader.readXMLObject(fvsDesignerConfig);
}
private void writeFvsDesignerConfig(XMLPrintWriter writer) {
this.fvsDesignerConfig.writeXML(writer);
}
enum XmlHandler { enum XmlHandler {
Self; Self;

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);
} }
/**
* 数据被修改(EntryEventKind.UPDATED) 的判定规则
* @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

@ -192,6 +192,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);

72
designer-base/src/main/java/com/fr/design/mainframe/simple/SimpleDesignerConfig.java

@ -0,0 +1,72 @@
package com.fr.design.mainframe.simple;
import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLable;
import com.fr.stable.xml.XMLableReader;
import java.util.HashMap;
import java.util.Map;
/**
* @author Wei
* 一个简单属性字符串存储类用于自定义简单属性的存储
* getInstance("FVSDesignerConfig")可在FineReportEnv.xml中定义一个<FVSDesignerConfig></>存储FVS相关配置
*/
public class SimpleDesignerConfig implements XMLable {
private static final HashMap<String, SimpleDesignerConfig> configs = new HashMap<>();
private SimpleDesignerConfig(String name) {
this.name = name;
}
public static SimpleDesignerConfig getInstance(String name) {
SimpleDesignerConfig config = configs.get(name);
if(config == null) {
config = new SimpleDesignerConfig(name);
configs.put(name, config);
}
return config;
}
private String name = "";
private HashMap<String, String> content = new HashMap<>();
public void addAttr(String key, String value) {
content.put(key, value);
}
public Map<String, String> getContent() {
return content;
}
@Override
public void readXML(XMLableReader reader) {
if (reader.isAttr()) {
content.putAll(reader.getAttrs());
}
}
@Override
public void writeXML(XMLPrintWriter writer) {
writer.startTAG(name);
content.forEach(writer::attr);
writer.end();
}
@Override
public Object clone() throws CloneNotSupportedException {
SimpleDesignerConfig cloned = (SimpleDesignerConfig) super.clone();
cloned.content = new HashMap<>(content);
return cloned;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Loading…
Cancel
Save