changeset 4:13a12b607baf

Added mechanism to create an share a global context in the artifact database. artifacts/trunk@13 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 04 Sep 2009 08:32:09 +0000
parents b1ec257e9d8d
children 8f2de197bce2
files Changelog artifact-database/doc/schema.sql artifacts/src/main/java/de/intevation/artifacts/Artifact.java artifacts/src/main/java/de/intevation/artifacts/ArtifactContextFactory.java artifacts/src/main/java/de/intevation/artifacts/ArtifactDatabase.java artifacts/src/main/java/de/intevation/artifacts/ArtifactFactory.java
diffstat 6 files changed, 68 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/Changelog	Thu Sep 03 16:13:25 2009 +0000
+++ b/Changelog	Fri Sep 04 08:32:09 2009 +0000
@@ -1,3 +1,19 @@
+2009-09-04	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* artifacts/src/main/java/de/intevation/artifacts/ArtifactContextFactory.java:
+	New. Factory for a global context in the artifact data base. Useful to
+	create shared ressources for artifacts like caches et al.
+
+	* artifacts/src/main/java/de/intevation/artifacts/ArtifactDatabase.java,
+	artifacts/src/main/java/de/intevation/artifacts/ArtifactFactory.java,
+	artifacts/src/main/java/de/intevation/artifacts/ArtifactContextFactory.java,
+	artifacts/src/main/java/de/intevation/artifacts/Artifact.java: Uses the
+	global context more consistent.
+
+	* artifact-database/doc/schema.sql: Using BINARY instead of BLOB to
+	avoid external files for each artifact blob. See H2 documentation
+	for details.
+
 2009-09-03	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* artifact-database/doc/schema.sql: Schema to store artifacts
--- a/artifact-database/doc/schema.sql	Thu Sep 03 16:13:25 2009 +0000
+++ b/artifact-database/doc/schema.sql	Fri Sep 04 08:32:09 2009 +0000
@@ -10,7 +10,7 @@
     creation    TIMESTAMP NOT NULL,
     last_access TIMESTAMP NOT NULL,
     ttl         TIME, -- NULL means eternal
-    data        BLOB
+    data        BINARY
 );
 
 COMMIT;
--- a/artifacts/src/main/java/de/intevation/artifacts/Artifact.java	Thu Sep 03 16:13:25 2009 +0000
+++ b/artifacts/src/main/java/de/intevation/artifacts/Artifact.java	Fri Sep 04 08:32:09 2009 +0000
@@ -15,11 +15,11 @@
  *        of this artifact.</li>
  *   <li>{@link #hash() hash()}: Returns a hash value over the internal state
  *        of this artifact.</li>
- *   <li>{@link #describe()}: Returns a description of this artifact.</li>
- *   <li>{@link #advance(String) advance()}: Advances this artifact
+ *   <li>{@link #describe(Object)}: Returns a description of this artifact.</li>
+ *   <li>{@link #advance(Document, Object) advance()}: Advances this artifact
  *       to the next internal state</li>
- *   <li>{@link #feed(Document) feed()}: Feed new data into this artifact.</li>
- *   <li>{@link #out(Document) out()}: Produces output for this artifact.</li>
+ *   <li>{@link #feed(Document, Object) feed()}: Feed new data into this artifact.</li>
+ *   <li>{@link #out(Document, Object) out()}: Produces output for this artifact.</li>
  * </ol>
  *
  * @author Sascha L. Teichmann (sascha.teichmann@intevation.de)
@@ -42,29 +42,33 @@
 
     /**
      * A description used to build a interface to interact with this artifact.
+     * @param context The global context of the runtime system.
      * @return An XML representation of the current state of the artifact.
      */
-    public Document describe();
+    public Document describe(Object context);
 
     /**
      * Change the internal state of the artifact.
-     * @param target Target of internal state to move to.
      * @return An XML representation of the success of the advancing.
+     * @param target Target of internal state to move to.
+     * @param context The global context of the runtime system.
      */
-    public Document advance(String target);
+    public Document advance(Document target, Object context);
 
     /**
      * Feed data into this artifact.
      * @param data Data to feed artifact with.
+     * @param context The global context of the runtime system.
      * @return An XML representation of the success of the feeding.
      */
-    public Document feed(Document data);
+    public Document feed(Document data, Object context);
 
     /**
      * Produce output from this artifact.
      * @param format Specifies the format of the output.
+     * @param context The global context of the runtime system.
      * @return a byte representation of the output.
      */
-    public byte [] out(Document format);
+    public byte [] out(Document format, Object context);
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/de/intevation/artifacts/ArtifactContextFactory.java	Fri Sep 04 08:32:09 2009 +0000
@@ -0,0 +1,21 @@
+package de.intevation.artifacts;
+
+import org.w3c.dom.Document;
+
+/**
+ * Interface of a factory that produces a global artifact context in the artifact data base.
+ *
+ * @author Sascha L. Teichmann (sascha.teichmann@intevation.de)
+ */
+public interface ArtifactContextFactory
+{
+    /**
+     * Creates a global context given a configuration in the artifact data base.
+     * @param config the configuration.
+     * @return The global context.
+     *   {@link de.intevation.artifacts.ArtifactFactory#createArtifact(String, Object) createArtifact()}
+     *   {@link de.intevation.artifacts.Artifact Artifact}
+     */
+    Object createArtifactContext(Document config);
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:
--- a/artifacts/src/main/java/de/intevation/artifacts/ArtifactDatabase.java	Thu Sep 03 16:13:25 2009 +0000
+++ b/artifacts/src/main/java/de/intevation/artifacts/ArtifactDatabase.java	Fri Sep 04 08:32:09 2009 +0000
@@ -21,8 +21,15 @@
 
     /**
      * Creates new artifact with a certain factory.
-     * @param factoryName the name of the factory. Name out of {@see #getArtifactFactoryNames() getArtifactFactoryNames()}.
+     * @param factoryName the name of the factory. Name out of {@link #getArtifactFactoryNames() getArtifactFactoryNames()}.
      */
     Artifact createArtifactWithFactory(String factoryName);
+
+
+    /**
+     * Returns the global artifact runtime context.
+     * @return the runtime context
+     */
+    Object getArtifactContext();
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:
--- a/artifacts/src/main/java/de/intevation/artifacts/ArtifactFactory.java	Thu Sep 03 16:13:25 2009 +0000
+++ b/artifacts/src/main/java/de/intevation/artifacts/ArtifactFactory.java	Fri Sep 04 08:32:09 2009 +0000
@@ -1,5 +1,7 @@
 package de.intevation.artifacts;
 
+import org.w3c.dom.Document;
+
 /**
  * Interface of an artifact producing factory.
  *
@@ -26,6 +28,12 @@
      * @param identifier unique identifer for the new artifact
      * @return a new {@linkplain de.intevation.artifacts.Artifact Artifact}
      */
-    Artifact createArtifact(Object context, String identifier);
+    Artifact createArtifact(String identifier, Object context);
+
+    /**
+     * Setup the factory with a given configuration
+     * @param config the configuration
+     */
+    void setup(Document config);
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:

http://dive4elements.wald.intevation.org