[PATCH 2 of 2] fix issue1415: Update state of artifact when storing artifact

Wald Commits scm-commit at wald.intevation.org
Thu Jul 25 11:56:56 CEST 2013


# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1374746769 -7200
# Node ID 05395533fe82b6f929a1c88d73f66c25bfb166d5
# Parent  8a1afe974fb0edbde092047671bbdae9d44b89e8
fix issue1415: Update state of artifact when storing artifact.

diff -r 8a1afe974fb0 -r 05395533fe82 artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/Datacage.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/Datacage.java	Thu Jul 25 12:05:22 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/Datacage.java	Thu Jul 25 12:06:09 2013 +0200
@@ -70,6 +70,7 @@
     private String SQL_ARTIFACT_ID_NEXTVAL    = "artifact.id.nextval";
     private String SQL_INSERT_ARTIFACT        = "insert.artifact";
     private String SQL_ARTIFACT_DATA_ID_NEXTVAL = "artifact.data.id.nextval";
+    private String SQL_UPDATE_ARTIFACT_STATE  = "update.artifact.state";
     private String SQL_INSERT_ARTIFACT_DATA   = "insert.artifact.data";
     private String SQL_OUT_ID_NEXTVALUE       = "out.id.nextval";
     private String SQL_INSERT_OUT             = "insert.out";
@@ -382,6 +383,7 @@
         SQL_INSERT_ARTIFACT     = sql.get(SQL_INSERT_ARTIFACT);
         SQL_ARTIFACT_DATA_ID_NEXTVAL = sql.get(SQL_ARTIFACT_DATA_ID_NEXTVAL);
         SQL_INSERT_ARTIFACT_DATA = sql.get(SQL_INSERT_ARTIFACT_DATA);
+        SQL_UPDATE_ARTIFACT_STATE = sql.get(SQL_UPDATE_ARTIFACT_STATE);
         SQL_OUT_ID_NEXTVALUE     = sql.get(SQL_OUT_ID_NEXTVALUE);
         SQL_INSERT_OUT           = sql.get(SQL_INSERT_OUT);
         SQL_FACET_ID_NEXTVAL     = sql.get(SQL_FACET_ID_NEXTVAL);
@@ -608,6 +610,7 @@
         // write new data
         storeData(res[0], flys);
         storeOuts(res[0], flys, context);
+        storeState(res[0], flys);
     }
 
     public void createdUser(
@@ -884,6 +887,27 @@
         }
     }
 
+    /** Update state of artifact. */
+    protected void storeState(
+        final int         artifactId,
+        final D4EArtifact artifact) {
+        SQLExecutor.Instance exec = sqlExecutor.new Instance() {
+            @Override
+            public boolean doIt() throws SQLException {
+                prepareStatement(SQL_UPDATE_ARTIFACT_STATE);
+                stmnt.setInt(1, artifactId);
+                stmnt.setString(2, artifact.getCurrentStateId());
+                stmnt.execute();
+                conn.commit();
+                return true;
+            }
+        };
+
+        if (!exec.runWrite()) {
+            log.error("storing state of artifact failed ("+artifactId+","+artifact.getCurrentStateId()+")");
+        }
+    }
+
     protected void storeData(
         final int     artifactId,
         D4EArtifact  artifact


More information about the Dive4elements-commits mailing list