# HG changeset patch # User Sascha L. Teichmann # Date 1299497869 0 # Node ID a22b7e367b2527c4323be735a79f7a6ba2795729 # Parent 9b8923043a386f7eaa79a0e3217aff439199327a Added Backend code to list the collection items in a collection. artifacts/trunk@1410 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 9b8923043a38 -r a22b7e367b25 ChangeLog --- 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 + + * 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 * artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java: diff -r 9b8923043a38 -r a22b7e367b25 artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.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 collectionItems = + new ArrayList(); + + 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 : diff -r 9b8923043a38 -r a22b7e367b25 artifact-database/src/main/resources/sql/org-h2-driver.properties --- 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 \ diff -r 9b8923043a38 -r a22b7e367b25 artifact-database/src/main/resources/sql/org-postgresql-driver.properties --- 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 \