changeset 199:face2302387c

Insert collection attribute into database, too. Fixed broken SQL schema. artifacts/trunk@1437 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 09 Mar 2011 11:14:21 +0000
parents 6370369412e9
children 62dd8438885f
files ChangeLog artifact-database/doc/schema-h2.sql artifact-database/doc/schema-pg.sql 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 6 files changed, 33 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Mar 09 11:03:25 2011 +0000
+++ b/ChangeLog	Wed Mar 09 11:14:21 2011 +0000
@@ -1,3 +1,15 @@
+2011-03-08	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* artifact-database/doc/schema-pg.sql, artifact-database/doc/schema-h2.sql: 
+	  Fixed broken schemas.
+
+	* artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java:
+	  Insert collection attribute into database, too.
+
+	* artifact-database/src/main/resources/sql/org-h2-driver.properties,
+	  artifact-database/src/main/resources/sql/org-postgresql-driver.properties:
+	  Adjusted SQL statements to insert attribute into collection table.
+
 2011-03-09  Ingo Weinzierl <ingo@intevation.de>
 
 	* artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java:
--- a/artifact-database/doc/schema-h2.sql	Wed Mar 09 11:03:25 2011 +0000
+++ b/artifact-database/doc/schema-h2.sql	Wed Mar 09 11:14:21 2011 +0000
@@ -37,6 +37,7 @@
     creation    TIMESTAMP       NOT NULL,
     last_access TIMESTAMP       NOT NULL,
     ttl         BIGINT, -- NULL means eternal
+    attribute   BINARY
 );
 
 CREATE SEQUENCE COLLECTION_ITEMS_ID_SEQ;
--- a/artifact-database/doc/schema-pg.sql	Wed Mar 09 11:03:25 2011 +0000
+++ b/artifact-database/doc/schema-pg.sql	Wed Mar 09 11:14:21 2011 +0000
@@ -24,7 +24,7 @@
     id   int PRIMARY KEY NOT NULL,
     gid  uuid            NOT NULL UNIQUE,
     name VARCHAR(256)    NOT NULL UNIQUE,
-    role BINARY
+    role bytea
 );
 
 CREATE SEQUENCE COLLECTIONS_ID_SEQ;
@@ -37,6 +37,7 @@
     creation    timestamp       NOT NULL,
     last_access timestamp       NOT NULL,
     ttl         bigint, -- NULL means eternal
+    attribute   bytea
 );
 
 CREATE SEQUENCE COLLECTION_ITEMS_ID_SEQ;
@@ -45,7 +46,7 @@
     id            int PRIMARY KEY NOT NULL,
     collection_id int             NOT NULL REFERENCES collections(id),
     artifact_id   int             NOT NULL REFERENCES artifacts(id),
-    attribute     BINARY,
+    attribute     bytea,
     UNIQUE (collection_id, artifact_id)
 );
 
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java	Wed Mar 09 11:03:25 2011 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java	Wed Mar 09 11:14:21 2011 +0000
@@ -937,7 +937,7 @@
         final String                    ownerIdentifier, 
         final String                    name,
         final ArtifactCollectionFactory factory,
-        final Document                  data,
+        final Document                  attribute,
         final Object                    context
     ) {
         if (name == null) {
@@ -997,6 +997,15 @@
                     stmnt.setLong(5, ttl);
                 }
 
+                byte [] data = XMLUtils.toByteArray(attribute);
+
+                if (data == null) {
+                    stmnt.setNull(6, Types.BINARY);
+                }
+                else {
+                    stmnt.setBytes(6, data);
+                }
+
                 stmnt.execute();
                 conn.commit();
 
@@ -1019,7 +1028,7 @@
                 }
 
                 collection[0] = factory.createCollection(
-                    identifier, name, creationTime, data, context);
+                    identifier, name, creationTime, attribute, context);
 
                 return true;
             }
--- a/artifact-database/src/main/resources/sql/org-h2-driver.properties	Wed Mar 09 11:03:25 2011 +0000
+++ b/artifact-database/src/main/resources/sql/org-h2-driver.properties	Wed Mar 09 11:14:21 2011 +0000
@@ -105,8 +105,9 @@
     (SELECT id FROM collections WHERE owner_id = ?)
 
 collections.insert= \
-    INSERT INTO collections (id, gid, name, owner_id, creation, last_access, ttl) \
-    VALUES (?, ?, ?, ?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, ?)
+    INSERT INTO collections \
+    (id, gid, name, owner_id, creation, last_access, ttl, attribute) \
+    VALUES (?, ?, ?, ?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, ?, ?)
 
 collection.creation.time=SELECT creation from collections WHERE id = ?
 
--- a/artifact-database/src/main/resources/sql/org-postgresql-driver.properties	Wed Mar 09 11:03:25 2011 +0000
+++ b/artifact-database/src/main/resources/sql/org-postgresql-driver.properties	Wed Mar 09 11:14:21 2011 +0000
@@ -104,8 +104,9 @@
     (SELECT id FROM collections WHERE owner_id = ?)
 
 collections.insert= \
-    INSERT INTO collections (id, gid, name, owner_id, creation, last_access, ttl) \
-    VALUES (?, ?::uuid, ?, ?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, ?)
+    INSERT INTO collections \
+    (id, gid, name, owner_id, creation, last_access, ttl, attribute) \
+    VALUES (?, ?::uuid, ?, ?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, ?, ?)
 
 collection.creation.time=SELECT creation from collections WHERE id = ?
 

http://dive4elements.wald.intevation.org