jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r701127 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: ./ nodetype/ state/ version/ virtual/
Date Thu, 02 Oct 2008 13:52:40 GMT
Author: jukka
Date: Thu Oct  2 06:52:39 2008
New Revision: 701127

URL: http://svn.apache.org/viewvc?rev=701127&view=rev
Log:
JCR-1775: Transaction-safe versioning

Modified the NodeTypeRegistry.getEffectiveNodeType method to simplify calling code that always
starts with the primary type name and a set of mixin types.

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/BatchedItemOperations.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemValidator.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/NodeStateEx.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/virtual/AbstractVISProvider.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/BatchedItemOperations.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/BatchedItemOperations.java?rev=701127&r1=701126&r2=701127&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/BatchedItemOperations.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/BatchedItemOperations.java
Thu Oct  2 06:52:39 2008
@@ -2039,14 +2039,10 @@
         if (mixins.contains(NameConstants.MIX_SHAREABLE)) {
             return true;
         }
-        // build effective node type
-        Name[] types = new Name[mixins.size() + 1];
-        mixins.toArray(types);
-        // primary type
-        types[types.length - 1] = primary;
 
         try {
-            return ntReg.getEffectiveNodeType(types).includesNodeType(NameConstants.MIX_REFERENCEABLE);
+            EffectiveNodeType type = ntReg.getEffectiveNodeType(primary, mixins);
+            return type.includesNodeType(NameConstants.MIX_REFERENCEABLE);
         } catch (NodeTypeConflictException ntce) {
             String msg = "internal error: failed to build effective node type for node "
                     + state.getNodeId();

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemValidator.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemValidator.java?rev=701127&r1=701126&r2=701127&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemValidator.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemValidator.java
Thu Oct  2 06:52:39 2008
@@ -185,23 +185,18 @@
      * node type representation of the specified node's primary and mixin
      * node types.
      *
-     * @param nodeState
+     * @param state
      * @return the effective node type
      * @throws RepositoryException
      */
-    public EffectiveNodeType getEffectiveNodeType(NodeState nodeState)
+    public EffectiveNodeType getEffectiveNodeType(NodeState state)
             throws RepositoryException {
-        // mixin types
-        Set set = nodeState.getMixinTypeNames();
-        Name[] types = new Name[set.size() + 1];
-        set.toArray(types);
-        // primary type
-        types[types.length - 1] = nodeState.getNodeTypeName();
         try {
-            return ntReg.getEffectiveNodeType(types);
+            return ntReg.getEffectiveNodeType(
+                    state.getNodeTypeName(), state.getMixinTypeNames());
         } catch (NodeTypeConflictException ntce) {
             String msg = "internal error: failed to build effective node type for node "
-                    + safeGetJCRPath(nodeState.getNodeId());
+                    + safeGetJCRPath(state.getNodeId());
             log.debug(msg);
             throw new RepositoryException(msg, ntce);
         }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java?rev=701127&r1=701126&r2=701127&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
Thu Oct  2 06:52:39 2008
@@ -842,28 +842,12 @@
      * @throws RepositoryException if an error occurs
      */
     public EffectiveNodeType getEffectiveNodeType() throws RepositoryException {
-        return getEffectiveNodeType(data.getNodeState().getMixinTypeNames());
-    }
-
-    /**
-     * Small optimization to void double call for mixin types.
-     *
-     * @param mixins the set of mixins
-     * @return the effective node type
-     * @throws RepositoryException if an error occurs
-     */
-    private EffectiveNodeType getEffectiveNodeType(Set mixins)
-            throws RepositoryException {
-
-        // build effective node type of mixins & primary type
-        NodeTypeRegistry ntReg = session.getNodeTypeManager().getNodeTypeRegistry();
-
-        Name[] types = new Name[mixins.size() + 1];
-        mixins.toArray(types);
-        // primary type
-        types[types.length - 1] = data.getNodeState().getNodeTypeName();
         try {
-            return ntReg.getEffectiveNodeType(types);
+            NodeTypeRegistry registry =
+                session.getNodeTypeManager().getNodeTypeRegistry();
+            return registry.getEffectiveNodeType(
+                    data.getNodeState().getNodeTypeName(),
+                    data.getNodeState().getMixinTypeNames());
         } catch (NodeTypeConflictException ntce) {
             String msg = "Failed to build effective node type for " + this;
             log.debug(msg);
@@ -1048,22 +1032,21 @@
         EffectiveNodeType entExisting;
         try {
             // existing mixin's
-            HashSet set = new HashSet(data.getNodeState().getMixinTypeNames());
-            // primary type
-            set.add(primaryTypeName);
+            Set mixins = new HashSet(data.getNodeState().getMixinTypeNames());
+
             // build effective node type representing primary type including existing mixin's
-            entExisting = ntReg.getEffectiveNodeType((Name[]) set.toArray(new Name[set.size()]));
+            entExisting = ntReg.getEffectiveNodeType(primaryTypeName, mixins);
             if (entExisting.includesNodeType(mixinName)) {
                 // new mixin is already included in existing mixin type(s)
                 return;
             }
 
             // add new mixin
-            set.add(mixinName);
+            mixins.add(mixinName);
             // try to build new effective node type (will throw in case of conflicts)
-            ntReg.getEffectiveNodeType((Name[]) set.toArray(new Name[set.size()]));
-        } catch (NodeTypeConflictException ntce) {
-            throw new ConstraintViolationException(ntce.getMessage());
+            ntReg.getEffectiveNodeType(primaryTypeName, mixins);
+        } catch (NodeTypeConflictException e) {
+            throw new ConstraintViolationException(e.getMessage(), e);
         }
 
         // do the actual modifications implied by the new mixin;
@@ -1160,14 +1143,11 @@
         remainingMixins.remove(mixinName);
         EffectiveNodeType entRemaining;
         try {
-            // remaining mixin's
-            HashSet set = new HashSet(remainingMixins);
-            // primary type
-            set.add(state.getNodeTypeName());
             // build effective node type representing primary type including remaining mixin's
-            entRemaining = ntReg.getEffectiveNodeType((Name[]) set.toArray(new Name[set.size()]));
-        } catch (NodeTypeConflictException ntce) {
-            throw new ConstraintViolationException(ntce.getMessage());
+            entRemaining = ntReg.getEffectiveNodeType(
+                    state.getNodeTypeName(), remainingMixins);
+        } catch (NodeTypeConflictException e) {
+            throw new ConstraintViolationException(e.getMessage(), e);
         }
 
         /**
@@ -1251,7 +1231,8 @@
         sanityCheck();
 
         // first do trivial checks without using type hierarchy
-        if (ntName.equals(data.getNodeState().getNodeTypeName())) {
+        Name primary = data.getNodeState().getNodeTypeName();
+        if (ntName.equals(primary)) {
             return true;
         }
         Set mixins = data.getNodeState().getMixinTypeNames();
@@ -1260,7 +1241,17 @@
         }
 
         // check effective node type
-        return getEffectiveNodeType(mixins).includesNodeType(ntName);
+        try {
+            NodeTypeRegistry registry =
+                session.getNodeTypeManager().getNodeTypeRegistry();
+            EffectiveNodeType type =
+                registry.getEffectiveNodeType(primary, mixins);
+            return type.includesNodeType(ntName);
+        } catch (NodeTypeConflictException e) {
+            String msg = "Failed to build effective node type for " + this;
+            log.debug(msg);
+            throw new RepositoryException(msg, e);
+        }
     }
 
     /**
@@ -2858,18 +2849,18 @@
         EffectiveNodeType entExisting;
         try {
             // existing mixin's
-            HashSet set = new HashSet(data.getNodeState().getMixinTypeNames());
-            // primary type
-            set.add(primaryTypeName);
+            Set mixins = new HashSet(data.getNodeState().getMixinTypeNames());
+
             // build effective node type representing primary type including existing mixin's
-            entExisting = ntReg.getEffectiveNodeType((Name[]) set.toArray(new Name[set.size()]));
+            entExisting = ntReg.getEffectiveNodeType(primaryTypeName, mixins);
             if (entExisting.includesNodeType(ntName)) {
                 return false;
             }
+
             // add new mixin
-            set.add(ntName);
+            mixins.add(ntName);
             // try to build new effective node type (will throw in case of conflicts)
-            ntReg.getEffectiveNodeType((Name[]) set.toArray(new Name[set.size()]));
+            ntReg.getEffectiveNodeType(primaryTypeName, mixins);
         } catch (NodeTypeConflictException ntce) {
             return false;
         }
@@ -4781,12 +4772,8 @@
             entNew = ntReg.getEffectiveNodeType(ntName);
             entOld = ntReg.getEffectiveNodeType(state.getNodeTypeName());
 
-            // existing mixin's
-            HashSet set = new HashSet(state.getMixinTypeNames());
-            // new primary type
-            set.add(ntName);
             // try to build new effective node type (will throw in case of conflicts)
-            ntReg.getEffectiveNodeType((Name[]) set.toArray(new Name[set.size()]));
+            ntReg.getEffectiveNodeType(ntName, state.getMixinTypeNames());
         } catch (NodeTypeConflictException ntce) {
             throw new ConstraintViolationException(ntce.getMessage());
         }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java?rev=701127&r1=701126&r2=701127&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java
Thu Oct  2 06:52:39 2008
@@ -470,14 +470,25 @@
     }
 
     /**
-     * @param ntNames
-     * @return
-     * @throws NodeTypeConflictException
-     * @throws NoSuchNodeTypeException
+     * Returns the effective node type of a node with the given primary
+     * and mixin types.
+     *
+     * @param primary primary type of the node
+     * @param mixins mixin types of the node (set of {@link Name names});
+     * @return effective node type
+     * @throws NodeTypeConflictException if the given types are conflicting
+     * @throws NoSuchNodeTypeException if one of the given types is not found
      */
-    public EffectiveNodeType getEffectiveNodeType(Name[] ntNames)
+    public EffectiveNodeType getEffectiveNodeType(Name primary, Set mixins)
             throws NodeTypeConflictException, NoSuchNodeTypeException {
-        return getEffectiveNodeType(ntNames, entCache, registeredNTDefs);
+        if (mixins.isEmpty()) {
+            return getEffectiveNodeType(primary);
+        } else {
+            Name[] names = new Name[mixins.size() + 1];
+            mixins.toArray(names);
+            names[names.length - 1] = primary;
+            return getEffectiveNodeType(names, entCache, registeredNTDefs);
+        }
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java?rev=701127&r1=701126&r2=701127&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
Thu Oct  2 06:52:39 2008
@@ -1206,13 +1206,11 @@
                 || primary.equals(NameConstants.NT_RESOURCE)) {
             return true;
         }
+
         // build effective node type
-        Name[] types = new Name[mixins.size() + 1];
-        mixins.toArray(types);
-        // primary type
-        types[types.length - 1] = primary;
         try {
-            return ntReg.getEffectiveNodeType(types).includesNodeType(NameConstants.MIX_REFERENCEABLE);
+            EffectiveNodeType type = ntReg.getEffectiveNodeType(primary, mixins);
+            return type.includesNodeType(NameConstants.MIX_REFERENCEABLE);
         } catch (NodeTypeConflictException ntce) {
             String msg = "internal error: failed to build effective node type for node "
                     + state.getNodeId();

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/NodeStateEx.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/NodeStateEx.java?rev=701127&r1=701126&r2=701127&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/NodeStateEx.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/NodeStateEx.java
Thu Oct  2 06:52:39 2008
@@ -284,14 +284,9 @@
      * @throws RepositoryException
      */
     public EffectiveNodeType getEffectiveNodeType() throws RepositoryException {
-
-        // build effective node type of mixins & primary type
-        // existing mixin's
-        HashSet set = new HashSet((nodeState).getMixinTypeNames());
-        // primary type
-        set.add(nodeState.getNodeTypeName());
         try {
-            return ntReg.getEffectiveNodeType((Name[]) set.toArray(new Name[set.size()]));
+            return ntReg.getEffectiveNodeType(
+                    nodeState.getNodeTypeName(), nodeState.getMixinTypeNames());
         } catch (NodeTypeConflictException ntce) {
             String msg = "internal error: failed to build effective node type for node "
+ nodeState.getNodeId();
             throw new RepositoryException(msg, ntce);

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/virtual/AbstractVISProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/virtual/AbstractVISProvider.java?rev=701127&r1=701126&r2=701127&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/virtual/AbstractVISProvider.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/virtual/AbstractVISProvider.java
Thu Oct  2 06:52:39 2008
@@ -406,14 +406,10 @@
      * @throws RepositoryException
      */
     protected EffectiveNodeType getEffectiveNodeType(NodeState parent) throws RepositoryException
{
-        // build effective node type of mixins & primary type
-        NodeTypeRegistry ntReg = getNodeTypeRegistry();
-        // existing mixin's
-        HashSet set = new HashSet(parent.getMixinTypeNames());
-        // primary type
-        set.add(parent.getNodeTypeName());
         try {
-            return ntReg.getEffectiveNodeType((Name[]) set.toArray(new Name[set.size()]));
+            NodeTypeRegistry ntReg = getNodeTypeRegistry();
+            return ntReg.getEffectiveNodeType(
+                    parent.getNodeTypeName(), parent.getMixinTypeNames());
         } catch (NodeTypeConflictException ntce) {
             String msg = "internal error: failed to build effective node type for node "
+ parent.getNodeId();
             throw new RepositoryException(msg, ntce);



Mime
View raw message