jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1162835 - in /jackrabbit/sandbox/microkernel/src: main/java/org/apache/jackrabbit/mk/ main/java/org/apache/jackrabbit/mk/store/ test/java/org/apache/jackrabbit/mk/
Date Mon, 29 Aug 2011 14:34:40 GMT
Author: stefan
Date: Mon Aug 29 14:34:39 2011
New Revision: 1162835

URL: http://svn.apache.org/viewvc?rev=1162835&view=rev
Log:
some refactoring

Added:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/AbstractRevisionStore.java
Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelFactory.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Repository.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/H2RevisionStore.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/SimpleRevisionStore.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/ConcurrentWriteTest.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelFactory.java?rev=1162835&r1=1162834&r2=1162835&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelFactory.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelFactory.java
Mon Aug 29 14:34:39 2011
@@ -30,7 +30,7 @@ public class MicroKernelFactory {
      * Get an instance. Supported URLs:
      * <ul>
      * <li>mem: (in-memory implementation)</li>
-     * <li>fs:target/test (using the directory ./target/mk-test)</li>
+     * <li>fs:target/mk-test (using the directory ./target/mk-test)</li>
      * <li>fs:target/mk-test;clean (same, but delete the old repository first)</li>
      * <li>fs:{homeDir} (use the system property homeDir or '.' if not set)</li>
      * </ul>
@@ -56,7 +56,7 @@ public class MicroKernelFactory {
             String dir = url.substring("fs:".length());
             dir = dir.replaceAll("\\{homeDir\\}", System.getProperty("homeDir", "."));
             if (clean) {
-                new File(dir, ".mk/db/revs.h2.db").delete();
+                rm(new File(dir, ".mk"));
             }
             return new MicroKernelImpl(dir);
         } else {
@@ -64,4 +64,15 @@ public class MicroKernelFactory {
         }
     }
 
+    static boolean rm(File f) {
+        if (f.isDirectory()) {
+            for (String child : f.list()) {
+                if (! rm(new File(f, child))) {
+                    return false;
+                }
+            }
+        }
+
+        return f.delete();
+    }
 }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java?rev=1162835&r1=1162834&r2=1162835&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
Mon Aug 29 14:34:39 2011
@@ -48,8 +48,8 @@ public class MicroKernelImpl implements 
     }
 
     protected void init(String homeDir) throws MicroKernelException {
-        rep = new Repository(homeDir);
         try {
+            rep = new Repository(homeDir);
             rep.init();
         } catch (Exception e) {
             throw new MicroKernelException(e);

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Repository.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Repository.java?rev=1162835&r1=1162834&r2=1162835&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Repository.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/Repository.java
Mon Aug 29 14:34:39 2011
@@ -24,6 +24,7 @@ import org.apache.jackrabbit.mk.store.H2
 import org.apache.jackrabbit.mk.store.Node;
 import org.apache.jackrabbit.mk.store.PersistenceManager;
 import org.apache.jackrabbit.mk.store.RevisionStore;
+import org.apache.jackrabbit.mk.store.SimpleRevisionStore;
 import org.apache.jackrabbit.mk.util.PathUtils;
 
 import java.io.File;
@@ -38,8 +39,12 @@ public class Repository {
 
     final PersistenceManager pm;
 
-    public Repository(String homeDir) {
-        this.homeDir = homeDir == null ? "." : homeDir;
+    public Repository(String homeDir) throws Exception {
+        File home = new File(homeDir == null ? "." : homeDir, ".mk");
+        if (!home.exists()) {
+            home.mkdirs();
+        }
+        this.homeDir = home.getCanonicalPath();
         pm = new PersistenceManager();
         initialized = false;
     }

Added: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/AbstractRevisionStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/AbstractRevisionStore.java?rev=1162835&view=auto
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/AbstractRevisionStore.java
(added)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/AbstractRevisionStore.java
Mon Aug 29 14:34:39 2011
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.mk.store;
+
+import org.apache.jackrabbit.mk.util.StringUtils;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.security.DigestOutputStream;
+import java.security.MessageDigest;
+
+/**
+ *
+ */
+abstract class AbstractRevisionStore implements RevisionStore {
+
+    private boolean initialized;
+    private PersistentId headRev;
+
+    public AbstractRevisionStore() throws Exception {
+        initialized = false;
+    }
+
+    public void initialize(File homeDir) throws Exception {
+        if (initialized) {
+            throw new IllegalStateException("already initialized");
+        }
+
+        headRev = new PersistentId(new File(homeDir, "HEAD"));
+
+        initialized = true;
+    }
+
+    public void close() {
+        if (!initialized) {
+            throw new IllegalStateException("not initialized");
+        }
+
+        initialized = false;
+    }
+
+    public String getHeadId() throws Exception {
+        if (!initialized) {
+            throw new IllegalStateException("not initialized");
+        }
+
+        return headRev.get();
+    }
+
+    public void setHeadId(String revId) throws Exception {
+        if (!initialized) {
+            throw new IllegalStateException("not initialized");
+        }
+
+        headRev.set(revId);
+    }
+
+    public String computeId(InputStream in) throws Exception {
+        MessageDigest digest = MessageDigest.getInstance("SHA-1");
+        int read;
+        byte[] buf = new byte[8192];
+        try {
+            while ((read = in.read(buf, 0, buf.length)) != -1) {
+                digest.update(buf, 0, read);
+            }
+        } finally {
+            in.close();
+        }
+        return StringUtils.convertBytesToHex(digest.digest());
+    }
+}

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=1162835&r1=1162834&r2=1162835&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
Mon Aug 29 14:34:39 2011
@@ -26,17 +26,22 @@ import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.PrintStream;
+import java.io.Writer;
 import java.security.DigestOutputStream;
 import java.security.MessageDigest;
 import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
+import java.sql.SQLException;
 import java.sql.Statement;
 
 /**
  *
  */
-public class H2RevisionStore extends SimpleRevisionStore implements BlobStore {
+public class H2RevisionStore extends AbstractRevisionStore implements BlobStore {
+
+    private boolean initialized;
 
     private JdbcConnectionPool cp;
     private DbBlobStore blobStore;
@@ -50,17 +55,15 @@ public class H2RevisionStore extends Sim
             throw new IllegalStateException("already initialized");
         }
 
-        homeDir = new File(homeDir, ".mk");
-        if (!homeDir.exists()) {
-            homeDir.mkdirs();
-        }
-        dataDir = new File(homeDir, "db");
-        if (!dataDir.exists()) {
-            dataDir.mkdir();
+        super.initialize(homeDir);
+
+        File dbDir = new File(homeDir, "db");
+        if (!dbDir.exists()) {
+            dbDir.mkdir();
         }
 
         Class.forName("org.h2.Driver");
-        cp = JdbcConnectionPool.create("jdbc:h2:" + dataDir.getCanonicalPath() + "/revs",
"sa", "");
+        cp = JdbcConnectionPool.create("jdbc:h2:" + dbDir.getCanonicalPath() + "/revs", "sa",
"");
         cp.setMaxConnections(40);
         Connection con = cp.getConnection();
         try {
@@ -73,6 +76,7 @@ public class H2RevisionStore extends Sim
         } finally {
             con.close();
         }
+
         initialized = true;
     }
 

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/SimpleRevisionStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/SimpleRevisionStore.java?rev=1162835&r1=1162834&r2=1162835&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/SimpleRevisionStore.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/SimpleRevisionStore.java
Mon Aug 29 14:34:39 2011
@@ -30,11 +30,10 @@ import java.security.MessageDigest;
 /**
  *
  */
-public class SimpleRevisionStore implements RevisionStore {
+public class SimpleRevisionStore extends AbstractRevisionStore {
 
-    boolean initialized;
-    File dataDir;
-    PersistentId headRev;
+    private boolean initialized;
+    private File dataDir;
 
     public SimpleRevisionStore() throws Exception {
         initialized = false;
@@ -45,11 +44,8 @@ public class SimpleRevisionStore impleme
             throw new IllegalStateException("already initialized");
         }
 
-        homeDir = new File(homeDir, ".mk");
-        if (!homeDir.exists()) {
-            homeDir.mkdirs();
-        }
-        headRev = new PersistentId(new File(homeDir, "HEAD"));
+        super.initialize(homeDir);
+
         dataDir = new File(homeDir, "data");
         if (!dataDir.exists()) {
             dataDir.mkdir();
@@ -66,22 +62,6 @@ public class SimpleRevisionStore impleme
         initialized = false;
     }
 
-    public String getHeadId() throws Exception {
-        if (!initialized) {
-            throw new IllegalStateException("not initialized");
-        }
-
-        return headRev.get();
-    }
-
-    public void setHeadId(String revId) throws Exception {
-        if (!initialized) {
-            throw new IllegalStateException("not initialized");
-        }
-
-        headRev.set(revId);
-    }
-
     public InputStream get(String id) throws Exception {
         if (!initialized) {
             throw new IllegalStateException("not initialized");
@@ -140,24 +120,6 @@ public class SimpleRevisionStore impleme
         }
     }
 
-    public String computeId(InputStream in) throws Exception {
-        if (!initialized) {
-            throw new IllegalStateException("not initialized");
-        }
-
-        MessageDigest digest = MessageDigest.getInstance("SHA-1");
-        int read;
-        byte[] buf = new byte[8192];
-        try {
-            while ((read = in.read(buf, 0, buf.length)) != -1) {
-                digest.update(buf, 0, read);
-            }
-        } finally {
-            in.close();
-        }
-        return StringUtils.convertBytesToHex(digest.digest());
-    }
-
     private File getFile(String id) {
         StringBuilder buf = new StringBuilder(id.substring(0, 2));
         buf.append('/');

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/ConcurrentWriteTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/ConcurrentWriteTest.java?rev=1162835&r1=1162834&r2=1162835&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/ConcurrentWriteTest.java
(original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/ConcurrentWriteTest.java
Mon Aug 29 14:34:39 2011
@@ -25,7 +25,8 @@ public class ConcurrentWriteTest extends
 
     protected static final String TEST_PATH = "/" + ConcurrentWriteTest.class.getName();
 
-    private static final String URL = "fs:{homeDir}/target;clean";
+    //private static final String URL = "fs:{homeDir}/target;clean";
+    private static final String URL = "fs:{homeDir}/target";
     //private static final String URL = "mem:";
 
     private static final int NUM_THREADS = 20;
@@ -39,7 +40,8 @@ public class ConcurrentWriteTest extends
     }
 
     public void tearDown() throws InterruptedException {
-        mk.commit("/", "- \"" + TEST_PATH.substring(1) + "\"", mk.getHeadRevision(), null);
+        String head = mk.commit("/", "- \"" + TEST_PATH.substring(1) + "\"", mk.getHeadRevision(),
null);
+        System.out.println("new HEAD: " + head);
         mk.dispose();
     }
 
@@ -91,7 +93,6 @@ public class ConcurrentWriteTest extends
         // System.out.println();
 
         // System.out.println(prof.getTop(5));
-
     }
 
     class TestThread extends Thread {



Mime
View raw message