changeset 1227:cdb35d96ca09

Importer session: Make use of the LRU cache from artifacts common. flys-backend/trunk@2415 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 28 Jul 2011 14:12:33 +0000
parents 1dbafbba50ea
children a964636a0be3
files flys-backend/ChangeLog flys-backend/src/main/java/de/intevation/flys/importer/ImporterSession.java
diffstat 2 files changed, 13 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/flys-backend/ChangeLog	Tue Jul 19 10:10:51 2011 +0000
+++ b/flys-backend/ChangeLog	Thu Jul 28 14:12:33 2011 +0000
@@ -1,3 +1,8 @@
+2011-07-28	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/importer/ImporterSession.java:
+	  Make use of the LRU cache from artifacts common.
+
 2011-07-18	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* doc/schema/postgresql.sql: Added missing foreign key contraint on hyks table.
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImporterSession.java	Tue Jul 19 10:10:51 2011 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImporterSession.java	Thu Jul 28 14:12:33 2011 +0000
@@ -3,7 +3,6 @@
 import java.util.Iterator;
 import java.util.Map;
 import java.util.TreeMap;
-import java.util.LinkedHashMap;
 
 import java.math.BigDecimal;
 
@@ -23,19 +22,12 @@
 
 import org.apache.log4j.Logger;
 
+import de.intevation.artifacts.common.utils.LRUCache;
+
 public class ImporterSession
 {
     private static Logger log = Logger.getLogger(ImporterSession.class);
 
-    public static final int CACHE_SIZE = 25;
-
-    public static class Cache<K, V> extends LinkedHashMap<K, V> {
-        @Override
-        protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
-            return size() > CACHE_SIZE;
-        }
-    };
-
     private static final ThreadLocal<ImporterSession> SESSION =
         new ThreadLocal<ImporterSession>() {
             @Override
@@ -46,13 +38,13 @@
 
     protected Session databaseSession;
 
-    protected Cache<Integer, Map<ValueKey, WstColumnValue>>
+    protected LRUCache<Integer, Map<ValueKey, WstColumnValue>>
         wstColumnValues;
 
-    protected Cache<Integer, Map<ValueKey, DischargeTableValue>>
+    protected LRUCache<Integer, Map<ValueKey, DischargeTableValue>>
         dischargeTableValues;
 
-    protected Cache<Integer, Map<ValueKey, Range>>
+    protected LRUCache<Integer, Map<ValueKey, Range>>
         ranges;
 
     public static ImporterSession getInstance() {
@@ -66,12 +58,12 @@
         //databaseSession.setFlushMode(FlushMode.MANUAL);
 
         wstColumnValues =
-            new Cache<Integer, Map<ValueKey, WstColumnValue>>();
+            new LRUCache<Integer, Map<ValueKey, WstColumnValue>>();
 
         dischargeTableValues =
-            new Cache<Integer, Map<ValueKey, DischargeTableValue>>();
+            new LRUCache<Integer, Map<ValueKey, DischargeTableValue>>();
 
-        ranges = new Cache<Integer, Map<ValueKey, Range>>();
+        ranges = new LRUCache<Integer, Map<ValueKey, Range>>();
     }
 
     public Session getDatabaseSession() {

http://dive4elements.wald.intevation.org