diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/Datacage.java @ 989:f3be883325ce

Add artifacts into datacage db at initial scan. flys-artifacts/trunk@2421 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 29 Jul 2011 07:56:28 +0000
parents dbe39e1fb5e7
children e573c4715d81
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/Datacage.java	Thu Jul 28 15:59:38 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/Datacage.java	Fri Jul 29 07:56:28 2011 +0000
@@ -40,6 +40,8 @@
     private String SQL_COLLECTION_ITEM_ID_NEXTVAL =
         "collection.item.id.nextval";
     private String SQL_INSERT_COLLECTION_ITEM = "insert.collection.item";
+    private String SQL_ARTIFACT_ID_NEXTVAL    = "artifact.id.nextval";
+    private String SQL_INSERT_ARTIFACT        = "insert.artifact";
 
 
     protected SQLExecutor sqlExecutor;
@@ -113,9 +115,9 @@
         }
 
         protected void storeArtifact(
-            String       artifactId,
-            Integer      collectionId,
-            FLYSArtifact artifact
+            final String       artifactId,
+            Integer            collectionId,
+            final FLYSArtifact artifact
         ) {
             Integer aId = getId(artifacts, artifactId, SQL_ARTIFACT_BY_GID);
 
@@ -125,6 +127,38 @@
                 return;
             }
             // We need to write it to database
+
+            final Integer [] res = new Integer[1];
+
+            SQLExecutor.Instance exec = sqlExecutor.new Instance() {
+                @Override
+                public boolean doIt() throws SQLException {
+                    prepareStatement(SQL_ARTIFACT_ID_NEXTVAL);
+                    result = stmnt.executeQuery();
+                    if (!result.next()) {
+                        return false;
+                    }
+                    res[0] = result.getInt(1);
+                    reset();
+                    prepareStatement(SQL_INSERT_ARTIFACT);
+                    stmnt.setInt   (1, res[0]);
+                    stmnt.setString(2, artifactId);
+                    stmnt.setString(3, artifact.getCurrentStateId());
+                    stmnt.execute();
+                    return true;
+                }
+            };
+
+            if (!exec.runWrite()) {
+                log.error("storing of artifact failed.");
+                return;
+            }
+
+            artifacts.put(artifactId, aId = res[0]);
+
+            storeCollectionItem(collectionId, aId);
+
+            // store data, outs and facets
             // TODO: Implement me!
         }
 
@@ -270,6 +304,8 @@
             sql.get(SQL_COLLECTION_ITEM_ID_NEXTVAL);
         SQL_INSERT_COLLECTION_ITEM =
             sql.get(SQL_INSERT_COLLECTION_ITEM);
+        SQL_ARTIFACT_ID_NEXTVAL = sql.get(SQL_ARTIFACT_ID_NEXTVAL);
+        SQL_INSERT_ARTIFACT     = sql.get(SQL_INSERT_ARTIFACT);
     }
 
     @Override

http://dive4elements.wald.intevation.org