changeset 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
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/Datacage.java flys-artifacts/src/main/resources/datacage-sql/org-h2-driver.properties
diffstat 3 files changed, 48 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Thu Jul 28 15:59:38 2011 +0000
+++ b/flys-artifacts/ChangeLog	Fri Jul 29 07:56:28 2011 +0000
@@ -1,3 +1,10 @@
+2011-07-29  Sascha L. Teichmann <sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/datacage/Datacage.java,
+	  src/main/resources/datacage-sql/org-h2-driver.properties:
+	  Add artifacts into datacage db at initial scan.
+	  TODO: Store data, outs and facets.
+
 2011-07-28  Sascha L. Teichmann <sascha.teichmann@intevation.de>
 
 	* doc/conf/datacage.sql: Fixed spelling in sequence name.
--- 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
--- a/flys-artifacts/src/main/resources/datacage-sql/org-h2-driver.properties	Thu Jul 28 15:59:38 2011 +0000
+++ b/flys-artifacts/src/main/resources/datacage-sql/org-h2-driver.properties	Fri Jul 29 07:56:28 2011 +0000
@@ -8,3 +8,5 @@
 artifact.by.gid = SELECT id FROM artifacts WHERE gid = ?
 collection.item.id.nextval = SELECT NEXTVAL('COLLECTION_ITEMS_ID_SEQ')
 insert.collection.item = INSERT INTO collection_items (id, collection_id, artifact_id) VALUES (?, ?, ?)
+artifact.id.nextval = SELECT NEXTVAL('ARTIFACTS_ID_SEQ')
+insert.artifact = INSERT INTO artifacts (id, gid, state) VALUES (?, ?, ?)

http://dive4elements.wald.intevation.org