comparison gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java @ 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
comparison
equal deleted inserted replaced
608:74dfb9346574 609:22e65fb4c64a
74 /** input value names which should not be rendered from State itself */ 74 /** input value names which should not be rendered from State itself */
75 public final static String[] BLACKLIST = {"sourceid", "fisname"}; 75 public final static String[] BLACKLIST = {"sourceid", "fisname"};
76 76
77 private String id = null; 77 private String id = null;
78 78
79 protected String hash;
80
79 private String description = null; 81 private String description = null;
80 82
81 protected String dataName = null; 83 protected String dataName = null;
82 84
83 protected String preSettingsName = null; 85 protected String preSettingsName = null;
350 } 352 }
351 } else { 353 } else {
352 log.warn("No Inputdata given"); 354 log.warn("No Inputdata given");
353 } 355 }
354 356
357 setHash(uuid);
355 } 358 }
356 359
357 360
358 /** 361 /**
359 * 362 *
385 } 388 }
386 389
387 public void initialize(String uuid, CallContext context) 390 public void initialize(String uuid, CallContext context)
388 throws StateException 391 throws StateException
389 { 392 {
390 /*
391 try {
392 getDescibeData(uuid);
393 }
394 catch (RuntimeException e) {
395 log.error(e, e);
396 throw new StateException(e);
397 }
398 */
399 } 393 }
400 394
401 /** 395 /**
402 * @return 396 * @return
403 */ 397 */
887 881
888 node.appendChild(groupNode); 882 node.appendChild(groupNode);
889 } 883 }
890 884
891 885
892 protected String getHash(String uuid) { 886 protected void setHash(String uuid) {
893 return uuid + id + inputData.hashCode(); 887 this.hash = uuid + id + inputData.hashCode();
888 }
889
890
891 protected String getHash() {
892 return this.hash;
894 } 893 }
895 894
896 895
897 /** 896 /**
898 * @see de.intevation.gnv.state.State#getDescibeData() 897 * @see de.intevation.gnv.state.State#getDescibeData()
899 */ 898 */
900 public List<Object> getDescibeData(String uuid) { 899 public List<Object> getDescibeData(String uuid) {
901 CacheFactory factory = CacheFactory.getInstance(); 900 CacheFactory factory = CacheFactory.getInstance();
902 if (factory.isInitialized()) { 901 if (factory.isInitialized()) {
903 // we use a cache 902 // we use a cache
903 log.debug("Using cache.");
904 Cache cache = factory.getCache(); 904 Cache cache = factory.getCache();
905 905 String key = getHash();
906 String key = getHash(uuid);
907 906
908 net.sf.ehcache.Element value = cache.get(key); 907 net.sf.ehcache.Element value = cache.get(key);
909 if (value != null) { 908 if (value != null) {
910 // element already in cache, so return it. 909 // element already in cache, so return it.
910 log.debug("Found element in cache.");
911 return (List<Object>) (value.getObjectValue()); 911 return (List<Object>) (value.getObjectValue());
912 } 912 }
913 else { 913 else {
914 // element is not in cache yet, so we need to fetch data from 914 // element is not in cache yet, so we need to fetch data from
915 // database and put it into cache right now 915 // database and put it into cache right now
916 log.debug("Element not in cache, we need to ask the database");
916 try { 917 try {
917 String[] filterValues = generateFilterValuesFromInputData(); 918 String[] filterValues = generateFilterValuesFromInputData();
918 List<Object> data = queryDatabase(filterValues, uuid); 919 List<Object> data = queryDatabase(filterValues, uuid);
919 920
920 cache.put(new net.sf.ehcache.Element(key, data)); 921 cache.put(new net.sf.ehcache.Element(key, data));
927 } 928 }
928 } 929 }
929 else { 930 else {
930 // we don't use a cache, so we have to query the database every 931 // we don't use a cache, so we have to query the database every
931 // single time 932 // single time
933 log.debug("Not using cache.");
932 String[] filterValues = generateFilterValuesFromInputData(); 934 String[] filterValues = generateFilterValuesFromInputData();
933 Collection<Result> result = null; 935 Collection<Result> result = null;
934 try { 936 try {
935 return queryDatabase(filterValues, uuid); 937 return queryDatabase(filterValues, uuid);
936 } 938 }

http://dive4elements.wald.intevation.org