jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1304491 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/state/ oak-jcr/src/main/java/org/apache/j...
Date Fri, 23 Mar 2012 17:12:00 GMT
Author: mduerig
Date: Fri Mar 23 17:12:00 2012
New Revision: 1304491

URL: http://svn.apache.org/viewvc?rev=1304491&view=rev
Log:
OAK-15: Clean up oak-jcr
Use Scalar instead of JsonValue (WIP)

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelPropertyState.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/state/ChangeLog.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/state/ChangeTree.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/state/TransientNodeState.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/state/TransientSpace.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/util/ValueConverter.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelPropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelPropertyState.java?rev=1304491&r1=1304490&r2=1304491&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelPropertyState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelPropertyState.java
Fri Mar 23 17:12:00 2012
@@ -18,6 +18,7 @@
  */
 package org.apache.jackrabbit.oak.kernel;
 
+import org.apache.jackrabbit.mk.json.JsonBuilder;
 import org.apache.jackrabbit.mk.model.AbstractPropertyState;
 import org.apache.jackrabbit.oak.api.Scalar;
 
@@ -65,7 +66,7 @@ public class KernelPropertyState extends
         }
     }
 
-    public boolean isMultiValues() {
+    public boolean isMultiValued() {
         return value == null;
     }
     
@@ -81,7 +82,7 @@ public class KernelPropertyState extends
     
     private static String encodeValue(Scalar value) {
         if (value.getType() == Scalar.STRING) {
-            return '"' + value.getString() + '"';
+            return '"' + JsonBuilder.escape(value.getString()) + '"';
         }
         else {
             return value.getString();

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java?rev=1304491&r1=1304490&r2=1304491&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
Fri Mar 23 17:12:00 2012
@@ -17,11 +17,10 @@
 package org.apache.jackrabbit.oak.jcr;
 
 import org.apache.jackrabbit.JcrConstants;
+import org.apache.jackrabbit.ScalarImpl;
 import org.apache.jackrabbit.commons.iterator.NodeIteratorAdapter;
 import org.apache.jackrabbit.commons.iterator.PropertyIteratorAdapter;
 import org.apache.jackrabbit.mk.model.PropertyState;
-import org.apache.jackrabbit.oak.jcr.json.JsonValue;
-import org.apache.jackrabbit.oak.jcr.json.JsonValue.JsonAtom;
 import org.apache.jackrabbit.oak.jcr.state.TransientNodeState;
 import org.apache.jackrabbit.oak.jcr.util.Function1;
 import org.apache.jackrabbit.oak.jcr.util.ItemNameMatcher;
@@ -232,7 +231,7 @@ public class NodeImpl extends ItemImpl i
     public Property setProperty(String name, Value value, int type) throws RepositoryException
{
         checkStatus();
 
-        state.setProperty(name, ValueConverter.toJsonValue(value));
+        state.setProperty(name, ValueConverter.toScalar(value));
         return getProperty(name);
     }
 
@@ -254,7 +253,7 @@ public class NodeImpl extends ItemImpl i
     public Property setProperty(String name, Value[] values, int type) throws RepositoryException
{
         checkStatus();
 
-        state.setProperty(name, ValueConverter.toJsonValue(values));
+        state.setProperty(name, ValueConverter.toScalar(values));
         return getProperty(name);
     }
 
@@ -589,25 +588,21 @@ public class NodeImpl extends ItemImpl i
     public void setPrimaryType(String nodeTypeName) throws RepositoryException {
         checkStatus();
 
-        state.setProperty(JcrConstants.JCR_PRIMARYTYPE, JsonAtom.string(nodeTypeName));
+        state.setProperty(JcrConstants.JCR_PRIMARYTYPE, ScalarImpl.stringScalar(nodeTypeName));
     }
 
     @Override
     public void addMixin(String mixinName) throws RepositoryException {
         checkStatus();
 
-        JsonValue mixins = state.getPropertyValue(JcrConstants.JCR_MIXINTYPES);
-        mixins.asArray().add(JsonAtom.string(mixinName));
-        state.setProperty(JcrConstants.JCR_MIXINTYPES, mixins);
+        // todo implement addMixin
     }
 
     @Override
     public void removeMixin(String mixinName) throws RepositoryException {
         checkStatus();
 
-        JsonValue mixins = state.getPropertyValue(JcrConstants.JCR_MIXINTYPES);
-        mixins.asArray().remove(JsonAtom.string(mixinName));
-        state.setProperty(JcrConstants.JCR_MIXINTYPES, mixins);
+        // todo implement removeMixin
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java?rev=1304491&r1=1304490&r2=1304491&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java
Fri Mar 23 17:12:00 2012
@@ -543,7 +543,7 @@ public class PropertyImpl extends ItemIm
      */
     @Override
     public boolean isMultiple() throws RepositoryException {
-        return ((KernelPropertyState) state).isMultiValues();  // fixme don't cast
+        return ((KernelPropertyState) state).isMultiValued();  // fixme don't cast
     }
 
     //------------------------------------------------------------< private >---
@@ -583,7 +583,7 @@ public class PropertyImpl extends ItemIm
             remove();
         }
         else {
-            parentState.setProperty(state.getName(), ValueConverter.toJsonValue(value));
+            parentState.setProperty(state.getName(), ValueConverter.toScalar(value));
         }
     }
 
@@ -603,7 +603,7 @@ public class PropertyImpl extends ItemIm
             remove();
         }
         else {
-            parentState.setProperty(state.getName(), ValueConverter.toJsonValue(values));
+            parentState.setProperty(state.getName(), ValueConverter.toScalar(values));
         }
     }
 

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/state/ChangeLog.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/state/ChangeLog.java?rev=1304491&r1=1304490&r2=1304491&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/state/ChangeLog.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/state/ChangeLog.java
Fri Mar 23 17:12:00 2012
@@ -19,9 +19,10 @@
 
 package org.apache.jackrabbit.oak.jcr.state;
 
-import org.apache.jackrabbit.oak.jcr.json.JsonValue;
-import org.apache.jackrabbit.oak.jcr.json.JsonValue.JsonAtom;
+import org.apache.jackrabbit.ScalarImpl;
+import org.apache.jackrabbit.mk.model.PropertyState;
 import org.apache.jackrabbit.oak.jcr.util.Path;
+import org.apache.jackrabbit.oak.kernel.KernelPropertyState;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -79,14 +80,10 @@ public class ChangeLog {
     /**
      * Add a set property operation to this change log
      * @param parent  parent of the property
-     * @param name  name of the property
-     * @param value  value of the property
+     * @param state  state of the property
      */
-    public void setProperty(Path parent, String name, JsonValue value) {
-        if (value == null) {
-            value = JsonAtom.NULL;
-        }
-        addOperation(Operation.setProperty(parent, name, value));
+    public void setProperty(Path parent, PropertyState state) {
+        addOperation(Operation.setProperty(parent, state.getName(), state));
     }
 
     /**
@@ -95,7 +92,7 @@ public class ChangeLog {
      * @param name  name of the property
      */
     public void removeProperty(Path parent, String name) {
-        setProperty(parent, name, JsonAtom.NULL);
+        setProperty(parent, new KernelPropertyState(name, ScalarImpl.nullScalar()));
     }
 
     private void addOperation(Operation operation) {
@@ -290,24 +287,25 @@ public class ChangeLog {
      * The underlying abstraction models operations as a moves: remove
      * node is represented as move to {@code NIL} and add node and add
      * property are represented as move from {@code NIL}. Add property
-     * operations carry a value and the property names is disambiguated
-     * (leading star) in order to avoid conflicts with node names.
+     * operations carry the property state and the property names is
+     * disambiguated (leading star) in order to avoid conflicts with node
+     * names.
      */
     static final class Operation {
         public static final Operation ID = new Operation(NIL, NIL, null);
 
         private final Path from;
         private final Path to;
-        private final JsonValue value;
+        private final PropertyState state;
 
-        private Operation(Path from, Path to, JsonValue value) {
+        private Operation(Path from, Path to, PropertyState state) {
             if (from == null || to == null) {
                 throw new IllegalArgumentException("path is null");
             }
 
             this.from = from;
             this.to = to;
-            this.value = value;
+            this.state = state;
         }
 
         /**
@@ -355,11 +353,11 @@ public class ChangeLog {
          * Create a new set property operation.
          * @param parent  parent of the property
          * @param name  name of the property
-         * @param value  value of the property
+         * @param state  state of the property
          * @return  new set property operation
          */
-        public static Operation setProperty(Path parent, String name, JsonValue value) {
-            return new Operation(NIL, encodeProperty(parent, name), value);
+        public static Operation setProperty(Path parent, String name, PropertyState state)
{
+            return new Operation(NIL, encodeProperty(parent, name), state);
         }
 
         /**
@@ -370,7 +368,7 @@ public class ChangeLog {
          * in both {@code from} and {@code to} of this operation.
          */
         public Operation move(Path source, Path target) {
-            return new Operation(subst(source, target, from), subst(source, target, to),
value);
+            return new Operation(subst(source, target, from), subst(source, target, to),
state);
         }
 
         /**
@@ -380,8 +378,8 @@ public class ChangeLog {
             if (from == NIL && to == NIL) {
                 return "";
             }
-            else if (value != null) {
-                return "^\"" + decodeProperty(to).toMkPath() + "\":" + value.toJson();
+            else if (state != null) {
+                return "^\"" + decodeProperty(to).toMkPath() + "\":" + state.getEncodedValue();
             }
             else if (from == NIL) {
                 return "+\"" + to.toMkPath() + "\":{}";
@@ -405,13 +403,13 @@ public class ChangeLog {
 
             Operation that = (Operation) other;
             return from.equals(that.from) && to.equals(that.to)
-                    && value == null ? that.value == null : value.equals(that.value);
+                    && state == null ? that.state == null : state.equals(that.state);
 
         }
 
         @Override
         public int hashCode() {
-            return 31 * (31 * from.hashCode() + to.hashCode()) + (value == null ? 0 : value.hashCode());
+            return 31 * (31 * from.hashCode() + to.hashCode()) + (state == null ? 0 : state.hashCode());
         }
 
         @Override
@@ -419,8 +417,8 @@ public class ChangeLog {
             if (from == NIL && to == NIL) {
                 return "ID";
             }
-            else if (value != null) {
-                return '^' + decodeProperty(to).toMkPath() + ':' + value.toJson();
+            else if (state != null) {
+                return '^' + decodeProperty(to).toMkPath() + ':' + state.getEncodedValue();
             }
             else if (from == NIL) {
                 return '+' + to.toMkPath() + ":{}";
@@ -440,6 +438,7 @@ public class ChangeLog {
         private static Path decodeProperty(Path path) {
             return path.getParent().concat(path.getName().substring(1));
         }
+
     }
 
     /**
@@ -579,7 +578,7 @@ public class ChangeLog {
             ops.remove(index);
             return index;
         }
-        else if (m.value != null && n.value != null && m.to.equals(n.to))
{
+        else if (m.state != null && n.state != null && m.to.equals(n.to))
{
             // set property absorption: ^a:x * ^a:y = ^a:y
             ops.remove(index);
             return index;

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/state/ChangeTree.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/state/ChangeTree.java?rev=1304491&r1=1304490&r2=1304491&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/state/ChangeTree.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/state/ChangeTree.java
Fri Mar 23 17:12:00 2012
@@ -21,21 +21,21 @@ package org.apache.jackrabbit.oak.jcr.st
 
 import org.apache.commons.collections.map.AbstractReferenceMap;
 import org.apache.commons.collections.map.ReferenceMap;
+import org.apache.jackrabbit.ScalarImpl;
 import org.apache.jackrabbit.mk.model.PropertyState;
-import org.apache.jackrabbit.oak.jcr.json.JsonValue;
-import org.apache.jackrabbit.oak.jcr.json.JsonValue.JsonAtom;
-import org.apache.jackrabbit.oak.jcr.util.Function1;
+import org.apache.jackrabbit.oak.api.Scalar;
 import org.apache.jackrabbit.oak.jcr.util.Iterators;
 import org.apache.jackrabbit.oak.jcr.util.Path;
 import org.apache.jackrabbit.oak.jcr.util.Predicate;
+import org.apache.jackrabbit.oak.kernel.KernelPropertyState;
 
 import javax.jcr.ItemExistsException;
 import javax.jcr.ItemNotFoundException;
 import javax.jcr.PathNotFoundException;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
-import java.util.Map.Entry;
 
 import static org.apache.jackrabbit.oak.jcr.util.Unchecked.cast;
 
@@ -67,7 +67,8 @@ public class ChangeTree {
         void added(NodeDelta nodeDelta);
         void removed(NodeDelta nodeDelta);
         void moved(Path source, NodeDelta nodeDelta);
-        void setValue(NodeDelta parent, String name, JsonValue value);
+        void setProperty(NodeDelta parent, PropertyState state);
+        void removeProperty(NodeDelta parent, String name);
     }
 
     /**
@@ -136,7 +137,7 @@ public class ChangeTree {
      */
     public abstract class NodeDelta {
         private final Map<String, NodeDelta> childNodes = new HashMap<String, NodeDelta>();
-        private final Map<String, JsonValue> properties = new HashMap<String, JsonValue>();
+        private final Map<String, PropertyState> properties = new HashMap<String,
PropertyState>();
         protected NodeDelta parent;
         protected String name;
 
@@ -248,31 +249,22 @@ public class ChangeTree {
 
         /**
          * @param name
-         * @return  the value of the property with the given {@code name}, JSON {@code null}
if the
-         * property has been removed or {@code null} if if does not exist.
+         * @return  the state of the property with the given {@code name} or
+         * {@code null} if if does not exist.
          */
-        public JsonValue getPropertyValue(String name) {
+        public PropertyState getPropertyState(String name) {
             return properties.get(name);
         }
 
         /**
-         * @return  an iterator for all added and modified properties.
+         * @return  an iterator for all added and modified property states.
          */
         public Iterator<PropertyState> getPropertyStates() {
-            Iterator<Entry<String, JsonValue>> entries =
-                Iterators.filter(properties.entrySet().iterator(),
-                        new Predicate<Entry<String, JsonValue>>() {
-                            @Override
-                            public boolean evaluate(Entry<String, JsonValue> entry)
{
-                                return entry.getValue() != JsonAtom.NULL;
-                            }
-                        });
-
-            return Iterators.map(entries,
-                    new Function1<Entry<String, JsonValue>, PropertyState>()
{
+            return Iterators.filter(properties.values().iterator(),
+                    new Predicate<PropertyState>() {
                         @Override
-                        public PropertyState apply(final Entry<String, JsonValue> entry)
{
-                            return TransientNodeState.createPropertyState(entry.getKey(),
entry.getValue());
+                        public boolean evaluate(PropertyState state) {
+                            return !((KernelPropertyState) state).getValue().equals(ScalarImpl.nullScalar());
 // fixme don't cast
                         }
                     });
         }
@@ -342,23 +334,39 @@ public class ChangeTree {
 
         /**
          * Set the property with the given {@code name} to {@code value} or remove the
-         * property if {@code value} is {@code null} or JSON {@code null}.
+         * property if {@code value} is {@code null}.
          * @param name
          * @param value
          */
-        public void setValue(String name, JsonValue value) {
+        public void setValue(String name, Scalar value) {
             if (value == null) {
-                value = JsonAtom.NULL;
+                value = ScalarImpl.nullScalar();
             }
-            
-            if (value.isNull() && properties.containsKey(name) && properties.get(name)
!= JsonAtom.NULL) {
+
+            if (value.equals(ScalarImpl.nullScalar()) && properties.containsKey(name)
&&
+                    !properties.get(name).equals(ScalarImpl.nullScalar())) {
+
                 properties.remove(name);
+                notifyRemoveProperty(this, name);
             }
             else {
-                properties.put(name, value);
+                KernelPropertyState state = new KernelPropertyState(name, value);
+                properties.put(name, state);
                 touch();
+                notifySetProperty(this, state);
             }
-            notifySetValue(this, name, value);
+        }
+
+        /**
+         * Set the property with the given {@code name} to {@code values}.
+         * @param name
+         * @param values
+         */
+        public void setValue(String name, List<Scalar> values) {
+            KernelPropertyState state = new KernelPropertyState(name, values);
+            properties.put(name, state);
+            touch();
+            notifySetProperty(this, state);
         }
 
         //------------------------------------------< internal >---
@@ -418,9 +426,15 @@ public class ChangeTree {
             }
         }
         
-        private void notifySetValue(NodeDelta parent, String name, JsonValue value) {
+        private void notifySetProperty(NodeDelta parent, PropertyState state) {
+            if (listener != null) {
+                listener.setProperty(parent, state);
+            }
+        }
+
+        private void notifyRemoveProperty(NodeDelta parent, String name) {
             if (listener != null) {
-                listener.setValue(parent, name, value);
+                listener.removeProperty(parent, name);
             }
         }
     }
@@ -603,7 +617,7 @@ public class ChangeTree {
         }
 
         @Override
-        public void setValue(String name, JsonValue value) {
+        public void setValue(String name, Scalar value) {
             throw new IllegalStateException("Removed");
         }
 

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/state/TransientNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/state/TransientNodeState.java?rev=1304491&r1=1304490&r2=1304491&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/state/TransientNodeState.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/state/TransientNodeState.java
Fri Mar 23 17:12:00 2012
@@ -26,11 +26,6 @@ import org.apache.jackrabbit.mk.model.Pr
 import org.apache.jackrabbit.oak.api.Scalar;
 import org.apache.jackrabbit.oak.jcr.SessionContext;
 import org.apache.jackrabbit.oak.jcr.SessionImpl;
-import org.apache.jackrabbit.oak.jcr.json.FullJsonParser;
-import org.apache.jackrabbit.oak.jcr.json.JsonValue;
-import org.apache.jackrabbit.oak.jcr.json.JsonValue.JsonAtom;
-import org.apache.jackrabbit.oak.jcr.json.JsonValue.Type;
-import org.apache.jackrabbit.oak.jcr.json.UnescapingJsonTokenizer;
 import org.apache.jackrabbit.oak.jcr.state.ChangeTree.NodeDelta;
 import org.apache.jackrabbit.oak.jcr.util.Function1;
 import org.apache.jackrabbit.oak.jcr.util.Iterators;
@@ -43,7 +38,6 @@ import org.apache.jackrabbit.oak.kernel.
 import javax.jcr.ItemExistsException;
 import javax.jcr.ItemNotFoundException;
 import javax.jcr.PathNotFoundException;
-import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 
@@ -144,14 +138,31 @@ public class TransientNodeState {
     /**
      * Transiently set a property.
      * @param name  Name of the property.
-     * @param value  Value of the property. Use {@code null} or {@code JsonAtom.NULL}
+     * @param value  Value of the property.
      *               to remove the property.
      */
-    public void setProperty(String name, JsonValue value) {
+    public void setProperty(String name, Scalar value) {
         getNodeDelta().setValue(name, value);
     }
 
     /**
+     * Transiently set a property.
+     * @param name  Name of the property.
+     * @param values  Values of the property.
+     */
+    public void setProperty(String name, List<Scalar> values) {
+        getNodeDelta().setValue(name, values);
+    }
+
+    /**
+     * Transiently remove a property.
+     * @param name  name of the property to remove.
+     */
+    public void removeProperty(String name) {
+        getNodeDelta().setValue(name, (Scalar) null);
+    }
+
+    /**
      * @return {@code true} iff this instance has child nodes.
      */
     public boolean hasNodes() {
@@ -163,12 +174,12 @@ public class TransientNodeState {
      */
     public Iterator<TransientNodeState> getNodes() {
         Iterator<? extends ChildNodeEntry> persistedEntries = Iterators.flatten(
-            new PagedIterator<ChildNodeEntry>(BATCH_SIZE) {
-                @Override
-                protected Iterator<? extends ChildNodeEntry> getPage(long pos, int
size) {
-                    return getPersistentNodeState().getChildNodeEntries(pos, size).iterator();
-                }
-            });
+                new PagedIterator<ChildNodeEntry>(BATCH_SIZE) {
+                    @Override
+                    protected Iterator<? extends ChildNodeEntry> getPage(long pos,
int size) {
+                        return getPersistentNodeState().getChildNodeEntries(pos, size).iterator();
+                    }
+                });
 
         final NodeDelta delta = getNodeDelta();
 
@@ -228,55 +239,16 @@ public class TransientNodeState {
 
     /**
      * @param name  name of the property
-     * @return  value of the property named {@code name}.
+     * @return  state of the property named {@code name}.
      * @throws javax.jcr.ItemNotFoundException  if no such property exists.
      */
-    public JsonValue getPropertyValue(String name) throws ItemNotFoundException {
-        JsonValue value = getPropertyValueOrNull(name);
-        if (value == null) {
-            throw new ItemNotFoundException(name);
-        }
-
-        return value;
-    }
-
     public PropertyState getPropertyState(String name) throws ItemNotFoundException {
-        JsonValue value = getPropertyValueOrNull(name);
-        if (value == null) {
+        PropertyState state = getPropertyStateOrNull(name);
+        if (state == null) {
             throw new ItemNotFoundException(name);
         }
 
-        return createPropertyState(name, value);
-    }
-
-    public static PropertyState createPropertyState(String name, JsonValue value) {
-        switch (value.type()) {
-            case STRING:
-            case NUMBER:
-            case BOOLEAN:
-                return new KernelPropertyState(name, toScalar(value));
-            case ARRAY:
-                List<Scalar> values = new ArrayList<Scalar>();
-                for (JsonValue v : value.asArray().value()) {
-                    values.add(toScalar(v));
-                }
-                return new KernelPropertyState(name, values);
-            default:
-                throw new IllegalStateException("Invalid value");
-        }
-    }
-
-    private static Scalar toScalar(JsonValue value) {
-        switch (value.type()) {
-            case STRING:
-                return ScalarImpl.stringScalar(value.asAtom().value());
-            case NUMBER:
-                return ScalarImpl.numberScalar(value.asAtom().value());
-            case BOOLEAN:
-                return ScalarImpl.booleanScalar(value.asAtom().isTrue());
-            default:
-                throw new IllegalStateException("Invalid value");
-        }
+        return state;
     }
 
     /**
@@ -284,7 +256,7 @@ public class TransientNodeState {
      * @return {@code true} iff this instance has a property name {@code name}.
      */
     public boolean hasProperty(String name) {
-        return getPropertyValueOrNull(name) != null;
+        return getPropertyStateOrNull(name) != null;
     }
 
     /**
@@ -292,8 +264,18 @@ public class TransientNodeState {
      * @return {@code true} iff the property named {@code name} has been transiently added.
      */
     public boolean isPropertyNew(String name) {
-        JsonValue value = getNodeDelta().getPropertyValue(name);
-        return value != null && !value.isNull() && getPersistedPropertyValue(name)
== null;
+        KernelPropertyState state = (KernelPropertyState) getNodeDelta().getPropertyState(name);
 // fixme don't cast
+        if (state == null) {
+            return false;
+        }
+
+        if (state.isMultiValued()) {
+            return true;
+        }
+        else {
+            Scalar value = state.getValue();
+            return !value.equals(ScalarImpl.nullScalar()) && getPersistedPropertyState(name)
== null;
+        }
     }
 
     /**
@@ -304,14 +286,6 @@ public class TransientNodeState {
         return getNodeDelta().hasProperty(name);
     }
 
-    /**
-     * Transiently remove a property.
-     * @param name  name of the property to remove.
-     */
-    public void removeProperty(String name) {
-        getNodeDelta().setValue(name, null);
-    }
-
     @Override
     public String toString() {
         return "TransientNodeState(" + getPath().toString() + ')';
@@ -327,42 +301,28 @@ public class TransientNodeState {
         return getNodeStateProvider().getNodeState(nodeDelta);
     }
 
-    private JsonValue getPropertyValueOrNull(String name) {
-        JsonValue value = getNodeDelta().getPropertyValue(name);
-        if (value == null) {
-            return getPersistedPropertyValue(name);
-        }
-        else {
-            return value == JsonAtom.NULL ? null : value;
-        }
-    }
-
-    private JsonValue getPersistedPropertyValue(String name) {
-        PropertyState state = getPersistentNodeState().getProperty(name);
+    private PropertyState getPropertyStateOrNull(String name) {
+        KernelPropertyState state = (KernelPropertyState) getNodeDelta().getPropertyState(name);
 // fixme don't cast
         if (state == null) {
-            return null;
+            return getPersistedPropertyState(name);
         }
         else {
-            // fixme: use Scalar class
-            String v = state.getEncodedValue();
-            if (v.startsWith("[")) {
-                return FullJsonParser.parseArray(new UnescapingJsonTokenizer(v));
-            }
-            else if (v.startsWith("\"")) {
-                return new JsonAtom(v.substring(1, v.length() - 1), Type.STRING);
-            }
-            else if ("true".equalsIgnoreCase(v)) {
-                return JsonAtom.TRUE;
-            }
-            else if ("false".equalsIgnoreCase(v)) {
-                return JsonAtom.FALSE;
+            if (state.isMultiValued()) {
+                return state;
             }
             else {
-                return new JsonAtom(v, Type.NUMBER);
+                Scalar value = state.getValue();
+                return value.equals(ScalarImpl.nullScalar())
+                    ? null
+                    : state;
             }
         }
     }
 
+    private PropertyState getPersistedPropertyState(String name) {
+        return getPersistentNodeState().getProperty(name);
+    }
+
     private synchronized NodeState getPersistentNodeState() {
         Path path = getNodeDelta().getPersistentPath();
         String baseRevision = sessionContext.getRevision();

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/state/TransientSpace.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/state/TransientSpace.java?rev=1304491&r1=1304490&r2=1304491&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/state/TransientSpace.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/state/TransientSpace.java
Fri Mar 23 17:12:00 2012
@@ -21,7 +21,7 @@ package org.apache.jackrabbit.oak.jcr.st
 
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.api.MicroKernelException;
-import org.apache.jackrabbit.oak.jcr.json.JsonValue;
+import org.apache.jackrabbit.mk.model.PropertyState;
 import org.apache.jackrabbit.oak.jcr.state.ChangeTree.Listener;
 import org.apache.jackrabbit.oak.jcr.state.ChangeTree.NodeDelta;
 import org.apache.jackrabbit.oak.jcr.util.Path;
@@ -56,9 +56,15 @@ public class TransientSpace {
         }
 
         @Override
-        public void setValue(NodeDelta parent, String name, JsonValue value) {
-            changeLog.setProperty(parent.getPath(), name, value);
+        public void setProperty(NodeDelta parent, PropertyState state) {
+            changeLog.setProperty(parent.getPath(), state);
         }
+
+        @Override
+        public void removeProperty(NodeDelta parent, String name) {
+            changeLog.removeProperty(parent.getPath(), name);
+        }
+
     };
 
     private ChangeTree changeTree;

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/util/ValueConverter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/util/ValueConverter.java?rev=1304491&r1=1304490&r2=1304491&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/util/ValueConverter.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/util/ValueConverter.java
Fri Mar 23 17:12:00 2012
@@ -21,16 +21,12 @@ package org.apache.jackrabbit.oak.jcr.ut
 
 import org.apache.jackrabbit.ScalarImpl;
 import org.apache.jackrabbit.oak.api.Scalar;
-import org.apache.jackrabbit.oak.jcr.json.JsonValue;
-import org.apache.jackrabbit.oak.jcr.json.JsonValue.JsonArray;
-import org.apache.jackrabbit.oak.jcr.json.JsonValue.JsonAtom;
 
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.jcr.Value;
 import javax.jcr.ValueFactory;
-import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -70,44 +66,14 @@ public final class ValueConverter {
         }
     }
     
-    public static JsonValue toJsonValue(Value value) throws RepositoryException {
-        switch (value.getType()) {
-            case PropertyType.STRING: {
-                return JsonAtom.string(value.getString());
-            }
-            case PropertyType.DOUBLE: {
-                return JsonAtom.number(value.getDouble()); // todo mind NaN
-            }
-            case PropertyType.LONG: {
-                return JsonAtom.number(value.getLong());
-            }
-            case PropertyType.DECIMAL: {
-                return JsonAtom.number(value.getDecimal());
-            }
-            case PropertyType.BOOLEAN: {
-                return value.getBoolean() ? JsonAtom.TRUE : JsonAtom.FALSE;
-            }
-            case PropertyType.BINARY:
-            case PropertyType.DATE:
-            case PropertyType.NAME:
-            case PropertyType.PATH:
-            case PropertyType.REFERENCE:
-            case PropertyType.WEAKREFERENCE:
-            case PropertyType.URI:
-            default: {
-                throw new UnsupportedRepositoryOperationException("toJson"); // todo implement
toJson
-            }
-        }
-    }
-
-    public static JsonArray toJsonValue(Value[] values) throws RepositoryException {
-        List<JsonValue> jsonValues = new ArrayList<JsonValue>();
+    public static List<Scalar> toScalar(Value[] values) throws RepositoryException
{
+        List<Scalar> scalars = new ArrayList<Scalar>();
         for (Value value : values) {
             if (value != null) {
-                jsonValues.add(toJsonValue(value));
+                scalars.add(toScalar(value));
             }
         }
-        return new JsonArray(jsonValues);
+        return scalars;
     }
 
     public static Value toValue(ValueFactory valueFactory, Scalar scalar)
@@ -138,31 +104,4 @@ public final class ValueConverter {
         return values;
     }
 
-    public static Value toValue(ValueFactory valueFactory, JsonAtom jsonAtom) {
-        switch (jsonAtom.type()) {
-            case STRING: {
-                return valueFactory.createValue(jsonAtom.value());  // todo decode to correct
type
-            }
-            case NUMBER: {
-                String value = jsonAtom.value();
-                try {
-                    return valueFactory.createValue(Long.valueOf(value));
-                }
-                catch (NumberFormatException e) {
-                    try {
-                        return valueFactory.createValue(Double.valueOf(value));
-                    }
-                    catch (NumberFormatException e1) {
-                        return valueFactory.createValue(new BigDecimal(value));
-                    }
-                }
-            }
-            case BOOLEAN: {
-                return valueFactory.createValue(Boolean.valueOf(jsonAtom.value()));
-            }
-            default:
-                throw new IllegalArgumentException(jsonAtom.toString());
-        }
-    }
-
 }



Mime
View raw message