# HG changeset patch # User Sascha L. Teichmann # Date 1312217634 0 # Node ID c58da6dd15edf252c8a9c78e4ceaf504581eafa0 # Parent db86c665ab6e543991f1dce6b91cb5fd56823702 Datacage: Update collection names on change. Remove artifacts from collections. flys-artifacts/trunk@2443 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r db86c665ab6e -r c58da6dd15ed flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Mon Aug 01 16:34:48 2011 +0000 +++ b/flys-artifacts/ChangeLog Mon Aug 01 16:53:54 2011 +0000 @@ -1,3 +1,12 @@ +2011-08-01 Sascha L. Teichmann + + * src/main/java/de/intevation/flys/artifacts/datacage/Datacage.java: + Update collection names on change. Remove artifacts from collections. + + * src/main/resources/datacage-sql/org-h2-driver.properties, + src/main/resources/datacage-sql/org-postgresql-driver.properties: + Added needed statements. + 2011-08-01 Sascha L. Teichmann * src/main/java/de/intevation/flys/artifacts/datacage/DatacageBackendListener.java: diff -r db86c665ab6e -r c58da6dd15ed 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 Mon Aug 01 16:34:48 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/Datacage.java Mon Aug 01 16:53:54 2011 +0000 @@ -65,6 +65,9 @@ private String SQL_INSERT_OUT = "insert.out"; private String SQL_FACET_ID_NEXTVAL = "facet.id.nextval"; private String SQL_INSERT_FACET = "insert.facet"; + private String SQL_UPDATE_COLLECTION_NAME = "update.collection.name"; + private String SQL_DELETE_ARTIFACT_FROM_COLLECTION = + "delete.artifact.from.collection"; protected SQLExecutor sqlExecutor; @@ -349,6 +352,9 @@ SQL_INSERT_OUT = sql.get(SQL_INSERT_OUT); SQL_FACET_ID_NEXTVAL = sql.get(SQL_FACET_ID_NEXTVAL); SQL_INSERT_FACET = sql.get(SQL_INSERT_FACET); + SQL_UPDATE_COLLECTION_NAME = sql.get(SQL_UPDATE_COLLECTION_NAME); + SQL_DELETE_ARTIFACT_FROM_COLLECTION = + sql.get(SQL_DELETE_ARTIFACT_FROM_COLLECTION); } protected static final int numFacets(List outs) { @@ -552,20 +558,64 @@ } public void removedArtifactFromCollection( - String artifactId, - String collectionId, + final String artifactId, + final String collectionId, Backend backend, GlobalContext context ) { log.debug("removedArtifactFromCollection"); + SQLExecutor.Instance exec = sqlExecutor.new Instance() { + @Override + public boolean doIt() throws SQLException { + prepareStatement(SQL_ARTIFACT_BY_GID); + stmnt.setString(1, artifactId); + result = stmnt.executeQuery(); + if (!result.next()) { + return false; + } + int aId = result.getInt(1); + reset(); + prepareStatement(SQL_COLLECTION_BY_GID); + stmnt.setString(1, collectionId); + result = stmnt.executeQuery(); + if (!result.next()) { + return false; + } + int cId = result.getInt(1); + reset(); + prepareStatement(SQL_DELETE_ARTIFACT_FROM_COLLECTION); + stmnt.setInt(1, cId); + stmnt.setInt(2, aId); + stmnt.execute(); + conn.commit(); + return true; + } + }; + if (!exec.runWrite()) { + log.error("removing artifact from collection failed"); + } } public void setCollectionName( - String collectionId, - String name, + final String collectionId, + final String name, GlobalContext context ) { log.debug("setCollectionName"); + SQLExecutor.Instance exec = sqlExecutor.new Instance() { + @Override + public boolean doIt() throws SQLException { + prepareStatement(SQL_UPDATE_COLLECTION_NAME); + stmnt.setString(1, name); + stmnt.setString(2, collectionId); + stmnt.execute(); + conn.commit(); + return true; + } + }; + if (!exec.runWrite()) { + log.error("changing name failed"); + } } protected void storeData( @@ -713,6 +763,5 @@ log.error("storing facets failed"); } } - } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r db86c665ab6e -r c58da6dd15ed flys-artifacts/src/main/resources/datacage-sql/org-h2-driver.properties --- a/flys-artifacts/src/main/resources/datacage-sql/org-h2-driver.properties Mon Aug 01 16:34:48 2011 +0000 +++ b/flys-artifacts/src/main/resources/datacage-sql/org-h2-driver.properties Mon Aug 01 16:53:54 2011 +0000 @@ -17,3 +17,6 @@ insert.out = INSERT INTO outs (id, artifact_id, name, description, out_type) VALUES (?, ?, ?, ?, ?) facet.id.nextval = SELECT NEXTVAL('FACETS_ID_SEQ') insert.facet = INSERT INTO facets (id, out_id, name, num, state, description) VALUES (?, ?, ?, ?, ?, ?) + +update.collection.name = UPDATE collections SET name = ? WHERE gid = ? +delete.artifact.from.collection = DELETE FROM collection_items WHERE collection_id = ? AND artifact_id = ? diff -r db86c665ab6e -r c58da6dd15ed flys-artifacts/src/main/resources/datacage-sql/org-postgresql-driver.properties --- a/flys-artifacts/src/main/resources/datacage-sql/org-postgresql-driver.properties Mon Aug 01 16:34:48 2011 +0000 +++ b/flys-artifacts/src/main/resources/datacage-sql/org-postgresql-driver.properties Mon Aug 01 16:53:54 2011 +0000 @@ -17,3 +17,6 @@ insert.out = INSERT INTO outs (id, artifact_id, name, description, out_type) VALUES (?, ?, ?, ?, ?) facet.id.nextval = SELECT NEXTVAL('FACETS_ID_SEQ') insert.facet = INSERT INTO facets (id, out_id, name, num, state, description) VALUES (?, ?, ?, ?, ?, ?) + +update.collection.name = UPDATE collections SET name = ? WHERE gid = ?::uuid +delete.artifact.from.collection = DELETE FROM collection_items WHERE collection_id = ? AND artifact_id = ?