Mercurial > dive4elements > framework
changeset 178:535e4ea2ef9b
Added code to get the attribute of a collection item
artifacts/trunk@1404 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Sun, 06 Mar 2011 10:27:16 +0000 |
parents | 77cd37a93fca |
children | 644fd11ddd9f |
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 Sun Mar 06 10:03:53 2011 +0000 +++ b/ChangeLog Sun Mar 06 10:27:16 2011 +0000 @@ -1,3 +1,13 @@ +2011-03-06 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + * artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java: + Added code to get the attribute of a collection item. + + * artifact-database/src/main/resources/sql/org-h2-driver.properties, + artifact-database/src/main/resources/sql/org-postgresql-driver.properties: + Added SQL statements to get the attribute column of a collection item + given the collection and the artifact uuid. + 2011-03-06 Sascha L. Teichmann <sascha.teichmann@intevation.de> * artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java:
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java Sun Mar 06 10:03:53 2011 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java Sun Mar 06 10:27:16 2011 +0000 @@ -164,6 +164,9 @@ public static final String SQL_COLLECTION_ITEMS_INSERT = SQL.get("collection.items.insert"); + public static final String SQL_COLLECTION_ITEM_GET_ATTRIBUTE = + SQL.get("collection.item.get.attribute"); + /** The singleton.*/ protected static Backend instance; @@ -1109,11 +1112,35 @@ } public Document getCollectionAttribute( - String collectionId, - String artifactId + final String collectionId, + final String artifactId ) { - // TODO: Implement me! - return null; + if (!isValidIdentifier(collectionId)) { + logger.debug("collection id is not valid: " + collectionId); + return null; + } + if (!isValidIdentifier(artifactId)) { + logger.debug("artifact id is not valid: " + artifactId); + } + + final Document [] document = new Document[1]; + + SQLExecutor exec = new SQLExecutor() { + public boolean doIt() throws SQLException { + prepareStatement(SQL_COLLECTION_ITEM_GET_ATTRIBUTE); + stmnt.setString(1, collectionId); + stmnt.setString(2, artifactId); + result = stmnt.executeQuery(); + if (!result.next()) { + logger.debug("No such collection item"); + return false; + } + document[0] = XMLUtils.fromByteArray(result.getBytes(1)); + return true; + } + }; + + return exec.runRead() ? document[0] : null; } public boolean setCollectionAttribute(
--- a/artifact-database/src/main/resources/sql/org-h2-driver.properties Sun Mar 06 10:03:53 2011 +0000 +++ b/artifact-database/src/main/resources/sql/org-h2-driver.properties Sun Mar 06 10:27:16 2011 +0000 @@ -48,6 +48,12 @@ (id, collection_id, artifact_id, attribute) \ VALUES (?, ?, ?, ?) +collection.item.get.attribute= \ + SELECT ci.attribute FROM collections_items ci \ + INNER JOIN collection c ON ci.collection_id = c.id \ + INNER JOIN attributes a ON ci.artifact_id = a.id \ + WHERE c.gid = ? AND a.gid = ? + # COLLECTIONS collections.id.nextval=SELECT NEXTVAL('COLLECTIONS_ID_SEQ')
--- a/artifact-database/src/main/resources/sql/org-postgresql-driver.properties Sun Mar 06 10:03:53 2011 +0000 +++ b/artifact-database/src/main/resources/sql/org-postgresql-driver.properties Sun Mar 06 10:27:16 2011 +0000 @@ -48,6 +48,12 @@ (id, collection_id, artifact_id, attribute) \ VALUES (?, ?, ?, ?) +collection.item.get.attribute= \ + SELECT ci.attribute FROM collections_items ci \ + INNER JOIN collection c ON ci.collection_id = c.id \ + INNER JOIN attributes a ON ci.artifact_id = a.id \ + WHERE c.gid = ?::uuid AND a.gid = ?::uuid + # COLLECTIONS collections.id.nextval=SELECT NEXTVAL('COLLECTIONS_ID_SEQ')