Author: chetanm
Date: Wed Jul 20 05:10:33 2016
New Revision: 1753439

URL: http://svn.apache.org/viewvc?rev=1753439&view=rev
Log:
OAK-4567 - Define oak:Resource nodetype as non referenceable alternative to 
nt:resource

Apply updated patch from Angela

Modified:
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeTypeConstants.java
    
jackrabbit/oak/trunk/oak-core/src/main/resources/org/apache/jackrabbit/oak/plugins/nodetype/write/builtin_nodetypes.cnd
    
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/nodetype/write/NodeTypeRegistryTest.java
    jackrabbit/oak/trunk/oak-doc/src/site/markdown/dos_and_donts.md

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeTypeConstants.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeTypeConstants.java?rev=1753439&r1=1753438&r2=1753439&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeTypeConstants.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeTypeConstants.java
 Wed Jul 20 05:10:33 2016
@@ -46,6 +46,10 @@ public interface NodeTypeConstants exten
      * @since oak 1.0
      */
     String NT_OAK_UNSTRUCTURED = "oak:Unstructured";
+    /**
+     * @since oak 1.5.7
+     */
+    String NT_OAK_RESOURCE = "oak:Resource";
 
     String NT_REP_NODE_TYPE = "rep:NodeType";
     String NT_REP_NAMED_PROPERTY_DEFINITIONS = "rep:NamedPropertyDefinitions";

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/resources/org/apache/jackrabbit/oak/plugins/nodetype/write/builtin_nodetypes.cnd
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/resources/org/apache/jackrabbit/oak/plugins/nodetype/write/builtin_nodetypes.cnd?rev=1753439&r1=1753438&r2=1753439&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/resources/org/apache/jackrabbit/oak/plugins/nodetype/write/builtin_nodetypes.cnd
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/resources/org/apache/jackrabbit/oak/plugins/nodetype/write/builtin_nodetypes.cnd
 Wed Jul 20 05:10:33 2016
@@ -53,7 +53,7 @@
  * jcr:content. The jcr:content node is used to hold the actual content of the
  * file. This child node is mandatory, but not auto-created. Its node type 
will be
  * application-dependent and therefore it must be added by the user. A common
- * approach is to make the jcr:content a node of type nt:resource. The
+ * approach is to make the jcr:content a node of type nt:resource or 
oak:Resource. The
  * jcr:content child node is also designated as the primary child item of its 
parent.
  *
  * @since 1.0
@@ -97,6 +97,16 @@
   primaryitem jcr:data
   - jcr:data (BINARY) mandatory
 
+/**
+ * This node type may be used to represent the content of a file. This should 
be
+ * preferred over nt:resource if non referenceable nt:file nodes are required
+ *
+ * @since 1.5.6
+ */
+[oak:Resource] > mix:mimeType, mix:lastModified
+  primaryitem jcr:data
+  - jcr:data (BINARY) mandatory
+
 /**
  * This mixin node type can be used to add standardized title and description
  * properties to a node.

Modified: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/nodetype/write/NodeTypeRegistryTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/nodetype/write/NodeTypeRegistryTest.java?rev=1753439&r1=1753438&r2=1753439&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/nodetype/write/NodeTypeRegistryTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/nodetype/write/NodeTypeRegistryTest.java
 Wed Jul 20 05:10:33 2016
@@ -23,7 +23,16 @@ import static org.apache.jackrabbit.JcrC
 import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
 import static org.apache.jackrabbit.JcrConstants.NT_FOLDER;
 import static org.apache.jackrabbit.JcrConstants.NT_UNSTRUCTURED;
+import static org.apache.jackrabbit.JcrConstants.JCR_CONTENT;
+import static org.apache.jackrabbit.JcrConstants.JCR_DATA;
+import static org.apache.jackrabbit.JcrConstants.JCR_LASTMODIFIED;
+import static org.apache.jackrabbit.JcrConstants.JCR_UUID;
+import static org.apache.jackrabbit.JcrConstants.NT_FILE;
+import static org.apache.jackrabbit.JcrConstants.NT_RESOURCE;
 import static org.apache.jackrabbit.oak.api.Type.NAME;
+import static 
org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.JCR_LASTMODIFIEDBY;
+import static 
org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.NODE_TYPES_PATH;
+import static 
org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.NT_OAK_RESOURCE;
 import static 
org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.MIX_INDEXABLE;
 
 import java.io.Closeable;
@@ -34,7 +43,7 @@ import javax.annotation.Nonnull;
 import javax.jcr.NoSuchWorkspaceException;
 import javax.security.auth.login.LoginException;
 
-import org.apache.jackrabbit.JcrConstants;
+import com.google.common.base.Strings;
 import org.apache.jackrabbit.oak.Oak;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.ContentRepository;
@@ -42,15 +51,16 @@ import org.apache.jackrabbit.oak.api.Con
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.api.Type;
-import org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants;
 import org.apache.jackrabbit.oak.plugins.nodetype.TypeEditorProvider;
 import org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider;
+import org.apache.jackrabbit.oak.util.TreeUtil;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
-import com.google.common.base.Strings;
-import com.google.common.collect.ImmutableList;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 
 public class NodeTypeRegistryTest {
     private ContentRepository repository = null;
@@ -113,4 +123,33 @@ public class NodeTypeRegistryTest {
         test.addChild("oak:index").setProperty(JCR_PRIMARYTYPE, 
NT_UNSTRUCTURED, NAME);
         root.commit();
     }
+
+    @Test
+    public void oakResource() throws Exception{
+        registerNodeType(root, "builtin_nodetypes.cnd");
+        Tree typeRoot = root.getTree(NODE_TYPES_PATH);
+        Tree test1 = TreeUtil.addChild(root.getTree("/"), "test1", NT_FILE, 
typeRoot, "admin");
+        Tree content1 = TreeUtil.addChild(test1, JCR_CONTENT, NT_OAK_RESOURCE, 
typeRoot, "admin");
+        content1.setProperty(JCR_DATA, "hello".getBytes());
+
+        Tree test2 = TreeUtil.addChild(root.getTree("/"), "test2", NT_FILE, 
typeRoot, "admin");
+        Tree content2 = TreeUtil.addChild(test2, JCR_CONTENT, NT_RESOURCE, 
typeRoot, "admin");
+        content2.setProperty(JCR_DATA, "hello".getBytes());
+        root.commit();
+
+        test1 = root.getTree("/").addChild("test1");
+
+        
assertTrue(test1.getChild(JCR_CONTENT).hasProperty(JCR_LASTMODIFIEDBY));
+        assertTrue(test1.getChild(JCR_CONTENT).hasProperty(JCR_LASTMODIFIED));
+
+        //For oak:Resource the uuid property should not get generated
+        assertFalse(test1.getChild(JCR_CONTENT).hasProperty(JCR_UUID));
+
+        test2 = root.getTree("/").addChild("test2");
+
+        
assertTrue(test2.getChild(JCR_CONTENT).hasProperty(JCR_LASTMODIFIEDBY));
+        assertTrue(test2.getChild(JCR_CONTENT).hasProperty(JCR_LASTMODIFIED));
+        assertTrue(test2.getChild(JCR_CONTENT).hasProperty(JCR_UUID));
+
+    }
 }

Modified: jackrabbit/oak/trunk/oak-doc/src/site/markdown/dos_and_donts.md
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-doc/src/site/markdown/dos_and_donts.md?rev=1753439&r1=1753438&r2=1753439&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-doc/src/site/markdown/dos_and_donts.md (original)
+++ jackrabbit/oak/trunk/oak-doc/src/site/markdown/dos_and_donts.md Wed Jul 20 
05:10:33 2016
@@ -78,6 +78,16 @@ might hit some limit causing the commit
 8k for any inlined binary value. Further this would also lead to repository 
growth as
 by default when binaries are stored in BlobStore then they are deduplicated.
 
+### Creating files
+
+The default node type provided by JCR 1.0 to model file structure using
+`nt:file` is to add `jcr:content` child with type `nt:resource`, which makes
+that content referenceable.
+
+If the file has no need to be referenceable it is recommended to use the
+node type `oak:Resource` instead and add the mixin type `mix:referenceble`
+only upon demand (see 
[OAK-4567](https://issues.apache.org/jira/browse/OAK-4567))
+
 ### Don't use Thread.interrupt()
 
 `Thread.interrupt()` can severely impact or even stop the repository. The 
reason for 


Reply via email to