Mercurial > dive4elements > framework
changeset 217:87a7773030b5
The Backend got a method that retrieves an ArtifactCollection based on its GID.
artifacts/trunk@1556 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 24 Mar 2011 15:41:25 +0000 |
parents | 2d90d5cfe8f9 |
children | 70cbbe144931 |
files | ChangeLog artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java |
diffstat | 2 files changed, 64 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Thu Mar 24 15:29:41 2011 +0000 +++ b/ChangeLog Thu Mar 24 15:41:25 2011 +0000 @@ -1,3 +1,8 @@ +2011-03-24 Ingo Weinzierl <ingo@intevation.de> + + * artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java: + Added a method that retrieves an ArtifactCollection based on its GID. + 2011-03-24 Sascha L. Teichmann <sascha.teichmann@intevation.de> * artifact-database/src/main/resources/sql/org-postgresql-driver.properties:
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java Thu Mar 24 15:29:41 2011 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java Thu Mar 24 15:41:25 2011 +0000 @@ -143,6 +143,9 @@ public static final String SQL_COLLECTIONS_SELECT_ALL = SQL.get("collections.select.all"); + public static final String SQL_COLLECTIONS_SELECT_GID = + SQL.get("collections.select.by.gid"); + public static final String SQL_COLLECTIONS_CREATION_TIME = SQL.get("collection.creation.time"); @@ -1037,6 +1040,62 @@ return exec.runWrite() ? collection[0]: null; } + public ArtifactCollection getCollection( + final String collectionId, + final ArtifactCollectionFactory collectionFactory, + final UserFactory userFactory, + final Object context + ) { + if (!isValidIdentifier(collectionId)) { + logger.debug("collection id is not valid: " + collectionId); + return null; + } + + final ArtifactCollection[] ac = new ArtifactCollection[1]; + + SQLExecutor exec = new SQLExecutor() { + public boolean doIt() throws SQLException { + + prepareStatement(SQL_COLLECTIONS_SELECT_GID); + stmnt.setString(1, collectionId); + + result = stmnt.executeQuery(); + if (!result.next()) { + logger.debug("No such collection"); + return false; + } + + String collectionName = result.getString(2); + String ownerId = result.getString(3); + Date creationTime = + new Date(result.getTimestamp(4).getTime()); + Date lastAccess = + new Date(result.getTimestamp(5).getTime()); + Document attr = + XMLUtils.fromByteArray(result.getBytes(6)); + + ArtifactCollection collection = + collectionFactory.createCollection( + collectionId, + collectionName, + creationTime, + attr, + context); + + if (ownerId != null) { + collection.setUser(new LazyBackendUser( + ownerId, userFactory, Backend.this, context)); + } + + ac[0] = collection; + + return true; + } + }; + + return exec.runRead() ? ac[0] : null; + } + public ArtifactCollection [] listCollections( final String ownerIdentifier, final Document data,