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 st...@apache.org on 2012/05/16 11:03:50 UTC
svn commit: r1339069 - in
/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk:
core/MicroKernelImpl.java model/DiffBuilder.java
Author: stefan
Date: Wed May 16 09:03:50 2012
New Revision: 1339069
URL: http://svn.apache.org/viewvc?rev=1339069&view=rev
Log:
OAK-75: specify format and semantics of 'filter' parameter in MicroKernel API (WIP)
Modified:
jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/core/MicroKernelImpl.java
jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/DiffBuilder.java
Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/core/MicroKernelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/core/MicroKernelImpl.java?rev=1339069&r1=1339068&r2=1339069&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/core/MicroKernelImpl.java (original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/core/MicroKernelImpl.java Wed May 16 09:03:50 2012
@@ -154,7 +154,8 @@ public class MicroKernelImpl implements
throw new IllegalStateException("this instance has already been disposed");
}
- // todo support path filter
+ path = (path == null || "".equals(path)) ? "/" : path;
+ boolean filtered = !"/".equals(path);
Id fromRevisionId = Id.fromString(fromRevision);
Id toRevisionId = toRevision == null ? getHeadRevisionId() : Id.fromString(toRevision);
@@ -212,11 +213,25 @@ public class MicroKernelImpl implements
if (commit.getParentId() == null) {
continue;
}
+ String diff = commit.getChanges();
+ if (filtered) {
+ try {
+ diff = new DiffBuilder(
+ rep.getNodeState(commit.getParentId(), "/"),
+ rep.getNodeState(commit.getId(), "/"),
+ "/", rep.getRevisionStore(), path).build();
+ if (diff.isEmpty()) {
+ continue;
+ }
+ } catch (Exception e) {
+ throw new MicroKernelException(e);
+ }
+ }
commitBuff.object().
key("id").value(commit.getId().toString()).
key("ts").value(commit.getCommitTS()).
key("msg").value(commit.getMsg()).
- key("changes").value(commit.getChanges()).endObject();
+ key("changes").value(diff).endObject();
}
return commitBuff.endArray().toString();
}
Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/DiffBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/DiffBuilder.java?rev=1339069&r1=1339068&r2=1339069&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/DiffBuilder.java (original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/DiffBuilder.java Wed May 16 09:03:50 2012
@@ -30,21 +30,20 @@ public class DiffBuilder {
private final NodeState before;
private final NodeState after;
private final String path;
- private final String filter;
+ private final String pathFilter;
private final NodeStore store;
public DiffBuilder(NodeState before, NodeState after, String path,
- NodeStore store, String filter) {
+ NodeStore store, String pathFilter) {
this.before = before;
this.after = after;
this.path = path;
this.store = store;
- this.filter = filter;
+ this.pathFilter = (pathFilter == null || "".equals(pathFilter)) ? "/" : pathFilter;
+
}
public String build() throws Exception {
- // TODO extract and evaluate filter criteria specified in 'filter' parameter
-
final JsopBuilder buff = new JsopBuilder();
// maps (key: id of target node, value: path/to/target)
// for tracking added/removed nodes; this allows us
@@ -52,6 +51,10 @@ public class DiffBuilder {
final HashMap<NodeState, String> addedNodes = new HashMap<NodeState, String>();
final HashMap<NodeState, String> removedNodes = new HashMap<NodeState, String>();
+ if (!path.startsWith(pathFilter)) {
+ return "";
+ }
+
if (before == null) {
if (after != null) {
buff.tag('+').key(path).object();
@@ -69,47 +72,75 @@ public class DiffBuilder {
TraversingNodeDiffHandler diffHandler = new TraversingNodeDiffHandler(store) {
@Override
public void propertyAdded(PropertyState after) {
+ String p = PathUtils.concat(getCurrentPath(), after.getName());
+ if (!p.startsWith(pathFilter)) {
+ return;
+ }
buff.tag('+').
- key(PathUtils.concat(getCurrentPath(), after.getName())).
+ key(p).
encodedValue(after.getEncodedValue()).
newline();
}
@Override
public void propertyChanged(PropertyState before, PropertyState after) {
+ String p = PathUtils.concat(getCurrentPath(), after.getName());
+ if (!p.startsWith(pathFilter)) {
+ return;
+ }
buff.tag('^').
- key(PathUtils.concat(getCurrentPath(), after.getName())).
+ key(p).
encodedValue(after.getEncodedValue()).
newline();
}
@Override
public void propertyDeleted(PropertyState before) {
+ String p = PathUtils.concat(getCurrentPath(), before.getName());
+ if (!p.startsWith(pathFilter)) {
+ return;
+ }
// since property and node deletions can't be distinguished
// using the "- <path>" notation we're representing
// property deletions as "^ <path>:null"
buff.tag('^').
- key(PathUtils.concat(getCurrentPath(), before.getName())).
+ key(p).
value(null).
newline();
}
@Override
public void childNodeAdded(String name, NodeState after) {
- addedNodes.put(after, PathUtils.concat(getCurrentPath(), name));
+ String p = PathUtils.concat(getCurrentPath(), name);
+ if (!p.startsWith(pathFilter)) {
+ return;
+ }
+ addedNodes.put(after, p);
buff.tag('+').
- key(PathUtils.concat(getCurrentPath(), name)).object();
+ key(p).object();
toJson(buff, after);
buff.endObject().newline();
}
@Override
public void childNodeDeleted(String name, NodeState before) {
- removedNodes.put(before, PathUtils.concat(getCurrentPath(), name));
+ String p = PathUtils.concat(getCurrentPath(), name);
+ if (!p.startsWith(pathFilter)) {
+ return;
+ }
+ removedNodes.put(before, p);
buff.tag('-');
- buff.value(PathUtils.concat(getCurrentPath(), name));
+ buff.value(p);
buff.newline();
}
+
+ @Override
+ public void childNodeChanged(String name, NodeState before, NodeState after) {
+ String p = PathUtils.concat(getCurrentPath(), name);
+ if (p.startsWith(pathFilter)) {
+ super.childNodeChanged(name, before, after);
+ }
+ }
};
diffHandler.start(before, after, path);
@@ -129,27 +160,39 @@ public class DiffBuilder {
diffHandler = new TraversingNodeDiffHandler(store) {
@Override
public void propertyAdded(PropertyState after) {
+ String p = PathUtils.concat(getCurrentPath(), after.getName());
+ if (!p.startsWith(pathFilter)) {
+ return;
+ }
buff.tag('+').
- key(PathUtils.concat(getCurrentPath(), after.getName())).
+ key(p).
encodedValue(after.getEncodedValue()).
newline();
}
@Override
public void propertyChanged(PropertyState before, PropertyState after) {
+ String p = PathUtils.concat(getCurrentPath(), after.getName());
+ if (!p.startsWith(pathFilter)) {
+ return;
+ }
buff.tag('^').
- key(PathUtils.concat(getCurrentPath(), after.getName())).
+ key(p).
encodedValue(after.getEncodedValue()).
newline();
}
@Override
public void propertyDeleted(PropertyState before) {
+ String p = PathUtils.concat(getCurrentPath(), before.getName());
+ if (!p.startsWith(pathFilter)) {
+ return;
+ }
// since property and node deletions can't be distinguished
// using the "- <path>" notation we're representing
// property deletions as "^ <path>:null"
buff.tag('^').
- key(PathUtils.concat(getCurrentPath(), before.getName())).
+ key(p).
value(null).
newline();
}
@@ -160,8 +203,12 @@ public class DiffBuilder {
// moved node, will be processed separately
return;
}
+ String p = PathUtils.concat(getCurrentPath(), name);
+ if (!p.startsWith(pathFilter)) {
+ return;
+ }
buff.tag('+').
- key(PathUtils.concat(getCurrentPath(), name)).object();
+ key(p).object();
toJson(buff, after);
buff.endObject().newline();
}
@@ -172,11 +219,22 @@ public class DiffBuilder {
// moved node, will be processed separately
return;
}
+ String p = PathUtils.concat(getCurrentPath(), name);
+ if (!p.startsWith(pathFilter)) {
+ return;
+ }
buff.tag('-');
- buff.value(PathUtils.concat(getCurrentPath(), name));
+ buff.value(p);
buff.newline();
}
+ @Override
+ public void childNodeChanged(String name, NodeState before, NodeState after) {
+ String p = PathUtils.concat(getCurrentPath(), name);
+ if (p.startsWith(pathFilter)) {
+ super.childNodeChanged(name, before, after);
+ }
+ }
};
diffHandler.start(before, after, path);