jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1239723 - in /jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store: AbstractPersistenceManager.java MongoPersistenceManager.java PersistHook.java
Date Thu, 02 Feb 2012 17:03:43 GMT
Author: stefan
Date: Thu Feb  2 17:03:42 2012
New Revision: 1239723

URL: http://svn.apache.org/viewvc?rev=1239723&view=rev
Log:
refactoring persistence logic & cleanup

Added:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/PersistHook.java
Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/AbstractPersistenceManager.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MongoPersistenceManager.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/AbstractPersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/AbstractPersistenceManager.java?rev=1239723&r1=1239722&r2=1239723&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/AbstractPersistenceManager.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/AbstractPersistenceManager.java
Thu Feb  2 17:03:42 2012
@@ -124,7 +124,18 @@ public abstract class AbstractPersistenc
     public String putNode(Node node) throws Exception {
         verifyInitialized();
 
+        PersistHook callback = null;
+        if (node instanceof PersistHook) {
+            callback = (PersistHook) node;
+            callback.prePersist(this);
+        }
+
         String id = writeNode(node);
+        
+        if (callback != null)  {
+            callback.postPersist(this);
+        }
+        
         cache.put(id, new StoredNode(id, node));
 
         return id;
@@ -133,9 +144,20 @@ public abstract class AbstractPersistenc
     public String putCNEBucket(ChildNodeEntriesBucket bucket) throws Exception {
         verifyInitialized();
 
-        String id = writeCNEBucket(bucket);
-        // todo fixme
-        //cache.put(id, new ChildNodeEntriesBucket(id, bucket));
+        PersistHook callback = null;
+        if (bucket instanceof PersistHook) {
+            callback = (PersistHook) bucket;
+            callback.prePersist(this);
+        }
+
+       String id = writeCNEBucket(bucket);
+
+        if (callback != null)  {
+            callback.postPersist(this);
+        }
+
+        // todo is it correct to cache a clone?
+        cache.put(id, bucket.clone());
 
         return id;
     }
@@ -143,7 +165,18 @@ public abstract class AbstractPersistenc
     public String putCommit(Commit commit) throws Exception {
         verifyInitialized();
 
+        PersistHook callback = null;
+        if (commit instanceof PersistHook) {
+            callback = (PersistHook) commit;
+            callback.prePersist(this);
+        }
+
         String id = writeCommit(commit);
+
+        if (callback != null)  {
+            callback.postPersist(this);
+        }
+
         cache.put(id, new StoredCommit(id, commit));
 
         return id;

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MongoPersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MongoPersistenceManager.java?rev=1239723&r1=1239722&r2=1239723&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MongoPersistenceManager.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MongoPersistenceManager.java
Thu Feb  2 17:03:42 2012
@@ -20,13 +20,9 @@ import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.InputStream;
-import java.util.HashMap;
 import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.Map;
 
 import org.apache.jackrabbit.mk.model.ChildNodeEntriesBucket;
-import org.apache.jackrabbit.mk.model.ChildNodeEntry;
 import org.apache.jackrabbit.mk.model.Commit;
 import org.apache.jackrabbit.mk.model.Node;
 import org.apache.jackrabbit.mk.model.StoredCommit;
@@ -59,8 +55,6 @@ public class MongoPersistenceManager ext
     private static final String BUCKETS_COLLECTION = "buckets";
     private static final String ID_FIELD = ":id";
     private static final String DATA_FIELD = ":data";
-    private static final String PROPERTIES_OBJECT = ":props";
-    private static final String CHILDREN_OBJECT = ":children";
 
     private Mongo con;
     private DB db;
@@ -296,61 +290,9 @@ public class MongoPersistenceManager ext
 
     //-------------------------------------------------------< implementation >
 
-    protected static Map<String, String> encodeKeys(Map<String, String> map)
{
-        boolean needsEncoding = false;
-        for (String key : map.keySet()) {
-            if (needsEncoding = needsEncoding(key)) {
-                break;
-            }
-        }
-        if (!needsEncoding) {
-            return map;
-        }
-        Map<String, String> result;
-        if (map instanceof LinkedHashMap) {
-            result = new LinkedHashMap<String, String>(map.size());
-        } else {
-            result = new HashMap<String, String>(map.size());
-        }
-        for (Map.Entry<String, String> entry : map.entrySet()) {
-            result.put(encodeName(entry.getKey()), entry.getValue());
-        }
-        return result;
-    }
-
-    protected static Map<String, String> decodeKeys(Map<String, String> map)
{
-        boolean needsDecoding = false;
-        for (String key : map.keySet()) {
-            if (needsDecoding = needsDecoding(key)) {
-                break;
-            }
-        }
-        if (!needsDecoding) {
-            return map;
-        }
-        Map<String, String> result;
-        if (map instanceof LinkedHashMap) {
-            result = new LinkedHashMap<String, String>(map.size());
-        } else {
-            result = new HashMap<String, String>(map.size());
-        }
-        for (Map.Entry<String, String> entry : map.entrySet()) {
-            result.put(decodeName(entry.getKey()), entry.getValue());
-        }
-        return result;
-    }
-
     protected final static String ENCODED_DOT = "_x46_";
     protected final static String ENCODED_DOLLAR_SIGN = "_x36_";
 
-    protected static boolean needsEncoding(String name) {
-        return name.startsWith("$") || name.indexOf('.') != -1;
-    }
-
-    protected static boolean needsDecoding(String name) {
-        return name.startsWith(ENCODED_DOLLAR_SIGN) || name.indexOf(ENCODED_DOT) != -1;
-    }
-
     /**
      * see http://www.mongodb.org/display/DOCS/Legal+Key+Names
      *
@@ -389,7 +331,7 @@ public class MongoPersistenceManager ext
             lastPos = ENCODED_DOLLAR_SIGN.length();
         }
 
-        int pos = -1;
+        int pos;
         while ((pos = name.indexOf(ENCODED_DOT, lastPos)) != -1) {
             if (buf == null) {
                 buf = new StringBuilder();

Added: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/PersistHook.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/PersistHook.java?rev=1239723&view=auto
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/PersistHook.java
(added)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/PersistHook.java
Thu Feb  2 17:03:42 2012
@@ -0,0 +1,26 @@
+/*
+ * 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;
+
+/**
+ * 
+ */
+public interface PersistHook {
+    
+    void prePersist(RevisionStore store) throws Exception;
+    void postPersist(RevisionStore store) throws Exception;
+}



Mime
View raw message