jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From resc...@apache.org
Subject svn commit: r1342274 - /jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java
Date Thu, 24 May 2012 14:02:22 GMT
Author: reschke
Date: Thu May 24 14:02:22 2012
New Revision: 1342274

URL: http://svn.apache.org/viewvc?rev=1342274&view=rev
Log:
OAK-23: implement lookup by identifier using Query (WIP)

Modified:
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java

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=1342274&r1=1342273&r2=1342274&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 14:02:22 2012
@@ -25,6 +25,8 @@ import org.apache.jackrabbit.oak.api.Roo
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.jcr.namespace.NamespaceRegistryImpl;
+import org.apache.jackrabbit.oak.jcr.query.QueryImpl;
+import org.apache.jackrabbit.oak.jcr.query.QueryManagerImpl;
 import org.apache.jackrabbit.oak.jcr.value.ValueFactoryImpl;
 import org.apache.jackrabbit.oak.namepath.AbstractNameMapper;
 import org.apache.jackrabbit.oak.namepath.NameMapper;
@@ -44,7 +46,11 @@ import javax.jcr.Session;
 import javax.jcr.Workspace;
 import javax.jcr.lock.LockManager;
 import javax.jcr.nodetype.NodeTypeManager;
+import javax.jcr.query.Query;
 import javax.jcr.query.QueryManager;
+import javax.jcr.query.QueryResult;
+import javax.jcr.query.Row;
+import javax.jcr.query.RowIterator;
 import javax.jcr.version.VersionManager;
 import java.io.IOException;
 
@@ -132,21 +138,49 @@ public class SessionDelegate {
 
     // 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;
+        
+       try {
+           QueryManagerImpl qm = new QueryManagerImpl(this);
+           Query q = qm.createQuery("SELECT * FROM [nt:base] WHERE [jcr:uuid] = $id", Query.JCR_SQL2);
+           q.bindValue("id", getValueFactory().createValue(id));
+           
+           QueryResult result = q.execute();
+           RowIterator ri = result.getRows();
+           if (!ri.hasNext()) {
+               // not found
+               return null;
+           }
+                   
+           Row r = ri.nextRow();
+           
+           if (ri.hasNext()) {
+               log.error("multiple results for query " + q.getStatement());
+               return null;
+           }
+           
+           String path = r.getNode().getPath();
+           String oakPath = namePathMapper.getOakPath(path);
+           return getNode(oakPath);
+       }
+       catch (RepositoryException ex) {
+           log.error("query failed", ex);
+           return null;
+       }
+        
+//       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