diff artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java @ 84:72e2dd4feb31

Added the time to live of an artifact to the CallContext. artifacts/trunk@828 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 25 Mar 2010 17:32:54 +0000
parents 8447467cef86
children b2e0cb83631c
line wrap: on
line diff
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java	Mon Mar 22 15:54:06 2010 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java	Thu Mar 25 17:32:54 2010 +0000
@@ -58,15 +58,18 @@
     {
         private Artifact           artifact;
         private ArtifactSerializer serializer;
+        private Long               ttl;
 
         public PersistentArtifact(
             Artifact           artifact,
             ArtifactSerializer serializer,
+            Long               ttl,
             int                id
         ) {
             super(id);
             this.artifact   = artifact;
             this.serializer = serializer;
+            this.ttl        = ttl;
         }
 
         public Artifact getArtifact() {
@@ -77,6 +80,10 @@
             return serializer;
         }
 
+        public Long getTTL() {
+            return ttl;
+        }
+
         public void store() {
             if (logger.isDebugEnabled()) {
                 logger.debug("storing artifact id = " + getId());
@@ -122,6 +129,7 @@
         return new PersistentArtifact(
             artifact,
             factory.getSerializer(),
+            ttl,
             insertDatabase(artifact, factory, ttl));
     }
 
@@ -135,12 +143,13 @@
         return new PersistentArtifact(
             artifact,
             factory.getSerializer(),
+            ttl,
             storeOrReplaceDatabase(artifact, factory, ttl));
     }
 
     public interface ArtifactLoader {
 
-        Object load(ArtifactFactory factory, byte [] bytes, int id);
+        Object load(ArtifactFactory factory, Long ttl, byte [] bytes, int id);
 
     } // interface ArtifactLoader
 
@@ -152,6 +161,7 @@
 
                 public Object load(
                     ArtifactFactory factory,
+                    Long            ttl,
                     byte []         bytes,
                     int             id
                 ) {
@@ -161,7 +171,7 @@
 
                     return artifact == null
                         ? null
-                        : new PersistentArtifact(artifact, serializer, id);
+                        : new PersistentArtifact(artifact, serializer, ttl, id);
                 }
             });
     }
@@ -188,12 +198,14 @@
                 return null;
             }
 
-            int  id  = load_result.getInt(1);
-            long ttl = load_result.getLong(3);
+            int  id   = load_result.getInt(1);
+            long ttlX = load_result.getLong(3);
 
-            if (!load_result.wasNull()) { // real time to life
+            Long ttl = load_result.wasNull() ? null : Long.valueOf(ttlX);
+
+            if (ttl != null) { // real time to life
                 long last_access = load_result.getTimestamp(2).getTime();
-                if (last_access + ttl < System.currentTimeMillis()) {
+                if (last_access + ttlX < System.currentTimeMillis()) {
                     artifactOutdated(id);
                     return null;
                 }
@@ -216,7 +228,7 @@
 
             byte [] bytes = load_result.getBytes(5);
 
-            return loader.load(factory, bytes, id);
+            return loader.load(factory, ttl, bytes, id);
         }
         catch (SQLException sqle) {
             logger.error(sqle.getLocalizedMessage(), sqle);

http://dive4elements.wald.intevation.org