# HG changeset patch # User Ingo Weinzierl # Date 1265878498 0 # Node ID 22e65fb4c64ad1699a415132dbaf27d910f85c80 # Parent 74dfb9346574a7b8efa74d0f4bfd7062d80b91f0 Improved hash creation in each state. gnv-artifacts/trunk@675 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 74dfb9346574 -r 22e65fb4c64a gnv-artifacts/ChangeLog --- 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 + + * 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 * src/main/java/de/intevation/gnv/state/StateBase.java: Append description diff -r 74dfb9346574 -r 22e65fb4c64a gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java --- 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) (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 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 = null; try {