comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java @ 691:2600aa2c7319 facets-slt

Store facets for each state. flys-artifacts/branches/facets-slt@2131 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 16 Jun 2011 09:04:59 +0000
parents 3481cd37e609
children 22e4bffbe240
comparison
equal deleted inserted replaced
690:3481cd37e609 691:2600aa2c7319
1 package de.intevation.flys.artifacts; 1 package de.intevation.flys.artifacts;
2 2
3 import java.util.ArrayList; 3 import java.util.ArrayList;
4 import java.util.Collection; 4 import java.util.Collection;
5 import java.util.Collections; 5 import java.util.Collections;
6 import java.util.HashMap;
6 import java.util.TreeMap; 7 import java.util.TreeMap;
7 import java.util.List; 8 import java.util.List;
8 import java.util.Map; 9 import java.util.Map;
9 import java.util.Set; 10 import java.util.Set;
10 11
102 103
103 /** The data that have been inserted into this artifact.*/ 104 /** The data that have been inserted into this artifact.*/
104 protected Map<String, StateData> data; 105 protected Map<String, StateData> data;
105 106
106 /** The list of facets supported by this artifact.*/ 107 /** The list of facets supported by this artifact.*/
107 protected List<Facet> facets; 108 protected Map<String, List<Facet>> facets;
108 109
109 110
110 /** 111 /**
111 * The default constructor that creates an empty FLYSArtifact. 112 * The default constructor that creates an empty FLYSArtifact.
112 */ 113 */
113 public FLYSArtifact() { 114 public FLYSArtifact() {
114 data = new TreeMap<String, StateData>(); 115 data = new TreeMap<String, StateData>();
115 previousStateIds = new ArrayList<String>(); 116 previousStateIds = new ArrayList<String>();
116 facets = new ArrayList<Facet>(); 117 facets = new HashMap<String, List<Facet>>();
117 } 118 }
118 119
119 120
120 /** 121 /**
121 * Returns the name of the concrete artifact. 122 * Returns the name of the concrete artifact.
256 257
257 for (int i = start; i >= targetIdx; i--) { 258 for (int i = start; i >= targetIdx; i--) {
258 String prev = prevs.get(i); 259 String prev = prevs.get(i);
259 logger.debug("Remove state id '" + prev + "'"); 260 logger.debug("Remove state id '" + prev + "'");
260 prevs.remove(prev); 261 prevs.remove(prev);
262 facets.remove(prev);
261 } 263 }
262 264
263 setCurrentStateId(targetState); 265 setCurrentStateId(targetState);
264 266
265 compute(context, ComputeType.ADVANCE); 267 compute(context, ComputeType.ADVANCE);
1087 public Object compute( 1089 public Object compute(
1088 String key, 1090 String key,
1089 ComputeCallback callback, 1091 ComputeCallback callback,
1090 ComputeType type) 1092 ComputeType type)
1091 { 1093 {
1094 String stateId = getCurrentStateId();
1095 List<Facet> fs = facets.get(stateId);
1096 if (fs == null) {
1097 fs = new ArrayList<Facet>();
1098 facets.put(stateId, fs);
1099 }
1100
1092 Cache cache = CacheFactory.getCache(COMPUTING_CACHE); 1101 Cache cache = CacheFactory.getCache(COMPUTING_CACHE);
1093
1094 if (cache == null) { 1102 if (cache == null) {
1095 switch (type) { 1103 switch (type) {
1096 case FEED: 1104 case FEED:
1097 return callback.computeFeed(facets); 1105 return callback.computeFeed(fs);
1098 1106
1099 case ADVANCE: 1107 case ADVANCE:
1100 return callback.computeAdvance(facets); 1108 return callback.computeAdvance(fs);
1101 } 1109 }
1102 } 1110 }
1103 1111
1104 net.sf.ehcache.Element element = cache.get(key); 1112 net.sf.ehcache.Element element = cache.get(key);
1105 if (element != null) { 1113 if (element != null) {
1108 } 1116 }
1109 1117
1110 Object result = null; 1118 Object result = null;
1111 switch (type) { 1119 switch (type) {
1112 case FEED: 1120 case FEED:
1113 result = callback.computeFeed(facets); 1121 result = callback.computeFeed(fs);
1114 break; 1122 break;
1115 1123
1116 case ADVANCE: 1124 case ADVANCE:
1117 result = callback.computeAdvance(facets); 1125 result = callback.computeAdvance(fs);
1118 } 1126 }
1119 1127
1120 if (result != null) { 1128 if (result != null) {
1121 cache.put(new net.sf.ehcache.Element(key, result)); 1129 cache.put(new net.sf.ehcache.Element(key, result));
1122 } 1130 }

http://dive4elements.wald.intevation.org