# HG changeset patch # User Sascha L. Teichmann # Date 1311926188 0 # Node ID f3be883325ce467a826be28ca95a30dcbd5398a0 # Parent dbe39e1fb5e7fbab7a093ffc545fe912208d65ee Add artifacts into datacage db at initial scan. flys-artifacts/trunk@2421 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r dbe39e1fb5e7 -r f3be883325ce flys-artifacts/ChangeLog --- 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 + + * 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 * doc/conf/datacage.sql: Fixed spelling in sequence name. diff -r dbe39e1fb5e7 -r f3be883325ce flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/Datacage.java --- 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 diff -r dbe39e1fb5e7 -r f3be883325ce flys-artifacts/src/main/resources/datacage-sql/org-h2-driver.properties --- 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 (?, ?, ?)