jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1375613 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/IdentifierManager.java oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java
Date Tue, 21 Aug 2012 15:39:30 GMT
Author: mduerig
Date: Tue Aug 21 15:39:29 2012
New Revision: 1375613

URL: http://svn.apache.org/viewvc?rev=1375613&view=rev
Log:
OAK-101: implement identifier handling (byUUID, byIdentifier, etc)
getReferences(String) and getWeakReferences(String) not yet working.

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/IdentifierManager.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/IdentifierManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/IdentifierManager.java?rev=1375613&r1=1375612&r2=1375613&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/IdentifierManager.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/IdentifierManager.java
Tue Aug 21 15:39:29 2012
@@ -41,6 +41,7 @@ import org.apache.jackrabbit.oak.api.Res
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.SessionQueryEngine;
 import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
 import org.apache.jackrabbit.oak.plugins.memory.StringValue;
 import org.slf4j.Logger;
@@ -179,26 +180,29 @@ public class IdentifierManager {
      * specified {@code tree} and matching the constraints.
      */
     @Nonnull
-    public Set<String> getReferences(boolean weak, Tree tree, String propertyName,
final String... nodeTypeNames) {
+    public Set<String> getReferences(boolean weak, Tree tree, final String propertyName,
final String... nodeTypeNames) {
         if (!isReferenceable(tree)) {
             return Collections.emptySet();
         } else {
             try {
-                String uuid = getIdentifier(tree);
+                final String uuid = getIdentifier(tree);
                 String reference = weak ? PropertyType.TYPENAME_WEAKREFERENCE : PropertyType.TYPENAME_REFERENCE;
-                propertyName = propertyName == null ? "*" : propertyName;   // TODO: sanitize
against injection attacks!?
-                Map<String, ? extends CoreValue> bindings = Collections.singletonMap("id",
new StringValue(uuid));
+                String pName = propertyName == null ? "*" : propertyName;   // TODO: sanitize
against injection attacks!?
+                Map<String, ? extends CoreValue> bindings = Collections.singletonMap("uuid",
new StringValue(uuid));
 
                 // TODO query depends on OAK-261
                 Result result = queryEngine.executeQuery(
-                        "SELECT * FROM [nt:base] WHERE PROPERTY([" + propertyName + "], '"
+ reference + "') = $uuid",
+                        "SELECT * FROM [nt:base] WHERE PROPERTY([" + pName + "], '" + reference
+ "') = $uuid",
                         Query.JCR_SQL2, Long.MAX_VALUE, 0, bindings, new NamePathMapper.Default());
 
                 Iterable<String> paths = Iterables.transform(result.getRows(),
                         new Function<ResultRow, String>() {
                             @Override
                             public String apply(ResultRow row) {
-                                return row.getPath();
+                                String pName = propertyName == null
+                                    ? findProperty(row.getPath(), uuid)
+                                    : propertyName;
+                                return PathUtils.concat(row.getPath(), pName);
                             }
                 });
 
@@ -206,7 +210,7 @@ public class IdentifierManager {
                     paths = Iterables.filter(paths, new Predicate<String>() {
                         @Override
                         public boolean apply(String path) {
-                            Tree tree = root.getTree(path);
+                            Tree tree = root.getTree(PathUtils.getParentPath(path));
                             if (tree != null) {
                                 for (String ntName : nodeTypeNames) {
                                     if (hasType(tree, ntName)) {
@@ -228,6 +232,30 @@ public class IdentifierManager {
         }
     }
 
+    private String findProperty(String path, final String uuid) {
+        // TODO (OAK-220) PropertyState can only be accessed from parent tree
+        Tree tree = root.getTree(path);
+        assert tree != null;
+        final PropertyState refProp = Iterables.find(tree.getProperties(), new Predicate<PropertyState>()
{
+            @Override
+            public boolean apply(PropertyState pState) {
+                if (pState.isArray()) {
+                    for (CoreValue value : pState.getValues()) {
+                        if (uuid.equals(value.getString())) {
+                            return true;
+                        }
+                    }
+                    return false;
+                }
+                else {
+                    return uuid.equals(pState.getValue().getString());
+                }
+            }
+        });
+
+        return refProp.getName();
+    }
+
     private static boolean hasType(Tree tree, String ntName) {
         // TODO use NodeType.isNodeType to determine type membership instead of equality
on type names
         PropertyState pType = tree.getProperty(JcrConstants.JCR_PRIMARYTYPE);

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java?rev=1375613&r1=1375612&r2=1375613&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java
Tue Aug 21 15:39:29 2012
@@ -984,7 +984,6 @@ public class RepositoryTest extends Abst
     }
 
     @Test
-    @Ignore("OAK-261")  //  TODO OAK-261: Support querying on property types
     public void getReferences() throws RepositoryException {
         Session session = getAdminSession();
         Node referee = getNode("/foo");
@@ -1006,19 +1005,18 @@ public class RepositoryTest extends Abst
         Node referee = getNode("/foo");
         referee.addMixin("mix:referenceable");
         Value value = session.getValueFactory().createValue(referee);
-        getNode(TEST_PATH).setProperty("reference", value);
-        getNode("/bar").setProperty("reference", value);
+        getNode(TEST_PATH).setProperty("reference1", value);
+        getNode("/bar").setProperty("reference2", value);
         session.save();
 
-        PropertyIterator refs = referee.getReferences("bar");
+        PropertyIterator refs = referee.getReferences("reference1");
         assertTrue(refs.hasNext());
         Property p = refs.nextProperty();
-        assertEquals("reference", p.getName());
+        assertEquals("reference1", p.getName());
         assertFalse(refs.hasNext());
     }
 
     @Test
-    @Ignore("OAK-261")  //  TODO OAK-261: Support querying on property types
     public void getWeakReferences() throws RepositoryException {
         Session session = getAdminSession();
         Node referee = getNode("/foo");
@@ -1040,14 +1038,14 @@ public class RepositoryTest extends Abst
         Node referee = getNode("/foo");
         referee.addMixin("mix:referenceable");
         Value value = session.getValueFactory().createValue(referee, true);
-        getNode(TEST_PATH).setProperty("reference", value);
-        getNode("/bar").setProperty("reference", value);
+        getNode(TEST_PATH).setProperty("weak-reference1", value);
+        getNode("/bar").setProperty("weak-reference2", value);
         session.save();
 
-        PropertyIterator refs = referee.getWeakReferences("bar");
+        PropertyIterator refs = referee.getWeakReferences("weak-reference1");
         assertTrue(refs.hasNext());
         Property p = refs.nextProperty();
-        assertEquals("reference", p.getName());
+        assertEquals("weak-reference1", p.getName());
         assertFalse(refs.hasNext());
     }
 



Mime
View raw message