jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1183376 - in /jackrabbit/sandbox/jackrabbit-mk: jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/util/
Date Fri, 14 Oct 2011 14:56:03 GMT
Author: mduerig
Date: Fri Oct 14 14:56:03 2011
New Revision: 1183376

URL: http://svn.apache.org/viewvc?rev=1183376&view=rev
Log:
Microkernel based Jackrabbit prototype (WIP)
simplify merging of item states

Modified:
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyState.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/util/Arrays.java

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java?rev=1183376&r1=1183375&r2=1183376&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java
Fri Oct 14 14:56:03 2011
@@ -26,14 +26,13 @@ import org.apache.jackrabbit.spi.Propert
 import org.apache.jackrabbit.spi.QNodeDefinition;
 import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.spi.commons.name.NameConstants;
+import org.apache.jackrabbit.spi.commons.util.Arrays;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import javax.jcr.ItemNotFoundException;
 import javax.jcr.RepositoryException;
-import java.util.Arrays;
 import java.util.Iterator;
-import java.util.List;
 
 import static org.apache.jackrabbit.spi.commons.util.Unchecked.cast;
 
@@ -114,35 +113,32 @@ public class NodeState extends ItemState
     }
 
     @Override
-    public MergeResult merge(ItemState<?> another, boolean keepChanges) {
+    public MergeResult merge(ItemState<?> state, boolean keepChanges) {
         boolean modified = false;
-        if (another != null && another != this) {
-            if (!another.isNode()) {
-                IllegalArgumentException e = new IllegalArgumentException("Attempt to merge
node state with property " +
-                        "state.");
+        if (state != null && state != this) {
+            if (!state.isNode()) {
+                IllegalArgumentException e = new IllegalArgumentException("Cannot merge node
state with property state");
                 log.error(e.getMessage(), e);
                 throw e;
             }
-            synchronized (another) {
-                NodeState otherState = cast(another);
 
-                if (!nodeTypeName.equals(otherState.nodeTypeName)) {
-                    nodeTypeName = otherState.nodeTypeName;
-                    modified = true;
-                }
+            NodeState otherState = cast(state);
 
-                if (otherState.definition != null && !otherState.definition.equals(definition))
{
-                    definition = otherState.definition;
-                    modified = true;
-                }
+            if (!nodeTypeName.equals(otherState.nodeTypeName)) {
+                nodeTypeName = otherState.nodeTypeName;
+                modified = true;
+            }
 
-                // since 'mixinTypeNames' are modified upon save only, no special
-                // merging is required here. just reset the mixinTypeNames.
-                List<Name> mixN = Arrays.asList(otherState.mixinTypeNames);
-                if (mixN.size() != mixinTypeNames.length || !mixN.containsAll(Arrays.asList(mixinTypeNames)))
{
-                    setMixinTypeNames(otherState.mixinTypeNames);
-                    modified = true;
-                }
+            if (otherState.definition != null && !otherState.definition.equals(definition))
{
+                definition = otherState.definition;
+                modified = true;
+            }
+
+            // since 'mixinTypeNames' are modified upon save only, no special
+            // merging is required here. just reset the mixinTypeNames.
+            if (!Arrays.containSameElements(otherState.mixinTypeNames, mixinTypeNames)) {
+                setMixinTypeNames(otherState.mixinTypeNames);
+                modified = true;
             }
         }
         return new SimpleMergeResult(modified);

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyState.java?rev=1183376&r1=1183375&r2=1183376&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyState.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyState.java
Fri Oct 14 14:56:03 2011
@@ -117,27 +117,26 @@ public class PropertyState extends ItemS
 
     /**
      * If {@code keepChanges} is true, this method only compares the existing
-     * values with the values from 'another' and returns true, if the underlying
+     * values with the values from 'state' and returns true, if the underlying
      * persistent state is different to the stored persistent values. Otherwise
      * the transient changes will be discarded.
      *
      */
     @Override
-    public MergeResult merge(ItemState<?> another, boolean keepChanges) {
+    public MergeResult merge(ItemState<?> state, boolean keepChanges) {
         boolean modified = false;
-        if (another != null && another != this) {
-            if (another.isNode()) {
-                IllegalArgumentException e = new IllegalArgumentException("Attempt to merge
property state with node " +
-                        "state.");
+        if (state != null && state != this) {
+            if (state.isNode()) {
+                IllegalArgumentException e = new IllegalArgumentException("Cannot merge property
state with node state");
                 log.error(e.getMessage(), e);
                 throw e;
             }
 
-            PropertyData anotherData = Unchecked.<PropertyState>cast(another).data;
-            PropertyDiffer result = new PropertyDiffer(data, anotherData);
+            PropertyData otherData = Unchecked.<PropertyState>cast(state).data;
+            PropertyDiffer result = new PropertyDiffer(data, otherData);
 
-            // reset the pInfo to point to the pInfo of another state.
-            data = anotherData;
+            // reset the pInfo to point to the pInfo of state.
+            data = otherData;
             // if transient changes should be preserved OR if there are not
             // transient changes, return the differ and postpone the effort of
             // calculating the diff (the test if this state got internally changed)).

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/util/Arrays.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/util/Arrays.java?rev=1183376&r1=1183375&r2=1183376&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/util/Arrays.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/util/Arrays.java
Fri Oct 14 14:56:03 2011
@@ -42,6 +42,19 @@ public final class Arrays {
         return false;
     }
 
+    public static <T> boolean containsAll(T[] array, T[] elements) {
+        for (T e : elements) {
+            if (!contains(array, e)) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    public static <T> boolean containSameElements(T[] array1, T[] array2) {
+        return array1 == array2 || array1.length == array2.length && containsAll(array1,
array2);
+    }
+
     public static <T> Set<T> toSet(T... elements) {
         Set<T> set = new HashSet<T>();
         set.addAll(java.util.Arrays.asList(elements));



Mime
View raw message