diff --git a/designer-base/src/main/java/com/fr/design/cache/DesignCacheManager.java b/designer-base/src/main/java/com/fr/design/cache/DesignCacheManager.java new file mode 100644 index 0000000000..80b8c56aab --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/cache/DesignCacheManager.java @@ -0,0 +1,56 @@ +package com.fr.design.cache; + +import com.fr.base.TableData; +import com.fr.design.data.tabledata.wrapper.TableDataFactory; + +import java.util.Map; + +/** + * 设计器缓存管理 + * + * @author Destiny.Lin + * @since 11.0 + * Created on 2024/8/11 + */ +public class DesignCacheManager { + + public static ThreadLocal> cacheTableData = new ThreadLocal<>(); + + /** + * 处理任务(使用数据集缓存) + */ + public static void processByCacheTableData(Task task) { + try { + cacheTableData.set(TableDataFactory.getTableDatas()); + task.process(); + } finally { + cacheTableData.remove(); + } + } + + + /** + * 是否使用数据集的缓存 + */ + public static boolean useDataCache() { + return cacheTableData.get() != null; + } + + public static ThreadLocal> getCacheTableData() { + return cacheTableData; + } + + public static void setCacheTableData(ThreadLocal> cacheTableData) { + DesignCacheManager.cacheTableData = cacheTableData; + } + + /** + * 任务 + */ + public interface Task { + /** + * 处理 + */ + void process(); + } +} diff --git a/designer-base/src/main/java/com/fr/design/data/DesignTableDataManager.java b/designer-base/src/main/java/com/fr/design/data/DesignTableDataManager.java index 1727edf26e..46e0c4de84 100644 --- a/designer-base/src/main/java/com/fr/design/data/DesignTableDataManager.java +++ b/designer-base/src/main/java/com/fr/design/data/DesignTableDataManager.java @@ -17,6 +17,7 @@ import com.fr.data.impl.storeproc.StoreProcedureConstants; import com.fr.data.impl.storeproc.StoreProcedureHelper; import com.fr.data.operator.DataOperator; import com.fr.design.DesignModelAdapter; +import com.fr.design.cache.DesignCacheManager; import com.fr.design.data.datapane.preview.PreviewTablePane; import com.fr.design.data.tabledata.wrapper.MultiResultTableDataNameWrapper; import com.fr.design.data.tabledata.wrapper.MultiResultTableDataWrapper; @@ -446,7 +447,13 @@ public abstract class DesignTableDataManager { } private static void addServerData(java.util.Map resMap) { - Map tableDataMap = TableDataFactory.getTableDatas(); + Map tableDataMap; + if (DesignCacheManager.useDataCache()) { + FineLoggerFactory.getLogger().debug("use cache Table data wrapper."); + tableDataMap = DesignCacheManager.getCacheTableData().get(); + } else { + tableDataMap = TableDataFactory.getTableDatas(); + } for (Entry entry : tableDataMap.entrySet()) { if (globalDsCache.containsKey(entry.getKey())) { resMap.put(entry.getKey(), globalDsCache.get(entry.getKey())); diff --git a/designer-base/src/main/java/com/fr/design/file/MultiTemplateTabPane.java b/designer-base/src/main/java/com/fr/design/file/MultiTemplateTabPane.java index 8f2783a3ca..1a1ab51b2f 100644 --- a/designer-base/src/main/java/com/fr/design/file/MultiTemplateTabPane.java +++ b/designer-base/src/main/java/com/fr/design/file/MultiTemplateTabPane.java @@ -6,6 +6,7 @@ import com.fr.base.svg.IconUtils; import com.fr.base.vcs.DesignerMode; import com.fr.design.actions.UpdateAction; import com.fr.design.actions.file.LocateAction; +import com.fr.design.cache.DesignCacheManager; import com.fr.design.constants.UIConstants; import com.fr.design.dialog.FineJOptionPane; import com.fr.design.gui.imenu.UIMenuItem; @@ -1296,7 +1297,7 @@ public class MultiTemplateTabPane extends JComponent { //没有点击关闭和ListDown按钮,则切换到点击的模板处 closeIconIndex = -1; clodeMode = CLOSE; - switchJTemplate(getTemplateIndex(evtX)); + DesignCacheManager.processByCacheTableData(() -> switchJTemplate(getTemplateIndex(evtX))); isShowList = false; } MultiTemplateTabPane.this.repaint(); diff --git a/designer-base/src/main/java/com/fr/design/file/TemplateTreePane.java b/designer-base/src/main/java/com/fr/design/file/TemplateTreePane.java index b91ac522d0..db63112647 100644 --- a/designer-base/src/main/java/com/fr/design/file/TemplateTreePane.java +++ b/designer-base/src/main/java/com/fr/design/file/TemplateTreePane.java @@ -5,6 +5,7 @@ package com.fr.design.file; import com.fr.base.FRContext; import com.fr.design.ExtraDesignClassManager; +import com.fr.design.cache.DesignCacheManager; import com.fr.design.dialog.FineJOptionPane; import com.fr.design.fun.TemplateTreeDefineProcessor; import com.fr.design.gui.itree.filetree.TemplateFileTree; @@ -112,7 +113,7 @@ public class TemplateTreePane extends JPanel implements FileOperations { @Override public void mousePressed(MouseEvent evt) { if (reportletsTree.getPathForLocation(evt.getX(), evt.getY()) != null && evt.getClickCount() == 2) { - openFile(); + DesignCacheManager.processByCacheTableData(() -> openFile()); } }