changeset 1003:c58da6dd15ed

Datacage: Update collection names on change. Remove artifacts from collections. flys-artifacts/trunk@2443 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 01 Aug 2011 16:53:54 +0000
parents db86c665ab6e
children 0e8c03b69627
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 flys-artifacts/src/main/resources/datacage-sql/org-postgresql-driver.properties
diffstat 4 files changed, 69 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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 <sascha.teichmann@intevation.de>
+
+	* 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 <sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/datacage/DatacageBackendListener.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<Output> 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 :
--- 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 = ?
--- 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 = ?

http://dive4elements.wald.intevation.org