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 md...@apache.org on 2012/04/30 15:14:50 UTC
svn commit: r1332182 -
/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java
Author: mduerig
Date: Mon Apr 30 13:14:50 2012
New Revision: 1332182
URL: http://svn.apache.org/viewvc?rev=1332182&view=rev
Log:
OAK-18: Define Oak API
remove change lock based rebase() implementation in favour of diff based implementation
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java?rev=1332182&r1=1332181&r2=1332182&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java Mon Apr 30 13:14:50 2012
@@ -18,13 +18,11 @@
*/
package org.apache.jackrabbit.oak.core;
-import org.apache.jackrabbit.mk.api.MicroKernelException;
import org.apache.jackrabbit.oak.api.CommitFailedException;
import org.apache.jackrabbit.oak.api.CoreValue;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Root;
import org.apache.jackrabbit.oak.api.Tree;
-import org.apache.jackrabbit.oak.commons.PathUtils;
import org.apache.jackrabbit.oak.core.TreeImpl.Listener;
import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
import org.apache.jackrabbit.oak.spi.state.NodeState;
@@ -40,7 +38,6 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import static java.util.Collections.singletonList;
import static org.apache.jackrabbit.oak.commons.PathUtils.elements;
import static org.apache.jackrabbit.oak.commons.PathUtils.getName;
import static org.apache.jackrabbit.oak.commons.PathUtils.getParentPath;
@@ -117,13 +114,13 @@ public class RootImpl implements Root {
@Override
public void rebase() {
- rebase_DiffBased(true);
+ rebase(true);
}
@Override
public void commit() throws CommitFailedException {
store.apply(nodeStateBuilder);
- rebase_DiffBased(false);
+ rebase(false);
}
@Override
@@ -150,21 +147,7 @@ public class RootImpl implements Root {
return state;
}
- // TODO remove either of the two rebase methods and related stuff
- private void rebase_changeLogBased(boolean mergeChanges) {
- TreeListener changes = treeListener;
-
- treeListener = new TreeListener();
- base = store.getRoot().getChildNode(workspaceName);
- nodeStateBuilder = store.getBuilder(base);
- root = new TreeImpl(store, nodeStateBuilder, treeListener);
-
- if (mergeChanges) {
- merge(changes);
- }
- }
-
- private void rebase_DiffBased(boolean mergeChanges) {
+ private void rebase(boolean mergeChanges) {
NodeState oldBase;
NodeState oldHead;
if (mergeChanges) {
@@ -268,175 +251,48 @@ public class RootImpl implements Root {
return l;
}
- private void merge(TreeListener changes) {
- for (Operation operation : changes.getChanges()) {
- try {
- switch (operation.type) {
- case ADD_NODE: {
- String parentPath = PathUtils.getParentPath(operation.targetPath);
- String name = PathUtils.getName(operation.targetPath);
- getChild(parentPath).addChild(name);
- break;
- }
- case REMOVE_NODE: {
- String parentPath = PathUtils.getParentPath(operation.targetPath);
- String name = PathUtils.getName(operation.targetPath);
- getChild(parentPath).removeChild(name);
- break;
- }
- case SET_PROPERTY: {
- String parentPath = PathUtils.getParentPath(operation.targetPath);
- String name = PathUtils.getName(operation.targetPath);
- if (operation.isMultiple) {
- getChild(parentPath).setProperty(name, operation.values.get(0));
- }
- else {
- getChild(parentPath).setProperty(name, operation.values);
- }
- break;
- }
- case REMOVE_PROPERTY: {
- String parentPath = PathUtils.getParentPath(operation.targetPath);
- String name = PathUtils.getName(operation.targetPath);
- getChild(parentPath).removeProperty(name);
- break;
- }
- case MOVE: {
- move(operation.sourcePath, operation.targetPath);
- break;
- }
- case COPY: {
- copy(operation.sourcePath, operation.targetPath);
- break;
- }
- }
- }
- catch (MicroKernelException e) {
- log.warn("Skipping failed operation on refresh:" + operation);
- }
- }
- }
-
-
private static class TreeListener implements Listener {
- private final List<Operation> operations = new ArrayList<Operation>();
+ private boolean hasChanges;
@Override
public void addChild(TreeImpl parent, String name) {
- String targetPath = PathUtils.concat(parent.getPath(), name);
- operations.add(Operation.addNode(targetPath));
+ hasChanges = true;
}
@Override
public void removeChild(TreeImpl parent, String name) {
- String targetPath = PathUtils.concat(parent.getPath(), name);
- operations.add(Operation.removeNode(targetPath));
+ hasChanges = true;
}
@Override
public void setProperty(TreeImpl parent, String name, CoreValue value) {
- String targetPath = PathUtils.concat(parent.getPath(), name);
- operations.add(Operation.setProperty(targetPath, value));
+ hasChanges = true;
}
@Override
public void setProperty(TreeImpl parent, String name, List<CoreValue> values) {
- String targetPath = PathUtils.concat(parent.getPath(), name);
- operations.add(Operation.setProperty(targetPath, values));
+ hasChanges = true;
}
@Override
public void removeProperty(TreeImpl parent, String name) {
- String targetPath = PathUtils.concat(parent.getPath(), name);
- operations.add(Operation.removeProperty(targetPath));
+ hasChanges = true;
}
@Override
public void move(TreeImpl sourceParent, String sourceName, TreeImpl moved) {
- String sourcePath = PathUtils.concat(sourceParent.getPath(), sourceName);
- operations.add(Operation.move(sourcePath, moved.getPath()));
+ hasChanges = true;
}
@Override
public void copy(TreeImpl sourceParent, String sourceName, TreeImpl copied) {
- String sourcePath = PathUtils.concat(sourceParent.getPath(), sourceName);
- operations.add(Operation.copy(sourcePath, copied.getPath()));
+ hasChanges = true;
}
boolean hasChanges() {
- return !operations.isEmpty();
- }
-
- List<Operation> getChanges() {
- return operations;
- }
- }
-
- private static class Operation {
- final Type type;
- final String targetPath;
- final String sourcePath;
- final List<CoreValue> values;
- final boolean isMultiple;
-
- enum Type {ADD_NODE, REMOVE_NODE, SET_PROPERTY, REMOVE_PROPERTY, MOVE, COPY}
-
- private Operation(Type type, String targetPath, String sourcePath,
- List<CoreValue> values, boolean isMultiple) {
-
- this.type = type;
- this.targetPath = targetPath;
- this.sourcePath = sourcePath;
- this.values = values;
- this.isMultiple = isMultiple;
- }
-
- static Operation addNode(String targetPath) {
- return new Operation(Type.ADD_NODE, targetPath, null, null, false);
- }
-
- static Operation removeNode(String targetPath) {
- return new Operation(Type.REMOVE_NODE, targetPath, null, null, false);
- }
-
- static Operation setProperty(String targetPath, CoreValue value) {
- return new Operation(Type.SET_PROPERTY, targetPath, null, singletonList(value), false);
- }
-
- static Operation setProperty(String targetPath, List<CoreValue> values) {
- return new Operation(Type.SET_PROPERTY, targetPath, null, values, true);
- }
-
- static Operation removeProperty(String targetPath) {
- return new Operation(Type.REMOVE_PROPERTY, targetPath, null, null, false);
- }
-
- static Operation move(String sourcePath, String targetPath) {
- return new Operation(Type.MOVE, targetPath, sourcePath, null, false);
- }
-
- static Operation copy(String sourcePath, String targetPath) {
- return new Operation(Type.COPY, targetPath, sourcePath, null, false);
+ return hasChanges;
}
- @Override
- public String toString() {
- switch (type) {
- case ADD_NODE:
- return '+' + targetPath + ":{}";
- case REMOVE_NODE:
- return '-' + targetPath;
- case SET_PROPERTY:
- return '^' + targetPath + ':' + (isMultiple ? values : values.get(0));
- case REMOVE_PROPERTY:
- return '^' + targetPath + ":null";
- case MOVE:
- return '>' + sourcePath + ':' + targetPath;
- case COPY:
- return '*' + sourcePath + ':' + targetPath;
- }
- throw new IllegalStateException("We should never get here");
- }
}
}