comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java @ 705:853dceead0f4

Only generate facets when needed. flys-artifacts/trunk@2157 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sat, 18 Jun 2011 17:03:17 +0000
parents eab5e5089d77
children ddd8b37d5cd3
comparison
equal deleted inserted replaced
704:eab5e5089d77 705:853dceead0f4
194 doc.appendChild(result); 194 doc.appendChild(result);
195 195
196 try { 196 try {
197 saveData(target, XPATH_FEED_INPUT, context); 197 saveData(target, XPATH_FEED_INPUT, context);
198 198
199 compute(context, ComputeType.FEED); 199 compute(context, ComputeType.FEED, true);
200 200
201 return describe(target, context); 201 return describe(target, context);
202 } 202 }
203 catch (IllegalArgumentException iae) { 203 catch (IllegalArgumentException iae) {
204 // do not store state if validation fails. 204 // do not store state if validation fails.
243 prev.add(getCurrentStateId()); 243 prev.add(getCurrentStateId());
244 244
245 setCurrentStateId(targetState); 245 setCurrentStateId(targetState);
246 246
247 logger.debug("Compute data for state: " + targetState); 247 logger.debug("Compute data for state: " + targetState);
248 compute(context, ComputeType.ADVANCE); 248 compute(context, ComputeType.ADVANCE, true);
249 249
250 return describe(target, context); 250 return describe(target, context);
251 } 251 }
252 else if (isPreviousState(targetState, context)) { 252 else if (isPreviousState(targetState, context)) {
253 logger.info("Advance: Step back to"); 253 logger.info("Advance: Step back to");
1074 */ 1074 */
1075 @Override 1075 @Override
1076 public String hash() { 1076 public String hash() {
1077 Set<Map.Entry<String, StateData>> entries = data.entrySet(); 1077 Set<Map.Entry<String, StateData>> entries = data.entrySet();
1078 1078
1079 int hash = 0; 1079 long hash = 0L;
1080 int shift = 3; 1080 int shift = 3;
1081 1081
1082 for (Map.Entry<String, StateData> entry: entries) { 1082 for (Map.Entry<String, StateData> entry: entries) {
1083 String key = entry.getKey(); 1083 String key = entry.getKey();
1084 Object value = entry.getValue().getValue(); 1084 Object value = entry.getValue().getValue();
1085 1085
1086 hash ^= (key.hashCode() << shift) | (value.hashCode() << 2 * shift); 1086 hash ^= ((long)key.hashCode() << shift)
1087 | ((long)value.hashCode() << (shift + shift));
1087 shift += 2; 1088 shift += 2;
1088 } 1089 }
1089 1090
1090 return getCurrentStateId() + hash; 1091 return getCurrentStateId() + hash;
1091 } 1092 }
1096 * hash) with the current hash value of the artifact which is provided by 1097 * hash) with the current hash value of the artifact which is provided by
1097 * hash(). 1098 * hash().
1098 * 1099 *
1099 * @param context The CallContext. 1100 * @param context The CallContext.
1100 */ 1101 */
1101 public Object compute(CallContext context, ComputeType type) { 1102 public Object compute(
1102 return compute(context, hash(), type); 1103 CallContext context,
1104 ComputeType type,
1105 boolean generateFacets
1106 ) {
1107 return compute(context, hash(), type, generateFacets);
1103 } 1108 }
1104 1109
1105 1110
1106 /** 1111 /**
1107 * Dispatches computation requests to the current state which needs to 1112 * Dispatches computation requests to the current state which needs to
1112 * @param hash The hash value which is used to fetch computed data from 1117 * @param hash The hash value which is used to fetch computed data from
1113 * cache. 1118 * cache.
1114 * 1119 *
1115 * @return the computed data. 1120 * @return the computed data.
1116 */ 1121 */
1117 public Object compute(CallContext context, String hash, ComputeType type) { 1122 public Object compute(
1123 CallContext context,
1124 String hash,
1125 ComputeType type,
1126 boolean generateFacets
1127 ) {
1118 DefaultState current = (DefaultState) getCurrentState(context); 1128 DefaultState current = (DefaultState) getCurrentState(context);
1119 1129
1120 logger.debug("Create ComputeCallback for state: " + current.getID()); 1130 logger.debug("Create ComputeCallback for state: " + current.getID());
1121 1131
1122 return compute(context, hash, current, type); 1132 return compute(context, hash, current, type, generateFacets);
1123 } 1133 }
1124 1134
1125 1135
1126 public Object compute( 1136 public Object compute(
1127 CallContext context, 1137 CallContext context,
1128 String key, 1138 String key,
1129 DefaultState state, 1139 DefaultState state,
1130 ComputeType type 1140 ComputeType type,
1141 boolean generateFacets
1131 ) { 1142 ) {
1132 String stateID = state.getID(); 1143 String stateID = state.getID();
1133 1144
1134 List<Facet> fs = new ArrayList<Facet>(); 1145 List<Facet> fs = generateFacets ? new ArrayList<Facet>() : null;
1135 1146
1136 try { 1147 try {
1137 Cache cache = CacheFactory.getCache(COMPUTING_CACHE); 1148 Cache cache = CacheFactory.getCache(COMPUTING_CACHE);
1138 1149
1139 Object old = null; 1150 Object old = null;
1166 } 1177 }
1167 1178
1168 return res; 1179 return res;
1169 } 1180 }
1170 finally { 1181 finally {
1171 if (fs.isEmpty()) { 1182 if (generateFacets) {
1172 facets.remove(stateID); 1183 if (fs.isEmpty()) {
1173 } 1184 facets.remove(stateID);
1174 else { 1185 }
1175 facets.put(stateID, fs); 1186 else {
1187 facets.put(stateID, fs);
1188 }
1176 } 1189 }
1177 } 1190 }
1178 } 1191 }
1179 1192
1180 1193

http://dive4elements.wald.intevation.org