jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1129525 - /jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/H2RevisionStore.java
Date Tue, 31 May 2011 07:43:39 GMT
Author: thomasm
Date: Tue May 31 07:43:38 2011
New Revision: 1129525

URL: http://svn.apache.org/viewvc?rev=1129525&view=rev
Log:
Slightly improved performance.

Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/H2RevisionStore.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/H2RevisionStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/H2RevisionStore.java?rev=1129525&r1=1129524&r2=1129525&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/H2RevisionStore.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/H2RevisionStore.java
Tue May 31 07:43:38 2011
@@ -16,8 +16,8 @@
  */
 package org.apache.jackrabbit.mk.store;
 
+import org.apache.jackrabbit.mk.util.StringUtils;
 import org.h2.jdbcx.JdbcConnectionPool;
-
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
@@ -57,6 +57,7 @@ public class H2RevisionStore extends Sim
 
         Class.forName("org.h2.Driver");
         cp = JdbcConnectionPool.create("jdbc:h2:" + dataDir.getCanonicalPath() + "/revs",
"sa", "");
+        cp.setMaxConnections(40);
         Connection con = cp.getConnection();
         try {
             ResultSet rs = con.getMetaData().getTables(null, null, "REVS", null);
@@ -90,12 +91,16 @@ public class H2RevisionStore extends Sim
         Connection con = cp.getConnection();
         try {
             PreparedStatement stmt = con.prepareStatement("select DATA from REVS where ID
= ?");
-            stmt.setBytes(1, hexToRaw(id));
-            ResultSet rs = stmt.executeQuery();
-            if (rs.next()) {
-                return new ByteArrayInputStream(rs.getBytes(1));
-            } else {
-                throw new Exception("not found: " + id);
+            try {
+                stmt.setBytes(1, StringUtils.convertHexToBytes(id));
+                ResultSet rs = stmt.executeQuery();
+                if (rs.next()) {
+                    return new ByteArrayInputStream(rs.getBytes(1));
+                } else {
+                    throw new Exception("not found: " + id);
+                }
+            } finally {
+                stmt.close();
             }
         } finally {
             con.close();
@@ -124,32 +129,23 @@ public class H2RevisionStore extends Sim
         }
 
         byte[] rawId = digest.digest();
-        String id = toHex(rawId);
+        String id = StringUtils.convertBytesToHex(rawId);
         Connection con = cp.getConnection();
         try {
             PreparedStatement stmt = con.prepareStatement(
                     "insert into REVS (ID, DATA) select ?, ? where not exists (select 1 from
revs where ID = ?)");
-            stmt.setBytes(1, rawId);
-            stmt.setBytes(2, baos.toByteArray());
-            stmt.setBytes(3, rawId);
-            stmt.executeUpdate();
+            try {
+                stmt.setBytes(1, rawId);
+                stmt.setBytes(2, baos.toByteArray());
+                stmt.setBytes(3, rawId);
+                stmt.executeUpdate();
+            } finally {
+                stmt.close();
+            }
         } finally {
             con.close();
         }
         return id;
     }
 
-    static byte[] hexToRaw(String hex) {
-        char[] chars = hex.toCharArray();
-        int len = chars.length;
-
-        byte[] raw = new byte[len / 2];
-        for (int i = 0; i < raw.length; i++) {
-            int n = Character.digit(chars[i * 2], 16) << 4;
-            n = n | Character.digit(chars[(i * 2) + 1], 16);
-            raw[i] = (byte) (n & 0xFF);
-        }
-
-        return raw;
-    }
 }



Mime
View raw message