Revision c7d830cc
Added by Cherian Mathew about 9 years ago
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/cache/CdmModelCacher.java | ||
---|---|---|
3 | 3 |
import java.lang.reflect.Field; |
4 | 4 |
import java.lang.reflect.Method; |
5 | 5 |
import java.util.ArrayList; |
6 |
import java.util.Arrays; |
|
7 | 6 |
import java.util.Iterator; |
8 | 7 |
import java.util.List; |
9 | 8 |
|
... | ... | |
22 | 21 |
|
23 | 22 |
private static final Logger logger = Logger.getLogger(CdmModelCacher.class); |
24 | 23 |
|
25 |
private List<CdmModelFieldPropertyFromClass> cmgmfcList = new ArrayList<CdmModelFieldPropertyFromClass>(); |
|
24 |
private final List<CdmModelFieldPropertyFromClass> cmgmfcList = new ArrayList<CdmModelFieldPropertyFromClass>();
|
|
26 | 25 |
|
27 | 26 |
public void cacheGetters() { |
28 | 27 |
|
29 | 28 |
Configuration configuration = new Configuration().configure("/eu/etaxonomy/cdm/mappings/hibernate.cfg.xml"); |
30 | 29 |
configuration.buildMappings(); |
31 |
Iterator<PersistentClass> classMappingIterator = configuration.getClassMappings();
|
|
30 |
Iterator<PersistentClass> classMappingIterator = configuration.getClassMappings(); |
|
32 | 31 |
|
33 | 32 |
Cache cache = CdmRemoteCacheManager.getInstance().getCdmModelGetMethodsCache(); |
34 | 33 |
cache.removeAll(); |
... | ... | |
39 | 38 |
String mappedClassName = mappedClass.getName(); |
40 | 39 |
|
41 | 40 |
CdmModelFieldPropertyFromClass cmgmfc = new CdmModelFieldPropertyFromClass(mappedClassName); |
42 |
Iterator propertyIt = persistentClass.getPropertyIterator();
|
|
41 |
Iterator propertyIt = persistentClass.getPropertyIterator(); |
|
43 | 42 |
|
44 | 43 |
logger.info("Adding class : " + mappedClassName + " to cache"); |
45 |
|
|
44 |
|
|
46 | 45 |
while(propertyIt.hasNext()) |
47 | 46 |
{ |
48 | 47 |
Property property = (Property)propertyIt.next(); |
49 |
Getter getter = property.getGetter(mappedClass);
|
|
50 |
if(getter != null && getter.getMember() != null) {
|
|
48 |
Getter getter = property.getGetter(mappedClass); |
|
49 |
if(getter != null && getter.getMember() != null) { |
|
51 | 50 |
Field field = (Field)getter.getMember(); |
52 |
String getMethod = getMethodNameFromFieldName(field.getName(), field.getType().getName());
|
|
51 |
String getMethod = getMethodNameFromFieldName(field.getName(), field.getType().getName()); |
|
53 | 52 |
logger.info(" - getMethod : " + getMethod + " for type " + field.getType().getName()); |
54 | 53 |
cmgmfc.addGetMethods(getMethod); |
55 | 54 |
} |
... | ... | |
59 | 58 |
} |
60 | 59 |
cache.flush(); |
61 | 60 |
} |
62 |
|
|
61 |
|
|
63 | 62 |
public void cacheGetterFields() { |
64 | 63 |
|
65 | 64 |
Configuration configuration = new Configuration().configure("/eu/etaxonomy/cdm/mappings/hibernate.cfg.xml"); |
66 | 65 |
configuration.buildMappings(); |
67 |
Iterator<PersistentClass> classMappingIterator = configuration.getClassMappings();
|
|
66 |
Iterator<PersistentClass> classMappingIterator = configuration.getClassMappings(); |
|
68 | 67 |
|
69 | 68 |
Cache cache = CdmRemoteCacheManager.getInstance().getCdmModelGetMethodsCache(); |
70 | 69 |
cache.removeAll(); |
... | ... | |
75 | 74 |
String mappedClassName = mappedClass.getName(); |
76 | 75 |
|
77 | 76 |
CdmModelFieldPropertyFromClass cmgmfc = new CdmModelFieldPropertyFromClass(mappedClassName); |
78 |
Iterator propertyIt = persistentClass.getPropertyIterator(); |
|
79 |
|
|
77 |
addGetters(persistentClass, cmgmfc); |
|
80 | 78 |
logger.info("Adding class : " + mappedClassName + " to cache"); |
81 |
|
|
82 |
while(propertyIt.hasNext()) |
|
83 |
{ |
|
84 |
Property property = (Property)propertyIt.next(); |
|
85 |
Getter getter = property.getGetter(mappedClass); |
|
86 |
if(getter != null && getter.getMember() != null) { |
|
87 |
Field field = (Field)getter.getMember(); |
|
88 |
//String getMethod = getMethodNameFromFieldName(field.getName(), field.getType().getName()); |
|
89 |
logger.info(" - contains field '" + field.getName() + "' of type '" + field.getType().getName() + "'"); |
|
90 |
cmgmfc.addGetMethods(field.getName()); |
|
91 |
} |
|
92 |
} |
|
79 |
|
|
93 | 80 |
cache.put(new Element(mappedClassName, cmgmfc)); |
94 | 81 |
|
95 | 82 |
} |
96 | 83 |
cache.flush(); |
97 | 84 |
} |
98 |
|
|
85 |
|
|
86 |
private void addGetters(PersistentClass persistentClass, CdmModelFieldPropertyFromClass cmgmfc) { |
|
87 |
if (persistentClass != null) { |
|
88 |
Iterator propertyIt = persistentClass.getPropertyIterator(); |
|
89 |
|
|
90 |
while(propertyIt.hasNext()) |
|
91 |
{ |
|
92 |
Property property = (Property)propertyIt.next(); |
|
93 |
Getter getter = property.getGetter(persistentClass.getMappedClass()); |
|
94 |
if(getter != null && getter.getMember() != null) { |
|
95 |
Field field = (Field)getter.getMember(); |
|
96 |
//String getMethod = getMethodNameFromFieldName(field.getName(), field.getType().getName()); |
|
97 |
logger.info(" - contains field '" + field.getName() + "' of type '" + field.getType().getName() + "'"); |
|
98 |
cmgmfc.addGetMethods(field.getName()); |
|
99 |
} |
|
100 |
} |
|
101 |
addGetters(persistentClass.getSuperclass(), cmgmfc); |
|
102 |
} |
|
103 |
} |
|
104 |
|
|
99 | 105 |
public void checkGetterMethods() { |
100 | 106 |
|
101 | 107 |
Configuration configuration = new Configuration().configure("/eu/etaxonomy/cdm/mappings/hibernate.cfg.xml"); |
102 | 108 |
configuration.buildMappings(); |
103 |
Iterator<PersistentClass> classMappingIterator = configuration.getClassMappings();
|
|
109 |
Iterator<PersistentClass> classMappingIterator = configuration.getClassMappings(); |
|
104 | 110 |
|
105 | 111 |
Cache cache = CdmRemoteCacheManager.getInstance().getCdmModelGetMethodsCache(); |
106 | 112 |
cache.removeAll(); |
... | ... | |
109 | 115 |
PersistentClass persistentClass = classMappingIterator.next(); |
110 | 116 |
Class mappedClass = persistentClass.getMappedClass(); |
111 | 117 |
String mappedClassName = mappedClass.getName(); |
112 |
|
|
113 |
Iterator propertyIt = persistentClass.getPropertyIterator();
|
|
114 |
|
|
118 |
|
|
119 |
Iterator propertyIt = persistentClass.getPropertyIterator(); |
|
120 |
|
|
115 | 121 |
Method[] methods = mappedClass.getMethods(); |
116 | 122 |
|
117 | 123 |
while(propertyIt.hasNext()) |
118 | 124 |
{ |
119 | 125 |
Property property = (Property)propertyIt.next(); |
120 |
Getter getter = property.getGetter(mappedClass);
|
|
121 |
if(getter != null && getter.getMember() != null) {
|
|
126 |
Getter getter = property.getGetter(mappedClass); |
|
127 |
if(getter != null && getter.getMember() != null) { |
|
122 | 128 |
Field field = (Field)getter.getMember(); |
123 |
String getMethod = getMethodNameFromFieldName(field.getName(), field.getType().getName());
|
|
124 |
|
|
129 |
String getMethod = getMethodNameFromFieldName(field.getName(), field.getType().getName()); |
|
130 |
|
|
125 | 131 |
boolean foundMethod = false; |
126 | 132 |
for(Method method : methods) { |
127 | 133 |
if(method.getName().equals(getMethod)) { |
... | ... | |
135 | 141 |
} |
136 | 142 |
} |
137 | 143 |
} |
138 |
|
|
144 |
|
|
139 | 145 |
|
140 | 146 |
} |
141 |
|
|
147 |
|
|
142 | 148 |
} |
143 | 149 |
|
144 | 150 |
public List<CdmModelFieldPropertyFromClass> getCdmModelGetMethodFromClassList() { |
145 | 151 |
cmgmfcList.clear(); |
146 | 152 |
Configuration configuration = new Configuration().configure("/eu/etaxonomy/cdm/mappings/hibernate.cfg.xml"); |
147 | 153 |
configuration.buildMappings(); |
148 |
Iterator<PersistentClass> classMappingIterator = configuration.getClassMappings();
|
|
154 |
Iterator<PersistentClass> classMappingIterator = configuration.getClassMappings(); |
|
149 | 155 |
|
150 | 156 |
while(classMappingIterator.hasNext()) { |
151 | 157 |
PersistentClass persistentClass = classMappingIterator.next(); |
... | ... | |
153 | 159 |
String mappedClassName = mappedClass.getName(); |
154 | 160 |
|
155 | 161 |
CdmModelFieldPropertyFromClass cmgmfc = new CdmModelFieldPropertyFromClass(mappedClassName); |
156 |
Iterator propertyIt = persistentClass.getPropertyIterator();
|
|
162 |
Iterator propertyIt = persistentClass.getPropertyIterator(); |
|
157 | 163 |
|
158 | 164 |
while(propertyIt.hasNext()) |
159 | 165 |
{ |
160 | 166 |
Property property = (Property)propertyIt.next(); |
161 |
Getter getter = property.getGetter(mappedClass);
|
|
162 |
if(getter != null && getter.getMember() != null) {
|
|
167 |
Getter getter = property.getGetter(mappedClass); |
|
168 |
if(getter != null && getter.getMember() != null) { |
|
163 | 169 |
Field field = (Field)getter.getMember(); |
164 |
String getMethod = getMethodNameFromFieldName(getter.getMember().getName(),field.getType().getName());
|
|
170 |
String getMethod = getMethodNameFromFieldName(getter.getMember().getName(),field.getType().getName()); |
|
165 | 171 |
cmgmfc.addGetMethods(getMethod); |
166 | 172 |
} |
167 | 173 |
} |
... | ... | |
172 | 178 |
} |
173 | 179 |
|
174 | 180 |
public static String getMethodNameFromFieldName(String fieldName, String type) { |
175 |
String prefix = type != null && type.toLowerCase().endsWith("boolean") ? "is" : "get";
|
|
181 |
String prefix = type != null && type.toLowerCase().endsWith("boolean") ? "is" : "get"; |
|
176 | 182 |
String getMethod = prefix + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1); |
177 | 183 |
return getMethod; |
178 | 184 |
} |
179 |
|
|
185 |
|
|
180 | 186 |
|
181 | 187 |
|
182 | 188 |
|
Also available in: Unified diff
CdmModelCacher : added recursive search in super classes
CdmTransientEntityCacher : corrected caching
EntityCacherDebugResult : new debug result object
CdmEntitySession, ICdmEntitySession, MockCdmEntitySession : added debug method
CdmEntitySessionInput : new super class for editor input objects
TaxonEditorInput : refactored and made sub class of CdmEntitySessionInput
DeleteNodeOperation : using new uuid service methods
TaxonNameEditor : removed unnecessary service call to retrieve taxon
TaxonLinkHelper : removed unnecessary second call to initialise input
AbstractCdmViewPart : now implements ISessionEnabled