jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1299278 - in /jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit: state/PersistentNodeState.java utils/Function0.java
Date Sat, 10 Mar 2012 21:44:04 GMT
Author: mduerig
Date: Sat Mar 10 21:44:04 2012
New Revision: 1299278

URL: http://svn.apache.org/viewvc?rev=1299278&view=rev
Log:
Microkernel based prototype of JCR implementation (WIP)
- memoize properties 

Added:
    jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/Function0.java
Modified:
    jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/PersistentNodeState.java

Modified: jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/PersistentNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/PersistentNodeState.java?rev=1299278&r1=1299277&r2=1299278&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/PersistentNodeState.java
(original)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/PersistentNodeState.java
Sat Mar 10 21:44:04 2012
@@ -15,14 +15,29 @@ import org.apache.jackrabbit.oak.model.P
 import org.apache.jackrabbit.spi.commons.iterator.Iterators;
 import org.apache.jackrabbit.spi.commons.iterator.Predicate;
 import org.apache.jackrabbit.spi.commons.iterator.Transformer;
+import org.apache.jackrabbit.utils.Function0;
 
 import java.util.Iterator;
 import java.util.Map.Entry;
+import java.util.Set;
 
 public class PersistentNodeState extends AbstractNodeState {
     private final MicroKernel microkernel;
     private final String revision;
     private final Path path;
+    
+    private final Function0<JsonObject> properties = new Function0<JsonObject>()
{
+        private JsonObject properties;
+        
+        @Override
+        public JsonObject apply() {
+            if (properties == null) {
+                String json = microkernel.getNodes(path.toMkPath(), revision, 0, 0, -1, null);
+                properties = FullJsonParser.parseObject(new UnescapingJsonTokenizer(json));
+            }
+            return properties;
+        }
+    };
 
     public PersistentNodeState(MicroKernel microkernel, String revision, Path path) {
         this.microkernel = microkernel;
@@ -32,24 +47,23 @@ public class PersistentNodeState extends
     
     @Override
     public PropertyState getProperty(String name) {
-        JsonObject jsonObject = getPropertiesAsJson();
-        return createPropertyState(name, jsonObject.get(name));
+        return createPropertyState(name, properties.apply().get(name));
     }
 
     @Override
     public Iterable<PropertyState> getProperties() {
         return new Iterable<PropertyState>() {
-            private final JsonObject jsonObject = getPropertiesAsJson();
+            private final Set<Entry<String, JsonValue>> props = properties.apply().value().entrySet();
 
             @Override
             public Iterator<PropertyState> iterator() {
-                return Iterators.transformIterator(jsonObject.value().entrySet().iterator(),

-                    new Transformer<Entry<String, JsonValue>, PropertyState>()
{
-                        @Override
-                        public PropertyState transform(Entry<String, JsonValue> entry)
{
-                            return createPropertyState(entry.getKey(), entry.getValue());
  
-                        }
-                });   
+                return Iterators.transformIterator(props.iterator(),
+                        new Transformer<Entry<String, JsonValue>, PropertyState>()
{
+                            @Override
+                            public PropertyState transform(Entry<String, JsonValue>
entry) {
+                                return createPropertyState(entry.getKey(), entry.getValue());
+                            }
+                        });
             }
         };
     }
@@ -66,8 +80,7 @@ public class PersistentNodeState extends
 
     @Override
     public long getChildNodeCount() {
-        JsonObject jsonObject = getPropertiesAsJson();
-        JsonValue count = jsonObject.get(":childNodeCount");
+        JsonValue count = properties.apply().get(":childNodeCount");
         long c = toLong(count);
         if (c < 0) {
             return super.getChildNodeCount();
@@ -109,11 +122,6 @@ public class PersistentNodeState extends
 
     //------------------------------------------< private >---
 
-    private JsonObject getPropertiesAsJson() {
-        String json = microkernel.getNodes(path.toMkPath(), revision, 0, 0, -1, null);
-        return FullJsonParser.parseObject(new UnescapingJsonTokenizer(json));
-    }
-
     private JsonObject getNodesAsJson(long offset, long length) {
         // fixme: microkernel should also use long for length
         String json = microkernel.getNodes(path.toMkPath(), revision, 1, offset, (int) length,
null);

Added: jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/Function0.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/Function0.java?rev=1299278&view=auto
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/Function0.java
(added)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/Function0.java
Sat Mar 10 21:44:04 2012
@@ -0,0 +1,5 @@
+package org.apache.jackrabbit.utils;
+
+public interface Function0<T> {
+    T apply();
+}



Mime
View raw message