Author: stillalex
Date: Thu May  2 11:48:10 2019
New Revision: 1858530

URL: http://svn.apache.org/viewvc?rev=1858530&view=rev
Log:
OAK-8249 NodeImpl#isNodeType could load mixin info lazily


Modified:
    
jackrabbit/oak/trunk/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/spi/nodetype/EffectiveNodeTypeProvider.java
    
jackrabbit/oak/trunk/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/spi/nodetype/package-info.java
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java
    
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/AccessManager.java
    
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/NodeImpl.java
    
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionContext.java

Modified: 
jackrabbit/oak/trunk/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/spi/nodetype/EffectiveNodeTypeProvider.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/spi/nodetype/EffectiveNodeTypeProvider.java?rev=1858530&r1=1858529&r2=1858530&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/spi/nodetype/EffectiveNodeTypeProvider.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/spi/nodetype/EffectiveNodeTypeProvider.java
 Thu May  2 11:48:10 2019
@@ -16,7 +16,10 @@
  */
 package org.apache.jackrabbit.oak.spi.nodetype;
 
+import java.util.ArrayList;
 import java.util.Iterator;
+import java.util.List;
+
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 import javax.jcr.nodetype.NoSuchNodeTypeException;
@@ -36,6 +39,11 @@ public interface EffectiveNodeTypeProvid
      * type or mixin type, or a subtype thereof respecting the effective node
      * type of the {@code tree}. Returns {@code false} otherwise.
      *
+     * Note: caution must be taken while calling this api because it doesn't
+     * offer the same strict guarantees as the {@code Node#isNodeType(String)}
+     * method in the case where the session doesn't have access to the
+     * {@code jcr:mixinTypes} property.
+     *
      * @param tree The tree to be tested.
      * @param nodeTypeName The internal oak name of the node type to be tested.
      * @return true if the specified node is of the given node type.
@@ -54,8 +62,29 @@ public interface EffectiveNodeTypeProvid
      * refer to an existing node type.
      * @throws RepositoryException If the given node type name is invalid or if
      * some other error occurs.
+     * @deprecated use {@link #isNodeType(String, Iterable, String)} instead
+     */
+    @Deprecated
+    default boolean isNodeType(@NotNull String primaryTypeName, @NotNull 
Iterator<String> mixinTypes, @NotNull String nodeTypeName) throws 
NoSuchNodeTypeException, RepositoryException {
+        List<String> mixins = new ArrayList<>();
+        mixinTypes.forEachRemaining(mixins::add);
+        return isNodeType(primaryTypeName, mixins, nodeTypeName);
+    }
+
+    /**
+     * Returns {@code true} if {@code typeName} is of the specified primary 
node
+     * type or mixin type, or a subtype thereof. Returns {@code false} 
otherwise.
+     *
+     * @param primaryTypeName  the internal oak name of the node to test
+     * @param mixinTypes the internal oak names of the node to test.
+     * @param nodeTypeName The internal oak name of the node type to be tested.
+     * @return {@code true} if the specified node type is of the given node 
type.
+     * @throws NoSuchNodeTypeException If the specified node type name doesn't
+     * refer to an existing node type.
+     * @throws RepositoryException If the given node type name is invalid or if
+     * some other error occurs.
      */
-    boolean isNodeType(@NotNull String primaryTypeName, @NotNull 
Iterator<String> mixinTypes, @NotNull String nodeTypeName) throws 
NoSuchNodeTypeException, RepositoryException;
+    boolean isNodeType(@NotNull String primaryTypeName, @NotNull 
Iterable<String> mixinTypes, @NotNull String nodeTypeName) throws 
NoSuchNodeTypeException, RepositoryException;
 
     /**
      * Returns {@code true} if {@code typeName} is of the specified primary 
node

Modified: 
jackrabbit/oak/trunk/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/spi/nodetype/package-info.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/spi/nodetype/package-info.java?rev=1858530&r1=1858529&r2=1858530&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/spi/nodetype/package-info.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/spi/nodetype/package-info.java
 Thu May  2 11:48:10 2019
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-@Version("1.0.2")
+@Version("1.1.0")
 package org.apache.jackrabbit.oak.spi.nodetype;
 
 import org.osgi.annotation.versioning.Version;

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java?rev=1858530&r1=1858529&r2=1858530&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java
 Thu May  2 11:48:10 2019
@@ -25,7 +25,6 @@ import static org.apache.jackrabbit.oak.
 import static 
org.apache.jackrabbit.oak.spi.nodetype.NodeTypeConstants.NODE_TYPES_PATH;
 import static 
org.apache.jackrabbit.oak.spi.nodetype.NodeTypeConstants.REP_SUPERTYPES;
 
-import java.util.Iterator;
 import java.util.List;
 
 import javax.jcr.Node;
@@ -285,7 +284,7 @@ public abstract class ReadOnlyNodeTypeMa
     }
 
     @Override
-    public boolean isNodeType(@Nullable String primaryTypeName, @NotNull 
Iterator<String> mixinTypes, @NotNull String nodeTypeName) {
+    public boolean isNodeType(@Nullable String primaryTypeName, @NotNull 
Iterable<String> mixinTypes, @NotNull String nodeTypeName) {
         // shortcut
         if (JcrConstants.NT_BASE.equals(nodeTypeName)) {
             return true;
@@ -294,8 +293,8 @@ public abstract class ReadOnlyNodeTypeMa
         if (primaryTypeName != null && isa(types, primaryTypeName, 
nodeTypeName)) {
             return true;
         }
-        while (mixinTypes.hasNext()) {
-            if (isa(types, mixinTypes.next(), nodeTypeName)) {
+        for (String mixin : mixinTypes) {
+            if (isa(types, mixin, nodeTypeName)) {
                 return true;
             }
         }

Modified: 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/AccessManager.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/AccessManager.java?rev=1858530&r1=1858529&r2=1858530&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/AccessManager.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/AccessManager.java
 Thu May  2 11:48:10 2019
@@ -50,7 +50,7 @@ public class AccessManager {
         });
     }
 
-    public boolean hasPermissions(@NotNull final Tree tree, @Nullable final 
PropertyState property, final long permissions) throws RepositoryException {
+    public boolean hasPermissions(@NotNull final Tree tree, @Nullable final 
PropertyState property, final long permissions) {
         return delegate.safePerform(new 
SessionOperation<Boolean>("hasPermissions") {
             @NotNull
             @Override

Modified: 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/NodeImpl.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/NodeImpl.java?rev=1858530&r1=1858529&r2=1858530&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/NodeImpl.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/NodeImpl.java
 Thu May  2 11:48:10 2019
@@ -938,7 +938,8 @@ public class NodeImpl<T extends NodeDele
             @Override
             public Boolean perform() throws RepositoryException {
                 Tree tree = node.getTree();
-                return 
getNodeTypeManager().isNodeType(getPrimaryTypeName(tree), 
getMixinTypeNames(tree), oakName);
+                Iterable<String> mixins = () -> getMixinTypeNames(tree);
+                return 
getNodeTypeManager().isNodeType(getPrimaryTypeName(tree), mixins, oakName);
             }
         });
     }
@@ -1294,7 +1295,7 @@ public class NodeImpl<T extends NodeDele
     }
 
     @NotNull
-    private Iterator<String> getMixinTypeNames(@NotNull Tree tree) throws 
RepositoryException {
+    private Iterator<String> getMixinTypeNames(@NotNull Tree tree) {
         if (tree.hasProperty(JcrConstants.JCR_MIXINTYPES) || 
canReadMixinTypes(tree)) {
             return TreeUtil.getMixinTypeNames(tree).iterator();
         } else {
@@ -1312,7 +1313,7 @@ public class NodeImpl<T extends NodeDele
         };
     }
 
-    private boolean canReadMixinTypes(@NotNull Tree tree) throws 
RepositoryException {
+    private boolean canReadMixinTypes(@NotNull Tree tree) {
         return sessionContext.getAccessManager().hasPermissions(
                 tree, EMPTY_MIXIN_TYPES, Permissions.READ_PROPERTY);
     }

Modified: 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionContext.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionContext.java?rev=1858530&r1=1858529&r2=1858530&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionContext.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionContext.java
 Thu May  2 11:48:10 2019
@@ -404,7 +404,7 @@ public class SessionContext implements N
     }
 
     @NotNull
-    public AccessManager getAccessManager() throws RepositoryException {
+    public AccessManager getAccessManager() {
         if (accessManager == null) {
             accessManager = new AccessManager(delegate, 
delegate.getPermissionProvider());
         }


Reply via email to