changeset 235:3e29395ebac6

The XML documents stored aside users, collections and collection items are now compressed/decompressed transparently. artifacts/trunk@1642 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 04 Apr 2011 09:28:54 +0000
parents 23d642319a0b
children 6ef6acf30d66
files ChangeLog artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java
diffstat 2 files changed, 43 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sun Apr 03 12:10:54 2011 +0000
+++ b/ChangeLog	Mon Apr 04 09:28:54 2011 +0000
@@ -1,3 +1,13 @@
+2011-04-04	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java:
+	  The XML documents stored aside users, collections and collection items
+	  are now compressed/decompressed transparently, to reduce i/o costs
+	  as its already done with artifacts.
+	  
+	  !!! This breaks database content of release FLYS 2.2 but this is okay,
+	  !!! because 2.2 is not productive..
+
 2011-04-03	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* artifacts-common/src/main/java/de/intevation/artifacts/common/utils/XMLUtils.java:
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java	Sun Apr 03 12:10:54 2011 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java	Mon Apr 04 09:28:54 2011 +0000
@@ -24,6 +24,7 @@
 
 import java.util.ArrayList;
 import java.util.Date;
+import java.util.HashMap;
 
 import org.apache.log4j.Logger;
 
@@ -769,6 +770,8 @@
     ) {
         final User [] user = new User[1];
 
+        final byte [] roleData = XMLUtils.toByteArray(role, true);
+
         SQLExecutor exec = new SQLExecutor() {
             public boolean doIt() throws SQLException {
 
@@ -791,10 +794,6 @@
                 stmnt.setString(2, identifier);
                 stmnt.setString(3, name);
 
-                byte [] roleData = role == null
-                    ? null
-                    : XMLUtils.toByteArray(role);
-
                 if (roleData == null) {
                     stmnt.setNull(4, Types.BIGINT);
                 }
@@ -898,7 +897,7 @@
                 String  name     = result.getString(2);
                 byte [] roleData = result.getBytes(3);
 
-                Document role = XMLUtils.fromByteArray(roleData);
+                Document role = XMLUtils.fromByteArray(roleData, true);
 
                 user[0] = factory.createUser(
                     identifier, name, role, context);
@@ -926,7 +925,7 @@
                     String  name       = result.getString(3);
                     byte [] roleData   = result.getBytes(4);
 
-                    Document role = XMLUtils.fromByteArray(roleData);
+                    Document role = XMLUtils.fromByteArray(roleData, true);
                     User user = factory.createUser(
                         identifier, name, role, context);
                     users.add(user);
@@ -957,8 +956,9 @@
             return null;
         }
 
-        final ArtifactCollection [] collection =
-            new ArtifactCollection[1];
+        final ArtifactCollection [] collection = new ArtifactCollection[1];
+
+        final byte [] data = XMLUtils.toByteArray(attribute, true);
 
         SQLExecutor exec = new SQLExecutor() {
             public boolean doIt() throws SQLException {
@@ -1004,8 +1004,6 @@
                     stmnt.setLong(5, ttl);
                 }
 
-                byte [] data = XMLUtils.toByteArray(attribute);
-
                 if (data == null) {
                     stmnt.setNull(6, Types.BINARY);
                 }
@@ -1069,14 +1067,14 @@
                     return false;
                 }
 
-                String collectionName       = result.getString(2);
-                String ownerId              = result.getString(3);
-                Date   creationTime         =
+                String collectionName = result.getString(2);
+                String ownerId        = result.getString(3);
+                Date   creationTime   =
                     new Date(result.getTimestamp(4).getTime());
-                Date   lastAccess           =
+                Date   lastAccess     =
                     new Date(result.getTimestamp(5).getTime());
-                Document attr               =
-                    XMLUtils.fromByteArray(result.getBytes(6));
+                Document attr         =
+                    XMLUtils.fromByteArray(result.getBytes(6), true);
 
                 ArtifactCollection collection =
                     collectionFactory.createCollection(
@@ -1130,6 +1128,9 @@
 
                 result = stmnt.executeQuery();
 
+                HashMap<String, LazyBackendUser> users =
+                    new HashMap<String, LazyBackendUser>();
+
                 while (result.next()) {
                     String collectionIdentifier = result.getString(1);
                     String collectionName       = result.getString(2);
@@ -1146,8 +1147,14 @@
                             context);
 
                     if (userIdentifier != null) {
-                        collection.setUser(new LazyBackendUser(
-                            userIdentifier, userFactory, Backend.this, context));
+                        LazyBackendUser user = users.get(userIdentifier);
+                        if (user == null) {
+                            user = new LazyBackendUser(
+                                userIdentifier, userFactory,
+                                Backend.this, context);
+                            users.put(userIdentifier, user);
+                        }
+                        collection.setUser(user);
                     }
 
                     collections.add(collection);
@@ -1217,7 +1224,7 @@
             return null;
         }
 
-        final Document [] document = new Document[1];
+        final byte [][] data = new byte[1][1];
 
         SQLExecutor exec = new SQLExecutor() {
             public boolean doIt() throws SQLException {
@@ -1229,12 +1236,14 @@
                     logger.debug("No such collection item");
                     return false;
                 }
-                document[0] = XMLUtils.fromByteArray(result.getBytes(1));
+                data[0] = result.getBytes(1);
                 return true;
             }
         };
 
-        return exec.runRead() ? document[0] : null;
+        return exec.runRead()
+            ? XMLUtils.fromByteArray(data[0], true)
+            : null;
     }
 
     public boolean setCollectionAttribute(
@@ -1251,7 +1260,7 @@
             return false;
         }
 
-        final byte [] data = XMLUtils.toByteArray(attribute);
+        final byte [] data = XMLUtils.toByteArray(attribute, true);
 
         return new SQLExecutor() {
             public boolean doIt() throws SQLException {
@@ -1295,6 +1304,8 @@
             return false;
         }
 
+        final byte [] data = XMLUtils.toByteArray(attribute, true);
+
         SQLExecutor exec = new SQLExecutor() {
             public boolean doIt() throws SQLException {
                 // fetch artifact id
@@ -1345,8 +1356,6 @@
                 stmnt.setInt(2, cid);
                 stmnt.setInt(3, aid);
 
-                byte [] data = XMLUtils.toByteArray(attribute);
-
                 if (data == null) {
                     stmnt.setNull(4, Types.BINARY);
                 }

http://dive4elements.wald.intevation.org