changeset 313:ddc35c950e97

Backend: Handle forgotten store/create event source. artifacts/trunk@2440 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 01 Aug 2011 15:43:44 +0000
parents fa056f9c8a0c
children 31ee2b3b5a57
files ChangeLog artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java
diffstat 3 files changed, 28 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Aug 01 14:54:34 2011 +0000
+++ b/ChangeLog	Mon Aug 01 15:43:44 2011 +0000
@@ -1,3 +1,11 @@
+2011-08-01	Sascha L. Teichmann	<teichmann@intevation.de>
+
+	* artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java:
+	  Reorganized code a bit.
+
+	* artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java: Added some
+	  debug output. Handle forgotten store/create event source.
+
 2011-08-01	Sascha L. Teichmann	<teichmann@intevation.de>
 
 	* artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java:
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java	Mon Aug 01 14:54:34 2011 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java	Mon Aug 01 15:43:44 2011 +0000
@@ -462,6 +462,8 @@
      */
     public ArtifactDatabaseImpl(FactoryBootstrap bootstrap, Backend backend) {
 
+        logger.debug("new ArtifactDatabaseImpl");
+
         backgroundIds = new HashSet<Integer>();
 
         setupArtifactCollectionFactory(bootstrap);
@@ -477,9 +479,7 @@
 
         exportSecret = bootstrap.getExportSecret();
 
-        wireWithBackend(backend);
-
-        setupBackendListeners(bootstrap);
+        wireWithBackend(backend, bootstrap);
     }
 
     public CallContext.Listener getCallContextListener() {
@@ -551,8 +551,9 @@
     }
 
     protected void setupBackendListeners(FactoryBootstrap bootstrap) {
+        logger.debug("setupBackendListeners");
         List<BackendListener> bls = bootstrap.getBackendListeners();
-        if (bls != null) {
+        if (bls != null && !bls.isEmpty()) {
             for (BackendListener listener: bls) {
                 listener.setup(context);
             }
@@ -609,10 +610,12 @@
      * via the serializers of this artifact factories.
      * @param backend The backend to be wired with this artifact database.
      */
-    public void wireWithBackend(Backend backend) {
+    public void wireWithBackend(Backend backend, FactoryBootstrap bootstrap) {
+        logger.debug("wireWithBackend");
         if (backend != null) {
             this.backend = backend;
             backend.setFactoryLookup(this);
+            setupBackendListeners(bootstrap);
         }
     }
 
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java	Mon Aug 01 14:54:34 2011 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java	Mon Aug 01 15:43:44 2011 +0000
@@ -357,10 +357,12 @@
 
     public void addListener(BackendListener listener) {
         listeners.add(listener);
+        logger.debug("# listeners: " + listeners.size());
     }
 
     public void addAllListeners(List<BackendListener> others) {
         listeners.addAll(others);
+        logger.debug("# listeners: " + listeners.size());
     }
 
     /**
@@ -603,7 +605,8 @@
             throw new RuntimeException("No valid UUID");
         }
 
-        final int [] id = new int[1];
+        final int     [] id     = new int[1];
+        final boolean [] stored = new boolean[1];
 
         SQLExecutor.Instance exec = sqlExecutor.new Instance() {
             public boolean doIt() throws SQLException {
@@ -618,7 +621,7 @@
 
                 reset();
 
-                if (ID != null) { // already in database
+                if (stored[0] = ID != null) { // already in database
                     prepareStatement(SQL_REPLACE);
 
                     if (ttl == null) {
@@ -674,6 +677,13 @@
             throw new RuntimeException("failed insert artifact into database");
         }
 
+        if (stored[0]) {
+            fireStoredArtifact(artifact);
+        }
+        else {
+            fireCreatedArtifact(artifact);
+        }
+
         return id[0];
     }
 
@@ -1738,8 +1748,6 @@
         boolean success = sqlExecutor.new Instance() {
             @Override
             public boolean doIt() throws SQLException {
-                logger.debug("doIt");
-
                 // a little cache to avoid too much deserializations.
                 LRUCache<String, Artifact> alreadyLoaded =
                     new LRUCache<String, Artifact>(200);

http://dive4elements.wald.intevation.org