Author: jukka
Date: Thu Mar 6 18:59:56 2014
New Revision: 1575006
URL: http://svn.apache.org/r1575006
Log:
OAK-1518: Relaxed type checking during upgrade
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveType.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeEditor.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeEditorProvider.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeEditorTest.java
jackrabbit/oak/trunk/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgrade.java
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveType.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveType.java?rev=1575006&r1=1575005&r2=1575006&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveType.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveType.java
Thu Mar 6 18:59:56 2014
@@ -21,7 +21,6 @@ import java.util.Set;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
-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.spi.state.ChildNodeEntry;
@@ -40,7 +39,6 @@ import static org.apache.jackrabbit.JcrC
import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
import static org.apache.jackrabbit.JcrConstants.JCR_SAMENAMESIBLINGS;
import static org.apache.jackrabbit.JcrConstants.JCR_UUID;
-import static org.apache.jackrabbit.oak.api.CommitFailedException.CONSTRAINT;
import static org.apache.jackrabbit.oak.api.Type.UNDEFINED;
import static org.apache.jackrabbit.oak.api.Type.UNDEFINEDS;
import static org.apache.jackrabbit.oak.commons.PathUtils.dropIndexFromName;
@@ -60,12 +58,6 @@ class EffectiveType {
this.types = checkNotNull(types);
}
- CommitFailedException constraintViolation(
- int code, String path, String message) {
- return new CommitFailedException(
- CONSTRAINT, code, path + this + ": " + message);
- }
-
/**
* Checks whether this effective type contains the named type.
*
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeEditor.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeEditor.java?rev=1575006&r1=1575005&r2=1575006&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeEditor.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeEditor.java
Thu Mar 6 18:59:56 2014
@@ -66,6 +66,8 @@ class TypeEditor extends DefaultEditor {
private static final Logger log =
LoggerFactory.getLogger(TypeEditor.class);
+ private final boolean strict;
+
private final TypeEditor parent;
private final String nodeName;
@@ -77,9 +79,10 @@ class TypeEditor extends DefaultEditor {
private final NodeBuilder builder;
TypeEditor(
- NodeState types,
+ boolean strict, NodeState types,
String primary, Iterable<String> mixins, NodeBuilder builder)
throws CommitFailedException {
+ this.strict = strict;
this.parent = null;
this.nodeName = null;
this.types = checkNotNull(types);
@@ -91,6 +94,7 @@ class TypeEditor extends DefaultEditor {
TypeEditor parent, String name,
String primary, Iterable<String> mixins, NodeBuilder builder)
throws CommitFailedException {
+ this.strict = parent.strict;
this.parent = checkNotNull(parent);
this.nodeName = checkNotNull(name);
this.types = parent.types;
@@ -103,6 +107,7 @@ class TypeEditor extends DefaultEditor {
* Test constructor.
*/
TypeEditor(EffectiveType effective) {
+ this.strict = true;
this.parent = null;
this.nodeName = null;
this.types = EMPTY_NODE;
@@ -110,13 +115,25 @@ class TypeEditor extends DefaultEditor {
this.builder = EMPTY_NODE.builder();
}
- private CommitFailedException constraintViolation(
- int code, String message) {
+ /**
+ * Throws or logs the specified constraint violation.
+ *
+ * @param code code of this violation
+ * @param message description of the violation
+ * @throws CommitFailedException the constraint violation
+ */
+ private void constraintViolation(int code, String message)
+ throws CommitFailedException {
+ String path = getPath();
if (effective != null) {
- return effective.constraintViolation(code, getPath(), message);
+ path = path + "[" + effective + "]";
+ }
+ CommitFailedException exception = new CommitFailedException(
+ CONSTRAINT, code, path + ": " + message);
+ if (strict) {
+ throw exception;
} else {
- return new CommitFailedException(
- CONSTRAINT, 0, getPath() + ": " + message);
+ log.warn(exception.getMessage());
}
}
@@ -141,14 +158,14 @@ class TypeEditor extends DefaultEditor {
throws CommitFailedException {
NodeState definition = effective.getDefinition(after);
if (definition == null) {
- throw constraintViolation(
+ constraintViolation(
4, "No matching property definition found for " + after);
} else if (JCR_UUID.equals(after.getName())
&& effective.isNodeType(MIX_REFERENCEABLE)) {
// special handling for the jcr:uuid property of mix:referenceable
// TODO: this should be done in a pluggable extension
if (!isValidUUID(after.getValue(Type.STRING))) {
- throw constraintViolation(
+ constraintViolation(
12, "Invalid UUID value in the jcr:uuid property");
}
} else {
@@ -161,7 +178,7 @@ class TypeEditor extends DefaultEditor {
throws CommitFailedException {
String name = before.getName();
if (effective.isMandatoryProperty(name)) {
- throw constraintViolation(
+ constraintViolation(
22, "Mandatory property " + name + " can not be removed");
}
}
@@ -176,14 +193,14 @@ class TypeEditor extends DefaultEditor {
// verify the presence of all mandatory items
for (String property : editor.effective.getMandatoryProperties()) {
if (!after.hasProperty(property)) {
- throw editor.constraintViolation(
+ editor.constraintViolation(
21, "Mandatory property " + property
+ " not found in a new node");
}
}
for (String child : editor.effective.getMandatoryChildNodes()) {
if (!after.hasChildNode(child)) {
- throw editor.constraintViolation(
+ editor.constraintViolation(
25, "Mandatory child node " + child
+ " not found in a new node");
}
@@ -206,7 +223,7 @@ class TypeEditor extends DefaultEditor {
if (primary != null) {
builder.setProperty(JCR_PRIMARYTYPE, primary, NAME);
} else {
- throw constraintViolation(
+ constraintViolation(
4, "No default primary type available "
+ " for child node " + name);
}
@@ -215,7 +232,7 @@ class TypeEditor extends DefaultEditor {
TypeEditor editor =
new TypeEditor(this, name, primary, mixins, childBuilder);
if (!effective.isValidChildNode(name, editor.effective)) {
- throw constraintViolation(
+ constraintViolation(
1, "No matching definition found for child node " + name
+ " with effective type " + editor.effective);
}
@@ -227,11 +244,10 @@ class TypeEditor extends DefaultEditor {
public Editor childNodeDeleted(String name, NodeState before)
throws CommitFailedException {
if (effective.isMandatoryChildNode(name)) {
- throw constraintViolation(
+ constraintViolation(
26, "Mandatory child node " + name + " can not be
removed");
- } else {
- return null; // no further checking needed for the removed subtree
}
+ return null; // no further checking needed for the removed subtree
}
//-----------------------------------------------------------< private >--
@@ -244,10 +260,10 @@ class TypeEditor extends DefaultEditor {
NodeState type = types.getChildNode(primary);
if (!type.exists()) {
- throw constraintViolation(
+ constraintViolation(
1, "The primary type " + primary + " does not exist");
} else if (type.getBoolean(JCR_ISMIXIN)) {
- throw constraintViolation(
+ constraintViolation(
2, "Mixin type " + primary + " used as the primary type");
} else {
if (type.getBoolean(JCR_IS_ABSTRACT)) {
@@ -258,7 +274,7 @@ class TypeEditor extends DefaultEditor {
+ " used as the default primary type of node "
+ getPath());
} else {
- throw constraintViolation(
+ constraintViolation(
2, "Abstract type " + primary + " used as the
primary type");
}
}
@@ -269,13 +285,13 @@ class TypeEditor extends DefaultEditor {
for (String mixin : mixins) {
type = types.getChildNode(mixin);
if (!type.exists()) {
- throw constraintViolation(
+ constraintViolation(
5, "The mixin type " + mixin + " does not exist");
} else if (!type.getBoolean(JCR_ISMIXIN)) {
- throw constraintViolation(
+ constraintViolation(
6, "Primary type " + mixin + " used as a mixin type");
} else if (type.getBoolean(JCR_IS_ABSTRACT)) {
- throw constraintViolation(
+ constraintViolation(
7, "Abstract type " + mixin + " used as a mixin type");
} else {
list.add(type);
@@ -341,7 +357,7 @@ class TypeEditor extends DefaultEditor {
}
}
}
- throw constraintViolation(5, "Value constraint violation in " +
property);
+ constraintViolation(5, "Value constraint violation in " + property);
}
}
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeEditorProvider.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeEditorProvider.java?rev=1575006&r1=1575005&r2=1575006&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeEditorProvider.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeEditorProvider.java
Thu Mar 6 18:59:56 2014
@@ -41,6 +41,16 @@ import org.apache.jackrabbit.oak.spi.sta
@Service(EditorProvider.class)
public class TypeEditorProvider implements EditorProvider {
+ private final boolean strict;
+
+ public TypeEditorProvider(boolean strict) {
+ this.strict = strict;
+ }
+
+ public TypeEditorProvider() {
+ this(true);
+ }
+
@Override
public Editor getRootEditor(
NodeState before, NodeState after, NodeBuilder builder,
@@ -68,7 +78,7 @@ public class TypeEditorProvider implemen
}
Editor editor = new VisibleEditor(
- new TypeEditor(afterTypes, primary, mixins, builder));
+ new TypeEditor(strict, afterTypes, primary, mixins, builder));
if (modifiedTypes.isEmpty()) {
return editor;
} else {
Modified:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeEditorTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeEditorTest.java?rev=1575006&r1=1575005&r2=1575006&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeEditorTest.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeEditorTest.java
Thu Mar 6 18:59:56 2014
@@ -73,9 +73,6 @@ public class TypeEditorTest {
public void removeMandatoryProperty() throws CommitFailedException {
EffectiveType effective =
createControl().createMock(EffectiveType.class);
expect(effective.isMandatoryProperty("mandatory")).andReturn(true);
- expect(effective.constraintViolation(
- 22, "/", "Mandatory property mandatory can not be removed"))
- .andReturn(new CommitFailedException("", 0, ""));
replay(effective);
@@ -98,9 +95,6 @@ public class TypeEditorTest {
public void removeMandatoryChildNode() throws CommitFailedException {
EffectiveType effective =
createControl().createMock(EffectiveType.class);
expect(effective.isMandatoryChildNode("mandatory")).andReturn(true);
- expect(effective.constraintViolation(
- 26, "/", "Mandatory child node mandatory can not be removed"))
- .andReturn(new CommitFailedException("", 0, ""));
replay(effective);
Modified:
jackrabbit/oak/trunk/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgrade.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgrade.java?rev=1575006&r1=1575005&r2=1575006&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgrade.java
(original)
+++
jackrabbit/oak/trunk/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/RepositoryUpgrade.java
Thu Mar 6 18:59:56 2014
@@ -233,7 +233,7 @@ public class RepositoryUpgrade {
CommitHook hook = new CompositeHook(
new EditorHook(new GroupEditorProvider(groupsPath)),
new EditorHook(new CompositeEditorProvider(
- new TypeEditorProvider(),
+ new TypeEditorProvider(false),
new IndexUpdateProvider(new
CompositeIndexEditorProvider(
new ReferenceEditorProvider(),
new PropertyIndexEditorProvider())))));