jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From resc...@apache.org
Subject svn commit: r1333078 - in /jackrabbit/oak/trunk: oak-it/jcr/ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/
Date Wed, 02 May 2012 15:38:05 GMT
Author: reschke
Date: Wed May  2 15:38:05 2012
New Revision: 1333078

URL: http://svn.apache.org/viewvc?rev=1333078&view=rev
Log:
OAK-66: add a few naive node type checks to addNode, improve handling of node.save, update
test exclusions

Modified:
    jackrabbit/oak/trunk/oak-it/jcr/pom.xml
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionContext.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java

Modified: jackrabbit/oak/trunk/oak-it/jcr/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-it/jcr/pom.xml?rev=1333078&r1=1333077&r2=1333078&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-it/jcr/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-it/jcr/pom.xml Wed May  2 15:38:05 2012
@@ -47,7 +47,9 @@
 org.apache.jackrabbit.test.api.NodeDiscoveringNodeTypesTest#testIsNodeType
 org.apache.jackrabbit.test.api.SessionReadMethodsTest#testGetNodeByUUIDFailure
 org.apache.jackrabbit.test.api.PathTest
-org.apache.jackrabbit.test.api.AddNodeTest
+org.apache.jackrabbit.test.api.AddNodeTest#testSameNameSiblings
+org.apache.jackrabbit.test.api.AddNodeTest#testConstraintViolation
+org.apache.jackrabbit.test.api.AddNodeTest#testRepositoryException
 org.apache.jackrabbit.test.api.ReferencesTest
 org.apache.jackrabbit.test.api.SessionTest
 org.apache.jackrabbit.test.api.SessionUUIDTest

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemImpl.java?rev=1333078&r1=1333077&r2=1333078&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemImpl.java
Wed May  2 15:38:05 2012
@@ -118,6 +118,11 @@ abstract class ItemImpl implements Item 
     @Override
     public void save() throws RepositoryException {
         log.warn("Item#save is no longer supported. Please use Session#save instead.");
+        
+        if (isNew()) {
+            throw new RepositoryException("Item.save() not allowed on new item");
+        }
+        
         getSession().save();
     }
 

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java?rev=1333078&r1=1333077&r2=1333078&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
Wed May  2 15:38:05 2012
@@ -16,7 +16,6 @@
  */
 package org.apache.jackrabbit.oak.jcr;
 
-import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.commons.iterator.NodeIteratorAdapter;
 import org.apache.jackrabbit.commons.iterator.PropertyIteratorAdapter;
 import org.apache.jackrabbit.oak.api.CoreValue;
@@ -45,6 +44,7 @@ import javax.jcr.RepositoryException;
 import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.jcr.Value;
 import javax.jcr.lock.Lock;
+import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.nodetype.NodeDefinition;
 import javax.jcr.nodetype.NodeType;
 import javax.jcr.nodetype.NodeTypeManager;
@@ -154,9 +154,17 @@ public class NodeImpl extends ItemImpl i
 
         if (primaryNodeTypeName == null) {
             // TODO retrieve matching nt from effective definition based on name-matching.
-            primaryNodeTypeName = JcrConstants.NT_UNSTRUCTURED;
+            primaryNodeTypeName = NodeType.NT_UNSTRUCTURED;
         }
 
+        // TODO: figure out the right place for this check
+        NodeTypeManager ntm = sessionContext.getNodeTypeManager();
+        NodeType nt = ntm.getNodeType(primaryNodeTypeName); // throws on not found
+        if (nt.isAbstract() || nt.isMixin()) {
+            throw new ConstraintViolationException();
+        }
+        // TODO: END
+        
         NodeDelegate added = dlg.addNode(toOakPath(relPath));
         Node childNode = new NodeImpl(added);
         childNode.setPrimaryType(primaryNodeTypeName);
@@ -471,8 +479,8 @@ public class NodeImpl extends ItemImpl i
     public String getUUID() throws RepositoryException {
         checkStatus();
 
-        if (hasProperty(JcrConstants.JCR_UUID) && isNodeType(JcrConstants.MIX_REFERENCEABLE))
{
-            return getProperty(JcrConstants.JCR_UUID).getString();
+        if (hasProperty(Property.JCR_UUID) && isNodeType(NodeType.MIX_REFERENCEABLE))
{
+            return getProperty(Property.JCR_UUID).getString();
         }
 
         throw new UnsupportedRepositoryOperationException("Node is not referenceable.");
@@ -574,9 +582,9 @@ public class NodeImpl extends ItemImpl i
         checkStatus();
 
         // TODO: check if transient changes to mixin-types are reflected here
-        if (hasProperty(JcrConstants.JCR_MIXINTYPES)) {
+        if (hasProperty(Property.JCR_MIXIN_TYPES)) {
             NodeTypeManager ntMgr = getSession().getWorkspace().getNodeTypeManager();
-            Value[] mixinNames = getProperty(JcrConstants.JCR_MIXINTYPES).getValues();
+            Value[] mixinNames = getProperty(Property.JCR_MIXIN_TYPES).getValues();
             NodeType[] mixinTypes = new NodeType[mixinNames.length];
             for (int i = 0; i < mixinNames.length; i++) {
                 mixinTypes[i] = ntMgr.getNodeType(mixinNames[i].getString());
@@ -615,7 +623,7 @@ public class NodeImpl extends ItemImpl i
         checkStatus();
 
         CoreValue cv = ValueConverter.toCoreValue(nodeTypeName, PropertyType.NAME, sessionContext);
-        dlg.setProperty(toOakPath(JcrConstants.JCR_PRIMARYTYPE), cv);
+        dlg.setProperty(toOakPath(Property.JCR_PRIMARY_TYPE), cv);
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionContext.java?rev=1333078&r1=1333077&r2=1333078&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionContext.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionContext.java
Wed May  2 15:38:05 2012
@@ -26,6 +26,7 @@ import org.apache.jackrabbit.oak.namepat
 
 import javax.jcr.RepositoryException;
 import javax.jcr.lock.LockManager;
+import javax.jcr.nodetype.NodeTypeManager;
 import javax.jcr.version.VersionManager;
 
 public interface SessionContext {
@@ -39,4 +40,5 @@ public interface SessionContext {
     Root getRoot();
     Tree getTree(String path);
     NamePathMapper getNamePathMapper();
+    NodeTypeManager getNodeTypeManager() throws RepositoryException;
 }

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=1333078&r1=1333077&r2=1333078&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
Wed May  2 15:38:05 2012
@@ -46,6 +46,7 @@ import javax.jcr.UnsupportedRepositoryOp
 import javax.jcr.ValueFactory;
 import javax.jcr.Workspace;
 import javax.jcr.lock.LockManager;
+import javax.jcr.nodetype.NodeTypeManager;
 import javax.jcr.retention.RetentionManager;
 import javax.jcr.security.AccessControlManager;
 import javax.jcr.version.VersionManager;
@@ -538,5 +539,10 @@ public class SessionImpl extends Abstrac
         public NamePathMapper getNamePathMapper() {
             return namePathMapper;
         }
+
+        @Override
+        public NodeTypeManager getNodeTypeManager() throws RepositoryException {
+            return getWorkspace().getNodeTypeManager();
+        }
     }
 }
\ No newline at end of file



Mime
View raw message