changeset 6661:05395533fe82

fix issue1415: Update state of artifact when storing artifact.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 25 Jul 2013 12:06:09 +0200 (2013-07-25)
parents 8a1afe974fb0
children ab11ce67854b
files artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/Datacage.java
diffstat 1 files changed, 24 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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

http://dive4elements.wald.intevation.org