jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1376871 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/api/ oak-core/src/main/java/org/apache/jackrabbit/oak/core/ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/
Date Fri, 24 Aug 2012 09:15:56 GMT
Author: mduerig
Date: Fri Aug 24 09:15:55 2012
New Revision: 1376871

URL: http://svn.apache.org/viewvc?rev=1376871&view=rev
Log:
OAK-275 Introduce TreeLocation interface
OAK-218 Session methods rely on accessibility of root node

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Root.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Root.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Root.java?rev=1376871&r1=1376870&r2=1376871&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Root.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Root.java Fri
Aug 24 09:15:55 2012
@@ -78,6 +78,14 @@ public interface Root {
     Tree getTree(String path);
 
     /**
+     * Get a tree location for a given {@code path}
+     * @param path  path to the location
+     * @return  the tree location for {@code path}
+     */
+    @Nonnull
+    TreeLocation getLocation(String path);
+
+    /**
      * Rebase this root instance to the latest revision. After a call to this method,
      * all trees obtained through {@link #getTree(String)} become invalid and fresh
      * instances must be obtained.

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java?rev=1376871&r1=1376870&r2=1376871&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java
Fri Aug 24 09:15:55 2012
@@ -20,6 +20,7 @@ package org.apache.jackrabbit.oak.core;
 
 import java.util.ArrayList;
 import java.util.List;
+
 import javax.annotation.Nonnull;
 
 import org.apache.jackrabbit.oak.api.ChangeExtractor;
@@ -27,7 +28,7 @@ import org.apache.jackrabbit.oak.api.Com
 import org.apache.jackrabbit.oak.api.ConflictHandler;
 import org.apache.jackrabbit.oak.api.CoreValueFactory;
 import org.apache.jackrabbit.oak.api.Root;
-import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.api.TreeLocation;
 import org.apache.jackrabbit.oak.security.privilege.PrivilegeValidatorProvider;
 import org.apache.jackrabbit.oak.security.user.UserValidatorProvider;
 import org.apache.jackrabbit.oak.spi.commit.CommitEditor;
@@ -139,11 +140,17 @@ public class RootImpl implements Root {
     }
 
     @Override
-    public Tree getTree(String path) {
+    public TreeImpl getTree(String path) {
         return rootTree.getTree(path);
     }
 
     @Override
+    public TreeLocation getLocation(String path) {
+        assert path.startsWith("/");
+        return rootTree.getLocation().getChild(path.substring(1));
+    }
+
+    @Override
     public void rebase(ConflictHandler conflictHandler) {
         if (!store.getRoot().equals(rootTree.getBaseState())) {
             purgePendingChanges();

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java?rev=1376871&r1=1376870&r2=1376871&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
Fri Aug 24 09:15:55 2012
@@ -562,6 +562,7 @@ public class TreeImpl implements Tree, P
 
         @Override
         public TreeLocation getChild(String relPath) {
+            assert !relPath.startsWith("/");
             if (relPath.isEmpty()) {
                 return this;
             }

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=1376871&r1=1376870&r2=1376871&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
Fri Aug 24 09:15:55 2012
@@ -18,6 +18,7 @@ package org.apache.jackrabbit.oak.jcr;
 
 import java.io.IOException;
 import java.util.concurrent.ScheduledExecutorService;
+
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import javax.jcr.ItemExistsException;
@@ -39,10 +40,10 @@ import org.apache.jackrabbit.oak.api.Cha
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.ConflictHandler;
 import org.apache.jackrabbit.oak.api.ContentSession;
-import org.apache.jackrabbit.oak.api.PropertyState;
 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.api.TreeLocation;
 import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.core.DefaultConflictHandler;
 import org.apache.jackrabbit.oak.jcr.observation.ObservationManagerImpl;
@@ -205,12 +206,10 @@ public class SessionDelegate {
      * none exists or not accessible.
      */
     public PropertyDelegate getProperty(String path) {
-        String parentPath = PathUtils.getParentPath(path);
-        String name = PathUtils.getName(path);
-
-        Tree parent = getTree(parentPath);
-        PropertyState propertyState = parent == null ? null : parent.getProperty(name);
-        return propertyState == null ? null : new PropertyDelegate(this, parent, propertyState);
+        TreeLocation location = root.getLocation(path);
+        return location.getProperty() == null
+            ? null
+            : new PropertyDelegate(this, location);
     }
 
     @Nonnull
@@ -479,6 +478,11 @@ public class SessionDelegate {
         return root.getTree(path);
     }
 
+    @Nonnull
+    TreeLocation getLocation(String path) {
+        return root.getLocation(path);
+    }
+
     UserManager getUserManager() throws UnsupportedRepositoryOperationException {
         // FIXME
         UserContext ctx = new UserContextImpl();

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java?rev=1376871&r1=1376870&r2=1376871&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
Fri Aug 24 09:15:55 2012
@@ -22,6 +22,7 @@ import java.util.HashSet;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
+
 import javax.annotation.Nonnull;
 import javax.jcr.AccessDeniedException;
 import javax.jcr.Credentials;
@@ -48,6 +49,7 @@ import org.apache.jackrabbit.api.securit
 import org.apache.jackrabbit.api.security.user.UserManager;
 import org.apache.jackrabbit.commons.AbstractSession;
 import org.apache.jackrabbit.commons.iterator.AccessControlPolicyIteratorAdapter;
+import org.apache.jackrabbit.oak.api.TreeLocation;
 import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.jcr.security.principal.PrincipalManagerImpl;
 import org.apache.jackrabbit.oak.jcr.xml.XmlImportHandler;
@@ -206,15 +208,40 @@ public class SessionImpl extends Abstrac
     }
 
     @Override
-    public Property getProperty(String absPath) throws RepositoryException {
-        // FIXME OAK-218
-        return super.getProperty(absPath);
+    public Property getProperty(final String absPath) throws RepositoryException {
+        if (absPath.equals("/")) {
+            throw new RepositoryException("The root node is not a property");
+        } else {
+            return dlg.perform(new SessionOperation<PropertyImpl>() {
+                @Override
+                public PropertyImpl perform() throws RepositoryException {
+                    String oakPath = dlg.getOakPathOrThrowNotFound(absPath);
+                    TreeLocation loc = dlg.getLocation(oakPath);
+                    if (loc.getProperty() == null) {
+                        throw new PathNotFoundException(absPath);
+                    }
+                    else {
+                        return new PropertyImpl(new PropertyDelegate(dlg, loc));
+                    }
+                }
+            });
+        }
     }
 
     @Override
-    public boolean propertyExists(String absPath) throws RepositoryException {
-        // FIXME OAK-218
-        return super.propertyExists(absPath);
+    public boolean propertyExists(final String absPath) throws RepositoryException {
+        if (absPath.equals("/")) {
+            throw new RepositoryException("The root node is not a property");
+        } else {
+            return dlg.perform(new SessionOperation<Boolean>() {
+                @Override
+                public Boolean perform() throws RepositoryException {
+                    String oakPath = dlg.getOakPathOrThrowNotFound(absPath);
+                    TreeLocation loc = dlg.getLocation(oakPath);
+                    return loc.getProperty() != null;
+                }
+            });
+        }
     }
 
     @Override
@@ -324,7 +351,8 @@ public class SessionImpl extends Abstrac
 
         String oakPath = dlg.getOakPathOrNull(absPath);
         if (oakPath == null) {
-            return false; // TODO should we throw an exception here?
+            // TODO should we throw an exception here?
+            return TODO.dummyImplementation().returnValue(false);
         }
 
         // TODO
@@ -418,15 +446,15 @@ public class SessionImpl extends Abstrac
         new HashMap<String, String>();
 
     @Override
-    public void setNamespacePrefix(String prefix, String uri) throws NamespaceException,
RepositoryException {
+    public void setNamespacePrefix(String prefix, String uri) throws RepositoryException
{
         if (prefix == null) {
             throw new IllegalArgumentException("Prefix must not be null");
         } else if (uri == null) {
             throw new IllegalArgumentException("Namespace must not be null");
-        } else if (prefix.length() == 0) {
+        } else if (prefix.isEmpty()) {
             throw new NamespaceException(
                     "Empty prefix is reserved and can not be remapped");
-        } else if (uri.length() == 0) {
+        } else if (uri.isEmpty()) {
             throw new NamespaceException(
                     "Default namespace is reserved and can not be remapped");
         } else if (prefix.toLowerCase(Locale.ENGLISH).startsWith("xml")) {
@@ -467,7 +495,7 @@ public class SessionImpl extends Abstrac
     }
 
     @Override
-    public String getNamespaceURI(String prefix) throws NamespaceException, RepositoryException
{
+    public String getNamespaceURI(String prefix) throws RepositoryException {
         synchronized (namespaces) {
             String uri = namespaces.get(prefix);
 
@@ -489,7 +517,7 @@ public class SessionImpl extends Abstrac
     }
 
     @Override
-    public String getNamespacePrefix(String uri) throws NamespaceException, RepositoryException
{
+    public String getNamespacePrefix(String uri) throws RepositoryException {
         synchronized (namespaces) {
             for (Map.Entry<String, String> entry : namespaces.entrySet()) {
                 if (entry.getValue().equals(uri)) {



Mime
View raw message