changeset 609:22e65fb4c64a

Improved hash creation in each state. gnv-artifacts/trunk@675 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 11 Feb 2010 08:54:58 +0000
parents 74dfb9346574
children 6484464d2059
files gnv-artifacts/ChangeLog gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java
diffstat 2 files changed, 21 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog	Wed Feb 10 15:35:26 2010 +0000
+++ b/gnv-artifacts/ChangeLog	Thu Feb 11 08:54:58 2010 +0000
@@ -1,3 +1,9 @@
+2010-02-11  Ingo Weinzierl <ingo.weinzierl@intevation.de>
+
+	* src/main/java/de/intevation/gnv/state/StateBase.java: Improved hash
+	  creation of each state. The hash is created using the uuid, state-id and
+	  the hash code of the input data required for the sql statement.
+
 2010-02-10  Ingo Weinzierl <ingo.weinzierl@intevation.de>
 
 	* src/main/java/de/intevation/gnv/state/StateBase.java: Append description
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java	Wed Feb 10 15:35:26 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java	Thu Feb 11 08:54:58 2010 +0000
@@ -76,6 +76,8 @@
 
     private String id = null;
 
+    protected String hash;
+
     private String description = null;
 
     protected String dataName = null;
@@ -352,6 +354,7 @@
             log.warn("No Inputdata given");
         }
 
+        setHash(uuid);
     }
 
 
@@ -387,15 +390,6 @@
     public void initialize(String uuid, CallContext context)
     throws StateException
     {
-        /*
-        try {
-            getDescibeData(uuid);
-        }
-        catch (RuntimeException e) {
-            log.error(e, e);
-            throw new StateException(e);
-        }
-        */
     }
 
     /**
@@ -889,8 +883,13 @@
     }
 
 
-    protected String getHash(String uuid) {
-        return uuid + id + inputData.hashCode();
+    protected void setHash(String uuid) {
+        this.hash = uuid + id + inputData.hashCode();
+    }
+
+
+    protected String getHash() {
+        return this.hash;
     }
 
 
@@ -901,18 +900,20 @@
         CacheFactory factory = CacheFactory.getInstance();
         if (factory.isInitialized()) {
             // we use a cache
+            log.debug("Using cache.");
             Cache cache = factory.getCache();
-
-            String key = getHash(uuid);
+            String key  = getHash();
 
             net.sf.ehcache.Element value = cache.get(key);
             if (value != null) {
                 // element already in cache, so return it.
+                log.debug("Found element in cache.");
                 return (List<Object>) (value.getObjectValue());
             }
             else {
                 // element is not in cache yet, so we need to fetch data from
                 // database and put it into cache right now
+                log.debug("Element not in cache, we need to ask the database");
                 try {
                     String[] filterValues = generateFilterValuesFromInputData();
                     List<Object> data     = queryDatabase(filterValues, uuid);
@@ -929,6 +930,7 @@
         else {
             // we don't use a cache, so we have to query the database every
             // single time
+            log.debug("Not using cache.");
             String[] filterValues     = generateFilterValuesFromInputData();
             Collection<Result> result = null;
             try {

http://dive4elements.wald.intevation.org