[ 
https://issues.apache.org/jira/browse/OAK-9134?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17159941#comment-17159941
 ] 

Marcel Reutegger commented on OAK-9134:
---------------------------------------

bq. edits internally the inputStream of the builtin_nodetypes.cnd file, which I 
don't think is an elegant solution

I don't have a better solution. It may not be perfect, but gets the job done.

Just a few suggestions.

There is an easier way than this:
{noformat}
            boolean referenceableFrozenNode = 
Boolean.parseBoolean(System.getProperty("oak.referenceableFrozenNode"));
{noformat}
Instead use:
{noformat}
            boolean referenceableFrozenNode = 
Boolean.getBoolean("oak.referenceableFrozenNode");
{noformat}

Use StringBuilder Instead of StringBuffer. The latter is thread-safe, which is 
not necessary in this case.

The InputStreamReader in the if clause should also use predefined encoding 
UTF-8.

When the InputStream is 'rewritten', a {{BufferedInputStream}} is created. I 
don't think this is necessary.

As an alternative, the following may also work:
{noformat}
@@ -89,9 +93,24 @@
 
     private void registerNodeTypes(InputStream stream, String systemId) {
         try {
-            CndImporter.registerNodeTypes(
-                    new InputStreamReader(stream, Charsets.UTF_8),
-                    systemId, ntMgr, nsReg, vf, false);
+            Reader reader = new InputStreamReader(stream, Charsets.UTF_8);
+            // OAK-9134: nt:frozenNode is not implementing mix:referenceable 
from JCR 2.0.
+            // This system property allows to add it back when initializing a 
repository.
+            boolean referenceableFrozenNode = 
Boolean.getBoolean("oak.referenceableFrozenNode");
+            if (referenceableFrozenNode) {
+                BufferedReader bufferedReader = new BufferedReader(reader);
+                StringBuilder result = new StringBuilder();
+                String line;
+                while ((line = bufferedReader.readLine()) != null) {
+                    if (line.trim().equals("[nt:frozenNode]")) {
+                        line = "[nt:frozenNode] > mix:referenceable";
+                    }
+                    result.append(line).append(System.lineSeparator());
+                }
+                reader = new StringReader(result.toString());
+            }
+
+            CndImporter.registerNodeTypes(reader, systemId, ntMgr, nsReg, vf, 
false);
         } catch (IOException e) {
             throw new IllegalStateException("Unable to read " + systemId, e);
         } catch (ParseException e) {
{noformat}

WDYT?

The class {{ReferenceableFrozenNodeTest}} has a comment that does not match. It 
was probably copied from an existing test.

I would not catch the {{CommitFailedException}} in {{initializeRepository()}} 
or is there a particular reason?

Clearing the system property could be moved to a {{@After}} method. That would 
also ensure it is cleared when the test fails.

Can you add a test that creates a repository with referenceable nt:frozenNodes 
and then initialize it again without the system property set? The test would 
verify the node type definition does not change on an existing repository.

> Remove mix:referenceable from nt:frozenNode definition
> ------------------------------------------------------
>
>                 Key: OAK-9134
>                 URL: https://issues.apache.org/jira/browse/OAK-9134
>             Project: Jackrabbit Oak
>          Issue Type: Improvement
>          Components: core, jcr
>            Reporter: José Andrés Cordero Benítez
>            Priority: Minor
>              Labels: patch
>         Attachments: OAK-9134-remove-referenceable-from-test.patch, 
> OAK-9134-remove-referenceable-frozenNode-2.patch, 
> OAK-9134-remove-referenceable-frozenNode.patch
>
>
> One of the changes between JCR 1.0 and JCR 2.0 is the definition of 
> nt:frozenNode. In JCR 1.0 the node type extends from mix:referenceable, while 
> in JCR 2.0 it does [not 
> anymore|https://docs.adobe.com/docs/en/spec/jcr/2.0/3_Repository_Model.html#3.13.4.1%20nt:frozenNode].
> Oak currently uses a nt:frozenNode definition that extends from 
> mix:referenceable. This adds quite a bit of overhead because each node 
> written under a JCR version gets a jcr:uuid, which is indexed by default.
> The proposal is to remove the supertype "mix:referenceable" from 
> nt:frozenNode.
> Removing this supertype, the frozenNodes wouldn't have a "jcr:uuid" field, 
> which at the end is not used, and allows to reduce the size of the index.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to