Return-Path: X-Original-To: apmail-jackrabbit-oak-commits-archive@minotaur.apache.org Delivered-To: apmail-jackrabbit-oak-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id DE898C170 for ; Mon, 30 Apr 2012 13:15:15 +0000 (UTC) Received: (qmail 34363 invoked by uid 500); 30 Apr 2012 13:15:15 -0000 Delivered-To: apmail-jackrabbit-oak-commits-archive@jackrabbit.apache.org Received: (qmail 34344 invoked by uid 500); 30 Apr 2012 13:15:15 -0000 Mailing-List: contact oak-commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: oak-commits@jackrabbit.apache.org Delivered-To: mailing list oak-commits@jackrabbit.apache.org Received: (qmail 34332 invoked by uid 99); 30 Apr 2012 13:15:15 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 30 Apr 2012 13:15:15 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 30 Apr 2012 13:15:12 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id BA0442388962; Mon, 30 Apr 2012 13:14:50 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1332182 - /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java Date: Mon, 30 Apr 2012 13:14:50 -0000 To: oak-commits@jackrabbit.apache.org From: mduerig@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120430131450.BA0442388962@eris.apache.org> 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 operations = new ArrayList(); + 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 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 getChanges() { - return operations; - } - } - - private static class Operation { - final Type type; - final String targetPath; - final String sourcePath; - final List 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 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 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"); - } } }