P15GEN2\59518
2024-05-29 d4210c7c4b04abde20037ea8aa0f54ef8a2649aa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package foundation.data.meta.template;
 
import foundation.data.meta.MetaMonitor;
import foundation.data.meta.field.FieldsRuntime;
import foundation.persist.source.NamedDataSource;
import foundation.util.MapList;
 
public class PropertyTemplateBucket {
    
    private static PropertyTemplateBucket instance;
    private MapList<String, PropertyTemplate> templates;
    private Indexes defaultIndexes;    
    private Indexes sceneIndexes;
    private Indexes capacityIndexes;
    private Indexes userIndexes;
    private MetaMonitor indexMonitor;
    private MetaMonitor templateAndIndexMonitor;
    
    
    private PropertyTemplateBucket() {
        try {
            templates = new MapList<String, PropertyTemplate>();
            
            defaultIndexes = new Indexes();
            sceneIndexes = new Indexes();
            capacityIndexes = new Indexes();
            userIndexes = new Indexes();
            
            NamedDataSource datasource = NamedDataSource.getInstance();
            indexMonitor = new MetaMonitor(datasource, "getPropertyIndexLastUpdateTime");
            templateAndIndexMonitor = new MetaMonitor(datasource, "getTemplateAndIndexLastUpdateTime");
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    public static synchronized PropertyTemplateBucket getInstance() {
        if (instance == null) {
            instance = new PropertyTemplateBucket();
        }
        
        return instance;
    }
 
    public void loadTemplateAndIndex() throws Exception {
        //1. 加载Field和Property模板
        TemplateLoader.reloadTemplate(this);
        
        //2.加载Property Index 设置
        TemplateLoader.reloadIndex(this);        
    }
    
    public void reloadIndex() throws Exception {
        TemplateLoader.reloadIndex(this);
    }
 
    public void build(FieldsRuntime fields) {
        defaultIndexes.build(fields);
        sceneIndexes.build(fields);
        capacityIndexes.build(fields);
        userIndexes.build(fields);
    }
    
    public void loadOneIndex(String fieldName, boolean list, boolean form, boolean exportable, boolean importable, boolean scene, boolean capacity, boolean user) {
        defaultIndexes.loadOne(fieldName, list, form, exportable, importable);
        
        if (scene) {
            sceneIndexes.loadOne(fieldName, list, form, exportable, importable);
        }
        
        if (capacity) {
            capacityIndexes.loadOne(fieldName, list, form, exportable, importable);
        }
        
        if (user) {
            userIndexes.loadOne(fieldName, list, form, exportable, importable);
        }
    }
 
    public Indexes getDefaultIndexes() {
        return defaultIndexes;
    }
    
    public Indexes getSceneIndexes() {
        return sceneIndexes;
    }
 
    public Indexes getCapacityIndexes() {
        return capacityIndexes;
    }
    
    public Indexes getUserIndexes() {
        return userIndexes;
    }
    
    public PropertyTemplate getOneTemplate(String fieldName) {
        return templates.get(fieldName);
    }
 
    public void setTemplateItems(MapList<String, PropertyTemplate> templates) {
        this.templates = templates;
    }
 
    public void clearIndex() {
        defaultIndexes.clear();
        sceneIndexes.clear();
        capacityIndexes.clear();
        userIndexes.clear();
    }
 
    public MetaMonitor getIndexMonitor() {
        return indexMonitor;
    }
    
    public MetaMonitor getTemplateAndIndexMonitor() {
        return templateAndIndexMonitor;
    }
}