# HG changeset patch # User Sascha L. Teichmann # Date 1312213424 0 # Node ID ddc35c950e97b9e23c26eafc2c2d594d25bb76fa # Parent fa056f9c8a0cca20072c1970d316c7cc4d58170a Backend: Handle forgotten store/create event source. artifacts/trunk@2440 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r fa056f9c8a0c -r ddc35c950e97 ChangeLog --- 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 + + * 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 * artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java: diff -r fa056f9c8a0c -r ddc35c950e97 artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.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(); 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 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); } } diff -r fa056f9c8a0c -r ddc35c950e97 artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java --- 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 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 alreadyLoaded = new LRUCache(200);