jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From resc...@apache.org
Subject svn commit: r1342222 - in /jackrabbit/oak/trunk: oak-it/jcr/ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/
Date Thu, 24 May 2012 12:23:43 GMT
Author: reschke
Date: Thu May 24 12:23:42 2012
New Revision: 1342222

URL: http://svn.apache.org/viewvc?rev=1342222&view=rev
Log:
OAK-66: add a small hack that will lead to auto-creation of jcr:uuid properties (WIP)

Modified:
    jackrabbit/oak/trunk/oak-it/jcr/pom.xml
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeDelegate.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/SessionDelegate.java

Modified: jackrabbit/oak/trunk/oak-it/jcr/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-it/jcr/pom.xml?rev=1342222&r1=1342221&r2=1342222&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-it/jcr/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-it/jcr/pom.xml Thu May 24 12:23:42 2012
@@ -44,8 +44,6 @@
             <property>
               <name>known.issues</name>
               <value>
-org.apache.jackrabbit.test.api.NodeReadMethodsTest#testGetUUID
-org.apache.jackrabbit.test.api.SessionReadMethodsTest#testGetNodeByUUID
 org.apache.jackrabbit.test.api.AddNodeTest#testConstraintViolation
 org.apache.jackrabbit.test.api.AddNodeTest#testRepositoryException
 org.apache.jackrabbit.test.api.ReferencesTest#testNonReferenceable

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeDelegate.java?rev=1342222&r1=1342221&r2=1342222&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeDelegate.java
Thu May 24 12:23:42 2012
@@ -95,8 +95,13 @@ public class NodeDelegate extends ItemDe
     }
 
     public String getIdentifier() {
-        // TODO for now the identifier is the OAK path
-        return getPath();
+        PropertyDelegate pd = getProperty("jcr:uuid");
+        if (pd == null) {
+            return getPath();
+        }
+        else {
+            return pd.getValue().toString();
+        }
     }
 
     /**

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=1342222&r1=1342221&r2=1342222&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
Thu May 24 12:23:42 2012
@@ -56,9 +56,12 @@ import javax.jcr.version.Version;
 import javax.jcr.version.VersionHistory;
 import java.io.InputStream;
 import java.math.BigDecimal;
+import java.util.ArrayList;
 import java.util.Calendar;
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
+import java.util.UUID;
 
 import static org.apache.jackrabbit.oak.util.Iterators.filter;
 
@@ -700,10 +703,30 @@ public class NodeImpl extends ItemImpl i
         checkStatus();
         // TODO: figure out the right place for this check
         NodeTypeManager ntm = sessionDelegate.getNodeTypeManager();
-        ntm.getNodeType(mixinName); // throws on not found
+        NodeType nt = ntm.getNodeType(mixinName); // throws on not found
+        
+        if (nt.isNodeType("mix:referenceable")) {
+            this.setProperty(Property.JCR_UUID, UUID.randomUUID().toString());
+        }
         // TODO: END
 
-        // todo implement addMixin
+        String jcrMixinTypes =
+                sessionDelegate.getOakPathOrThrow(Property.JCR_MIXIN_TYPES);
+        PropertyDelegate mixins = dlg.getProperty(jcrMixinTypes);
+
+        CoreValue cv = ValueConverter.toCoreValue(mixinName, PropertyType.NAME, sessionDelegate);
+        if (mixins == null) {
+            dlg.setProperty(jcrMixinTypes, Collections.singletonList(cv));
+        } else {
+            List<CoreValue> values = new ArrayList<CoreValue>();
+            values.add(cv);
+            for (CoreValue existingValue : mixins.getValues()) {
+                if (!values.contains(existingValue)) {
+                    values.add(existingValue);
+                }
+            }
+            dlg.setProperty(jcrMixinTypes, values);
+        }
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java?rev=1342222&r1=1342221&r2=1342222&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java
Thu May 24 12:23:42 2012
@@ -19,6 +19,7 @@ package org.apache.jackrabbit.oak.jcr;
 import org.apache.jackrabbit.oak.api.AuthInfo;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.ContentSession;
+import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.QueryEngine;
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.Tree;
@@ -119,9 +120,33 @@ public class SessionDelegate {
 
     @CheckForNull
     public NodeDelegate getNodeByIdentifier(String id) {
-        // TODO: for now the OAK path is the identifier
-        Tree tree = getTree(id);
-        return tree == null ? null : new NodeDelegate(this, tree);
+        if (id.startsWith("/")) {
+            Tree tree = getTree(id);
+            return tree == null ? null : new NodeDelegate(this, tree);
+        }
+        else {
+            // referenceable
+            return findByJcrUuid(getTree(""), id);
+        }
+    }
+
+    // TODO replace by query-based implementation
+    private NodeDelegate findByJcrUuid(Tree tree, String id) {
+
+       PropertyState p = tree.getProperty("jcr:uuid");
+        if (p != null && id.equals(p.getValue().getString())) {
+            return new NodeDelegate(this, tree);
+        }
+        else {
+            for (Tree c : tree.getChildren()) {
+                NodeDelegate found = findByJcrUuid(c, id);
+                if (found != null) {
+                    return found;
+                }
+            }
+        }
+
+        return null;
     }
 
     @Nonnull



Mime
View raw message