diff 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
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Fri Jun 17 16:17:03 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Sat Jun 18 17:03:17 2011 +0000
@@ -196,7 +196,7 @@
         try {
             saveData(target, XPATH_FEED_INPUT, context);
 
-            compute(context, ComputeType.FEED);
+            compute(context, ComputeType.FEED, true);
 
             return describe(target, context);
         }
@@ -245,7 +245,7 @@
             setCurrentStateId(targetState);
 
             logger.debug("Compute data for state: " + targetState);
-            compute(context, ComputeType.ADVANCE);
+            compute(context, ComputeType.ADVANCE, true);
 
             return describe(target, context);
         }
@@ -1076,14 +1076,15 @@
     public String hash() {
         Set<Map.Entry<String, StateData>> entries = data.entrySet();
 
-        int hash  = 0;
-        int shift = 3;
+        long hash  = 0L;
+        int  shift = 3;
 
         for (Map.Entry<String, StateData> entry: entries) {
             String key   = entry.getKey();
             Object value = entry.getValue().getValue();
 
-            hash ^= (key.hashCode() << shift) | (value.hashCode() << 2 * shift);
+            hash ^= ((long)key.hashCode() << shift) 
+                 |  ((long)value.hashCode() << (shift + shift));
             shift += 2;
         }
 
@@ -1098,8 +1099,12 @@
      *
      * @param context The CallContext.
      */
-    public Object compute(CallContext context, ComputeType type) {
-        return compute(context, hash(), type);
+    public Object compute(
+        CallContext context, 
+        ComputeType type, 
+        boolean     generateFacets
+    ) {
+        return compute(context, hash(), type, generateFacets);
     }
 
 
@@ -1114,12 +1119,17 @@
      *
      * @return the computed data.
      */
-    public Object compute(CallContext context, String hash, ComputeType type) {
+    public Object compute(
+        CallContext context,
+        String      hash,
+        ComputeType type, 
+        boolean     generateFacets
+    ) {
         DefaultState current = (DefaultState) getCurrentState(context);
 
         logger.debug("Create ComputeCallback for state: " + current.getID());
 
-        return compute(context, hash, current, type);
+        return compute(context, hash, current, type, generateFacets);
     }
 
 
@@ -1127,11 +1137,12 @@
         CallContext   context,
         String        key,
         DefaultState  state,
-        ComputeType   type
+        ComputeType   type,
+        boolean       generateFacets
     ) {
         String stateID = state.getID();
 
-        List<Facet> fs = new ArrayList<Facet>();
+        List<Facet> fs = generateFacets ? new ArrayList<Facet>() : null;
 
         try {
             Cache cache = CacheFactory.getCache(COMPUTING_CACHE);
@@ -1168,11 +1179,13 @@
             return res;
         }
         finally {
-            if (fs.isEmpty()) {
-                facets.remove(stateID);
-            }
-            else {
-                facets.put(stateID, fs);
+            if (generateFacets) {
+                if (fs.isEmpty()) {
+                    facets.remove(stateID);
+                }
+                else {
+                    facets.put(stateID, fs);
+                }
             }
         }
     }

http://dive4elements.wald.intevation.org