changeset 246:a8a06bbe306c

Added calls to call init/close for call contextes. artifacts/trunk@1686 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 14 Apr 2011 11:18:10 +0000
parents def3daabc5b5
children 3a1209f214f5
files ChangeLog artifact-database/src/main/java/de/intevation/artifactdatabase/AbstractCallContext.java artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactCallContext.java artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java artifact-database/src/main/java/de/intevation/artifactdatabase/CollectionCallContext.java
diffstat 5 files changed, 71 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Apr 14 10:19:12 2011 +0000
+++ b/ChangeLog	Thu Apr 14 11:18:10 2011 +0000
@@ -1,3 +1,17 @@
+2011-04-14	Sascha L. Teichmann	<sascha.teichmann@intevation.de>	
+
+	* artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java:
+	  Call the postCall() methods of all CallContextes. Removed superfluous context
+	  paramter to AbstractCallContext constructors.
+
+	* artifact-database/src/main/java/de/intevation/artifactdatabase/AbstractCallContext.java:
+	  call ArtifactDatabaseImpl.initCallContext() in constructor and 
+	  ArtifactDatabaseImpl.closeCallContext() in postCall().
+
+	* artifact-database/src/main/java/de/intevation/artifactdatabase/CollectionCallContext.java,
+	  artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactCallContext.java:
+	  adjusted to guarantee that super.postCall() is called.
+
 2011-04-14	Sascha L. Teichmann	<sascha.teichmann@intevation.de>	
 
 	* artifacts/src/main/java/de/intevation/artifacts/CallContext.java:
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/AbstractCallContext.java	Thu Apr 14 10:19:12 2011 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/AbstractCallContext.java	Thu Apr 14 11:18:10 2011 +0000
@@ -38,11 +38,6 @@
     protected CallMeta callMeta;
 
     /**
-     * The global context.
-     */
-    protected Object context;
-
-    /**
      * Map to act like a clipboard when nesting calls like a proxy artifact.
      */
     protected HashMap customValues;
@@ -58,17 +53,19 @@
     public AbstractCallContext(
         ArtifactDatabaseImpl artifactDatabase,
         int                  action,
-        CallMeta             callMeta,
-        Object               context)
-    {
+        CallMeta             callMeta
+    ) {
         this.database = artifactDatabase;
         this.action   = action;
         this.callMeta = callMeta;
-        this.context  = context;
+
+        database.initCallContext(this);
     }
 
 
-    public abstract void postCall();
+    public void postCall() {
+        database.closeCallContext(this);
+    }
 
     public abstract void afterCall(int action);
 
@@ -78,7 +75,7 @@
 
 
     public Object globalContext() {
-        return context;
+        return database.context;
     }
 
 
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactCallContext.java	Thu Apr 14 10:19:12 2011 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactCallContext.java	Thu Apr 14 11:18:10 2011 +0000
@@ -49,10 +49,9 @@
         ArtifactDatabaseImpl artifactDatabase,
         int                  action,
         CallMeta             callMeta,
-        Object               context,
         PersistentArtifact   artifact)
     {
-        super(artifactDatabase, action, callMeta, context);
+        super(artifactDatabase, action, callMeta);
 
         this.artifact = artifact;
     }
@@ -84,23 +83,28 @@
      * the return of the concrete artifact call.
      */
     public void postCall() {
-        switch (action) {
-            case NOTHING:
-                break;
-            case TOUCH:
-                artifact.touch();
-                break;
-            case STORE:
-                artifact.store();
-                break;
-            case BACKGROUND:
-                logger.warn(
-                    "BACKGROUND processing is not fully implemented, yet!");
-                artifact.store();
-                break;
-            default:
-                logger.error(INVALID_CALL_STATE + ": " + action);
-                throw new IllegalStateException(INVALID_CALL_STATE);
+        try {
+            switch (action) {
+                case NOTHING:
+                    break;
+                case TOUCH:
+                    artifact.touch();
+                    break;
+                case STORE:
+                    artifact.store();
+                    break;
+                case BACKGROUND:
+                    logger.warn(
+                        "BACKGROUND processing is not fully implemented, yet!");
+                    artifact.store();
+                    break;
+                default:
+                    logger.error(INVALID_CALL_STATE + ": " + action);
+                    throw new IllegalStateException(INVALID_CALL_STATE);
+            }
+        }
+        finally {
+            super.postCall();
         }
     }
 }
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java	Thu Apr 14 10:19:12 2011 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java	Thu Apr 14 11:18:10 2011 +0000
@@ -273,7 +273,6 @@
                 ArtifactDatabaseImpl.this,
                 CallContext.TOUCH,
                 callMeta,
-                context,
                 artifact);
 
             try {
@@ -336,7 +335,6 @@
                 ArtifactDatabaseImpl.this,
                 CallContext.TOUCH,
                 callMeta,
-                context,
                 collection);
 
             try {
@@ -638,7 +636,6 @@
             ArtifactDatabaseImpl.this,
             CallContext.NOTHING,
             callMeta,
-            context,
             persistentArtifact);
 
         try {
@@ -667,7 +664,6 @@
             ArtifactDatabaseImpl.this,
             CallContext.TOUCH,
             callMeta,
-            context,
             artifact);
 
         try {
@@ -696,7 +692,6 @@
             ArtifactDatabaseImpl.this,
             CallContext.STORE,
             callMeta,
-            context,
             artifact);
 
         try {
@@ -721,14 +716,15 @@
             ArtifactDatabaseImpl.this,
             CallContext.STORE,
             callMeta,
-            context,
             artifact);
 
+        initCallContext(cc);
         try {
             return artifact.getArtifact().feed(data, cc);
         }
         finally {
             cc.postCall();
+            closeCallContext(cc);
         }
     }
 
@@ -926,7 +922,6 @@
             ArtifactDatabaseImpl.this,
             CallContext.NOTHING,
             callMeta,
-            context,
             persistentArtifact);
 
         try {
@@ -1239,14 +1234,19 @@
             throw new ArtifactDatabaseException(NO_SUCH_COLLECTION);
         }
 
-        CallContext cc = new CollectionCallContext(
+        CollectionCallContext cc = new CollectionCallContext(
             ArtifactDatabaseImpl.this,
             CallContext.NOTHING,
             callMeta,
-            context,
             c);
 
-        return c.describe(cc);
+        try {
+            return c.describe(cc);
+        }
+        finally {
+            cc.postCall();
+        }
+
     }
 
     public Document getCollectionAttribute(String collectionId, String artifactId,
@@ -1430,14 +1430,26 @@
             throw new ArtifactDatabaseException(NO_SUCH_COLLECTION);
         }
 
-        CallContext cc = new CollectionCallContext(
+        CollectionCallContext cc = new CollectionCallContext(
             ArtifactDatabaseImpl.this,
             CallContext.NOTHING,
             callMeta,
-            context,
             c);
 
-        return new DeferredCollectionOutputImpl(c, format, callMeta);
+        try {
+            return new DeferredCollectionOutputImpl(c, format, callMeta);
+        }
+        finally {
+            cc.postCall();
+        }
+    }
+
+    protected void initCallContext(CallContext cc) {
+        logger.info("Implement me!");
+    }
+
+    protected void closeCallContext(CallContext cc) {
+        logger.info("Implement me!");
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/CollectionCallContext.java	Thu Apr 14 10:19:12 2011 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/CollectionCallContext.java	Thu Apr 14 11:18:10 2011 +0000
@@ -33,10 +33,9 @@
         ArtifactDatabaseImpl artifactDatabase,
         int                  action,
         CallMeta             callMeta,
-        Object               context,
         ArtifactCollection   collection)
     {
-        super(artifactDatabase, action, callMeta, context);
+        super(artifactDatabase, action, callMeta);
 
         this.collection = collection;
     }
@@ -56,10 +55,5 @@
         log.debug("CollectionCallContext.getTimeToLive - NOT IMPLEMENTED");
         return null;
     }
-
-
-    public void postCall() {
-        log.debug("CollectionCallContext.postCall - NOT IMPLEMENTED");
-    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org