changeset 184:a22b7e367b25

Added Backend code to list the collection items in a collection. artifacts/trunk@1410 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 07 Mar 2011 11:37:49 +0000
parents 9b8923043a38
children afd5945ff8d1
files ChangeLog artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java artifact-database/src/main/resources/sql/org-h2-driver.properties artifact-database/src/main/resources/sql/org-postgresql-driver.properties
diffstat 4 files changed, 53 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Mar 07 11:13:39 2011 +0000
+++ b/ChangeLog	Mon Mar 07 11:37:49 2011 +0000
@@ -1,3 +1,13 @@
+2011-03-07	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java:
+	  Added code to list the collection items in a collection.
+
+	* artifact-database/src/main/resources/sql/org-h2-driver.properties,
+	  artifact-database/src/main/resources/sql/org-postgresql-driver.properties:
+	  Added SQL statements to list the collection item 
+	  via a given collection uuid.
+
 2011-03-07  Ingo Weinzierl <ingo@intevation.de>
 
 	* artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java:
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java	Mon Mar 07 11:13:39 2011 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java	Mon Mar 07 11:37:49 2011 +0000
@@ -184,6 +184,9 @@
     public static final String SQL_COLLECTIONS_TOUCH_BY_ID =
         SQL.get("collections.touch.by.id");
 
+    public static final String SQL_COLLECTION_ITEMS_LIST_GID =
+        SQL.get("collection.items.list.gid");
+
     /** The singleton.*/
     protected static Backend instance;
 
@@ -1337,10 +1340,36 @@
         }.runWrite();
     }
 
-    public ArtifactCollection [] listCollectionArtifacts(String collectionId) {
-        // TODO: Implement me!
-        return null;
+    public CollectionItem [] listCollectionArtifacts(
+        final String collectionId
+    ) {
+        if (!isValidIdentifier(collectionId)) {
+            logger.debug("Invalid collection id: '" + collectionId + "'");
+            return null;
+        }
+
+        final ArrayList<CollectionItem> collectionItems =
+            new ArrayList<CollectionItem>();
+
+        SQLExecutor exec = new SQLExecutor() {
+            public boolean doIt() throws SQLException {
+                prepareStatement(SQL_COLLECTION_ITEMS_LIST_GID);
+                stmnt.setString(1, collectionId);
+                result = stmnt.executeQuery();
+                while (result.next()) {
+                    CollectionItem item = new CollectionItem(
+                        result.getString(1),
+                        result.getBytes(2));
+                    collectionItems.add(item);
+                }
+                return true;
+            }
+        };
+
+        return exec.runRead()
+            ? collectionItems.toArray(
+                new CollectionItem[collectionItems.size()])
+            : null;
     }
-
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/artifact-database/src/main/resources/sql/org-h2-driver.properties	Mon Mar 07 11:13:39 2011 +0000
+++ b/artifact-database/src/main/resources/sql/org-h2-driver.properties	Mon Mar 07 11:37:49 2011 +0000
@@ -75,6 +75,11 @@
 
 collection.item.delete=DELETE FROM collections_items WHERE id = ?
 
+collection.items.list.gid= \
+    SELECT a.gid, ci.attribute FROM collections_items ci \
+    INNER JOIN artifacts a ON ci.artifact_id = a.id \
+    WHERE ci.id IN (SELECT id FROM collections WHERE gid = ?)
+
 # COLLECTIONS
 collections.touch.by.gid =\
     UPDATE collection SET last_access = CURRENT_TIMESTAMP \
--- a/artifact-database/src/main/resources/sql/org-postgresql-driver.properties	Mon Mar 07 11:13:39 2011 +0000
+++ b/artifact-database/src/main/resources/sql/org-postgresql-driver.properties	Mon Mar 07 11:37:49 2011 +0000
@@ -75,6 +75,11 @@
 
 collection.item.delete=DELETE FROM collections_items WHERE id = ?
 
+collection.items.list.gid= \
+    SELECT a.gid, ci.attribute FROM collections_items ci \
+    INNER JOIN artifacts a ON ci.artifact_id = a.id \
+    WHERE ci.id IN (SELECT id FROM collections WHERE gid = ?)
+
 # COLLECTIONS
 collections.touch.by.gid =\
     UPDATE collection SET last_access = CURRENT_TIMESTAMP \

http://dive4elements.wald.intevation.org