You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by mr...@apache.org on 2020/12/02 14:25:14 UTC
svn commit: r1884037 - in /jackrabbit/oak/trunk/oak-core/src:
main/java/org/apache/jackrabbit/oak/plugins/version/
test/java/org/apache/jackrabbit/oak/
test/java/org/apache/jackrabbit/oak/plugins/version/
Author: mreutegg
Date: Wed Dec 2 14:25:13 2020
New Revision: 1884037
URL: http://svn.apache.org/viewvc?rev=1884037&view=rev
Log:
OAK-9291: Refactor check for referenceable nt:frozenNode definition
Added:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/version/UtilsTest.java (with props)
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/Utils.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionableState.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/InitialContentHelper.java
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/Utils.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/Utils.java?rev=1884037&r1=1884036&r2=1884037&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/Utils.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/Utils.java Wed Dec 2 14:25:13 2020
@@ -18,22 +18,36 @@
*/
package org.apache.jackrabbit.oak.plugins.version;
+import javax.jcr.RepositoryException;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
+import javax.jcr.nodetype.NodeType;
+
import static com.google.common.base.Preconditions.checkNotNull;
import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
import static org.apache.jackrabbit.JcrConstants.JCR_UUID;
+import static org.apache.jackrabbit.JcrConstants.MIX_REFERENCEABLE;
+import static org.apache.jackrabbit.JcrConstants.NT_FROZENNODE;
import static org.apache.jackrabbit.oak.api.CommitFailedException.CONSTRAINT;
import org.apache.jackrabbit.oak.api.CommitFailedException;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.namepath.NamePathMapper;
+import org.apache.jackrabbit.oak.plugins.nodetype.ReadOnlyNodeTypeManager;
+import org.apache.jackrabbit.oak.plugins.tree.factories.RootFactory;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
import org.apache.jackrabbit.oak.spi.state.NodeState;
import org.jetbrains.annotations.NotNull;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* {@code Utils} provide some utility methods.
*/
-final class Utils {
+public final class Utils {
+
+ private static final Logger LOG = LoggerFactory.getLogger(Utils.class);
+
private Utils() {
}
@@ -78,6 +92,47 @@ final class Utils {
return primaryType;
}
+ /**
+ * Returns {@code true} iff there is a {@code nt:frozenNode} definition and
+ * the definition has a {@code mix:referenceable} supertype.
+ *
+ * @param root the root of a repository from where to read the node type
+ * information.
+ * @return {@code true} if frozen nodes are referenceable, {@code false}
+ * otherwise.
+ */
+ public static boolean isFrozenNodeReferenceable(@NotNull NodeState root) {
+ return isFrozenNodeReferenceable(
+ ReadOnlyNodeTypeManager.getInstance(
+ RootFactory.createReadOnlyRoot(root),
+ NamePathMapper.DEFAULT));
+ }
+
+ /**
+ * Returns {@code true} iff there is a {@code nt:frozenNode} definition and
+ * the definition has a {@code mix:referenceable} supertype.
+ *
+ * @param ntMgr a node type manager to access the node types.
+ * @return {@code true} if frozen nodes are referenceable, {@code false}
+ * otherwise.
+ */
+ public static boolean isFrozenNodeReferenceable(@NotNull ReadOnlyNodeTypeManager ntMgr) {
+ try {
+ NodeType[] superTypes = ntMgr.getNodeType(NT_FROZENNODE).getSupertypes();
+ for (NodeType superType : superTypes) {
+ if (superType.isNodeType(MIX_REFERENCEABLE)) {
+ // OAK-9134: add uuid in older repositories with mix:referenceable in nt:frozenNode
+ return true;
+ }
+ }
+ } catch (NoSuchNodeTypeException e) {
+ LOG.info("Repository does not define nt:frozenNode. Assuming frozen nodes are not referenceable.");
+ } catch (RepositoryException e) {
+ throw new RuntimeException(e);
+ }
+ return false;
+ }
+
static <T> T throwProtected(String path) throws CommitFailedException {
throw new CommitFailedException(CONSTRAINT, 100,
"Item is protected: " + path);
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionableState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionableState.java?rev=1884037&r1=1884036&r2=1884037&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionableState.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/VersionableState.java Wed Dec 2 14:25:13 2020
@@ -37,7 +37,6 @@ import static org.apache.jackrabbit.JcrC
import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
import static org.apache.jackrabbit.JcrConstants.JCR_UUID;
import static org.apache.jackrabbit.JcrConstants.JCR_VERSIONHISTORY;
-import static org.apache.jackrabbit.JcrConstants.MIX_REFERENCEABLE;
import static org.apache.jackrabbit.JcrConstants.MIX_VERSIONABLE;
import static org.apache.jackrabbit.JcrConstants.NT_FROZENNODE;
import static org.apache.jackrabbit.JcrConstants.NT_VERSIONEDCHILD;
@@ -51,7 +50,6 @@ import java.util.Set;
import javax.jcr.RepositoryException;
import javax.jcr.Value;
-import javax.jcr.nodetype.NodeType;
import javax.jcr.nodetype.PropertyDefinition;
import javax.jcr.version.OnParentVersionAction;
@@ -124,21 +122,7 @@ class VersionableState {
this.versionable = checkNotNull(versionable);
this.vMgr = checkNotNull(vMgr);
this.ntMgr = checkNotNull(ntMgr);
-
- boolean referenceableFound = false;
- try {
- NodeType[] superTypes = ntMgr.getNodeType(NT_FROZENNODE).getSupertypes();
- for (NodeType superType : superTypes) {
- if (superType.isNodeType(MIX_REFERENCEABLE)) {
- // OAK-9134: add uuid in older repositories with mix:referenceable in nt:frozenNode
- referenceableFound = true;
- break;
- }
- }
- } catch (RepositoryException e) {
- log.warn("Unable to access node type " + NT_FROZENNODE, e);
- }
- this.isFrozenNodeReferenceable = referenceableFound;
+ this.isFrozenNodeReferenceable = Utils.isFrozenNodeReferenceable(ntMgr);
}
/**
Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/InitialContentHelper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/InitialContentHelper.java?rev=1884037&r1=1884036&r2=1884037&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/InitialContentHelper.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/InitialContentHelper.java Wed Dec 2 14:25:13 2020
@@ -29,14 +29,32 @@ import org.apache.jackrabbit.oak.spi.sta
*/
public class InitialContentHelper {
- public static final NodeState INITIAL_CONTENT = createInitialContent();
+ public static final NodeState INITIAL_CONTENT = createInitialContent(false);
- private static NodeState createInitialContent() {
- NodeStore store = new MemoryNodeStore();
- EditorHook hook = new EditorHook(
- new CompositeEditorProvider(new NamespaceEditorProvider(), new TypeEditorProvider()));
- OakInitializer.initialize(store, new InitialContent(), hook);
- return store.getRoot();
+ public static final NodeState INITIAL_CONTENT_FROZEN_NODE_REFERENCEABLE = createInitialContent(true);
+
+ private static final String REFERENCEABLE_FROZEN_NODE_PROPERTY = "oak.referenceableFrozenNode";
+
+ private static NodeState createInitialContent(boolean referenceableFrozenNodes) {
+ String propValue = System.getProperty(REFERENCEABLE_FROZEN_NODE_PROPERTY);
+ if (referenceableFrozenNodes) {
+ System.setProperty(REFERENCEABLE_FROZEN_NODE_PROPERTY, "true");
+ } else {
+ System.clearProperty(REFERENCEABLE_FROZEN_NODE_PROPERTY);
+ }
+ try {
+ NodeStore store = new MemoryNodeStore();
+ EditorHook hook = new EditorHook(
+ new CompositeEditorProvider(new NamespaceEditorProvider(), new TypeEditorProvider()));
+ OakInitializer.initialize(store, new InitialContent(), hook);
+ return store.getRoot();
+ } finally {
+ if (propValue != null) {
+ System.setProperty(REFERENCEABLE_FROZEN_NODE_PROPERTY, propValue);
+ } else {
+ System.clearProperty(REFERENCEABLE_FROZEN_NODE_PROPERTY);
+ }
+ }
}
private InitialContentHelper() {}
Added: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/version/UtilsTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/version/UtilsTest.java?rev=1884037&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/version/UtilsTest.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/version/UtilsTest.java Wed Dec 2 14:25:13 2020
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.plugins.version;
+
+import org.apache.jackrabbit.oak.InitialContentHelper;
+import org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState;
+import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore;
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class UtilsTest {
+
+ @Test
+ public void frozenNodeReferenceable() {
+ assertTrue(Utils.isFrozenNodeReferenceable(InitialContentHelper.INITIAL_CONTENT_FROZEN_NODE_REFERENCEABLE));
+ }
+
+ @Test
+ public void frozenNodeNotReferenceable() {
+ assertFalse(Utils.isFrozenNodeReferenceable(InitialContentHelper.INITIAL_CONTENT));
+ }
+
+ @Test
+ public void frozenNodeDefinitionMissing() {
+ // assume empty repository on recent Oak without referenceable nt:frozenNode
+ assertFalse(Utils.isFrozenNodeReferenceable(EmptyNodeState.EMPTY_NODE));
+ }
+}
Propchange: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/version/UtilsTest.java
------------------------------------------------------------------------------
svn:eol-style = native