Author: dpfister
Date: Fri Mar 9 13:58:54 2012
New Revision: 1298829
URL: http://svn.apache.org/viewvc?rev=1298829&view=rev
Log:
refactor String commit id's in Id instances
- propagate up to MK level
- use consistent naming (revision for String, revisionId for Id)
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/Repository.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/model/CommitBuilder.java
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java?rev=1298829&r1=1298828&r2=1298829&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
Fri Mar 9 13:58:54 2012
@@ -48,7 +48,11 @@ public class MicroKernelImpl implements
protected Repository rep;
private final CommitGate gate = new CommitGate();
- private final Map<String, String> diffCache =
Collections.synchronizedMap(SimpleLRUCache.<String, String>newInstance(100));
+
+ /**
+ * Key: revision id, Value: diff string
+ */
+ private final Map<Id, String> diffCache =
Collections.synchronizedMap(SimpleLRUCache.<Id, String>newInstance(100));
public MicroKernelImpl(String homeDir) throws MicroKernelException {
init(homeDir);
@@ -89,7 +93,15 @@ public class MicroKernelImpl implements
if (rep == null) {
throw new IllegalStateException("this instance has already been
disposed");
}
-
+ return getHeadRevisionId().toString();
+ }
+
+ /**
+ * Same as <code>getHeadRevisionId</code>, with typed <code>Id</code>
return value instead of string.
+ *
+ * @see #getHeadRevision()
+ */
+ private Id getHeadRevisionId() throws MicroKernelException {
try {
return rep.getHeadRevision();
} catch (Exception e) {
@@ -114,7 +126,7 @@ public class MicroKernelImpl implements
if (commitId == null) {
break;
}
- commit = rep.getCommit(commitId.toString());
+ commit = rep.getCommit(commitId);
}
} catch (Exception e) {
throw new MicroKernelException(e);
@@ -135,12 +147,13 @@ public class MicroKernelImpl implements
return gate.waitForCommit(oldHeadRevision, maxWaitMillis);
}
- public String getJournal(String fromRevisionId, String toRevisionId,
String filter) throws MicroKernelException {
+ public String getJournal(String fromRevision, String toRevision, String
filter) throws MicroKernelException {
if (rep == null) {
throw new IllegalStateException("this instance has already been
disposed");
}
- toRevisionId = toRevisionId == null ? getHeadRevision() : toRevisionId;
+ Id fromRevisionId = Id.fromString(fromRevision);
+ Id toRevisionId = toRevision == null ? getHeadRevisionId() :
Id.fromString(toRevision);
List<StoredCommit> commits = new ArrayList<StoredCommit>();
try {
@@ -163,14 +176,14 @@ public class MicroKernelImpl implements
StoredCommit commit = toCommit;
while (commit != null) {
commits.add(commit);
- if (commit.getId().toString().equals(fromRevisionId)) {
+ if (commit.getId().equals(fromRevisionId)) {
break;
}
Id commitId = commit.getParentId();
if (commitId == null) {
break;
}
- commit = rep.getCommit(commitId.toString());
+ commit = rep.getCommit(commitId);
}
} catch (Exception e) {
throw new MicroKernelException(e);
@@ -188,22 +201,31 @@ public class MicroKernelImpl implements
key("id").value(commit.getId().toString()).
key("ts").value(commit.getCommitTS()).
key("msg").value(commit.getMsg());
- String diff = diffCache.get(commit.getId().toString());
+ String diff = diffCache.get(commit.getId());
if (diff == null) {
- diff = diff(commit.getParentId().toString(),
commit.getId().toString(), filter);
- diffCache.put(commit.getId().toString(), diff);
+ diff = diff(commit.getParentId(), commit.getId(), filter);
+ diffCache.put(commit.getId(), diff);
}
commitBuff.key("changes").value(diff).endObject();
}
return commitBuff.endArray().toString();
}
- public String diff(String fromRevisionId, String toRevisionId, String
filter) throws MicroKernelException {
+ public String diff(String fromRevision, String toRevision, String filter)
throws MicroKernelException {
+ Id toRevisionId = toRevision == null ? getHeadRevisionId() :
Id.fromString(toRevision);
+
+ return diff(Id.fromString(fromRevision), toRevisionId, filter);
+ }
+
+ /**
+ * Same as <code>diff</code>, with typed <code>Id</code> arguments instead
of strings.
+ *
+ * @see #diff(String, String, String)
+ */
+ private String diff(Id fromRevisionId, Id toRevisionId, String filter)
throws MicroKernelException {
// TODO extract and evaluate filter criteria (such as e.g. 'path')
specified in 'filter' parameter
String path = "/";
- toRevisionId = toRevisionId == null ? getHeadRevision() : toRevisionId;
-
try {
final JsopBuilder buff = new JsopBuilder();
final RevisionProvider rp = rep.getRevisionStore();
@@ -369,22 +391,21 @@ public class MicroKernelImpl implements
}
}
- public boolean nodeExists(String path, String revisionId) throws
MicroKernelException {
+ public boolean nodeExists(String path, String revision) throws
MicroKernelException {
if (rep == null) {
throw new IllegalStateException("this instance has already been
disposed");
}
- revisionId = revisionId == null ? getHeadRevision() : revisionId;
-
+ Id revisionId = revision == null ? getHeadRevisionId() :
Id.fromString(revision);
return rep.nodeExists(revisionId, path);
}
- public long getChildNodeCount(String path, String revisionId) throws
MicroKernelException {
+ public long getChildNodeCount(String path, String revision) throws
MicroKernelException {
if (rep == null) {
throw new IllegalStateException("this instance has already been
disposed");
}
- revisionId = revisionId == null ? getHeadRevision() : revisionId;
+ Id revisionId = revision == null ? getHeadRevisionId() :
Id.fromString(revision);
try {
return rep.getNodeState(revisionId, path).getChildNodeCount();
@@ -393,16 +414,16 @@ public class MicroKernelImpl implements
}
}
- public String getNodes(String path, String revisionId) throws
MicroKernelException {
- return getNodes(path, revisionId, 1, 0, -1, null);
+ public String getNodes(String path, String revision) throws
MicroKernelException {
+ return getNodes(path, revision, 1, 0, -1, null);
}
- public String getNodes(String path, String revisionId, int depth, long
offset, int count, String filter) throws MicroKernelException {
+ public String getNodes(String path, String revision, int depth, long
offset, int count, String filter) throws MicroKernelException {
if (rep == null) {
throw new IllegalStateException("this instance has already been
disposed");
}
- revisionId = revisionId == null ? getHeadRevision() : revisionId;
+ Id revisionId = revision == null ? getHeadRevisionId() :
Id.fromString(revision);
// TODO extract and evaluate filter criteria (such as e.g. ':hash')
specified in 'filter' parameter
@@ -415,7 +436,7 @@ public class MicroKernelImpl implements
}
}
- public String commit(String path, String jsonDiff, String revisionId,
String message) throws MicroKernelException {
+ public String commit(String path, String jsonDiff, String revision, String
message) throws MicroKernelException {
if (rep == null) {
throw new IllegalStateException("this instance has already been
disposed");
}
@@ -423,7 +444,7 @@ public class MicroKernelImpl implements
throw new IllegalArgumentException("absolute path expected: " +
path);
}
- revisionId = revisionId == null ? getHeadRevision() : revisionId;
+ Id revisionId = revision == null ? getHeadRevisionId() :
Id.fromString(revision);
try {
JsopTokenizer t = new JsopTokenizer(jsonDiff);
@@ -540,13 +561,12 @@ public class MicroKernelImpl implements
throw new AssertionError("token type: " +
t.getTokenType());
}
}
- String newHead = cb.doCommit();
- if (newHead.equals(revisionId)) {
- // 'empty' commit
- return newHead;
+ Id newHead = cb.doCommit();
+ if (!newHead.equals(revisionId)) {
+ // non-empty commit
+ gate.commit(newHead.toString());
}
- gate.commit(newHead);
- return newHead;
+ return newHead.toString();
} catch (Exception e) {
throw new MicroKernelException(e);
}
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/Repository.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/Repository.java?rev=1298829&r1=1298828&r2=1298829&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/Repository.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/Repository.java
Fri Mar 9 13:58:54 2012
@@ -91,11 +91,11 @@ public class Repository {
return rs;
}
- public String getHeadRevision() throws Exception {
+ public Id getHeadRevision() throws Exception {
if (!initialized) {
throw new IllegalStateException("not initialized");
}
- return rs.getHeadCommitId().toString();
+ return rs.getHeadCommitId();
}
public StoredCommit getHeadCommit() throws Exception {
@@ -105,14 +105,14 @@ public class Repository {
return rs.getHeadCommit();
}
- public StoredCommit getCommit(String id) throws NotFoundException,
Exception {
+ public StoredCommit getCommit(Id id) throws NotFoundException, Exception {
if (!initialized) {
throw new IllegalStateException("not initialized");
}
- return rs.getCommit(Id.fromString(id));
+ return rs.getCommit(id);
}
- public NodeState getNodeState(String revId, String path) throws
NotFoundException, Exception {
+ public NodeState getNodeState(Id revId, String path) throws
NotFoundException, Exception {
return rs.getNodeState(getNode(revId, path));
}
@@ -124,12 +124,12 @@ public class Repository {
* @throws NotFoundException if either path or revision doesn't exist
* @throws Exception if another error occurs
*/
- public StoredNode getNode(String revId, String path) throws
NotFoundException, Exception {
+ public StoredNode getNode(Id revId, String path) throws NotFoundException,
Exception {
if (!initialized) {
throw new IllegalStateException("not initialized");
}
- StoredNode root = rs.getRootNode(Id.fromString(revId));
+ StoredNode root = rs.getRootNode(revId);
if (PathUtils.denotesRoot(path)) {
return root;
}
@@ -139,7 +139,7 @@ public class Repository {
return rs.getNode(ids[ids.length - 1]);
}
- public boolean nodeExists(String revId, String path) {
+ public boolean nodeExists(Id revId, String path) {
if (!initialized) {
throw new IllegalStateException("not initialized");
}
@@ -150,7 +150,7 @@ public class Repository {
try {
String[] names = PathUtils.split(path);
- Node parent = rs.getRootNode(Id.fromString(revId));
+ Node parent = rs.getRootNode(revId);
for (int i = 0; i < names.length; i++) {
ChildNodeEntry cne = parent.getChildNodeEntry(names[i]);
if (cne == null) {
@@ -164,7 +164,7 @@ public class Repository {
}
}
- public CommitBuilder getCommitBuilder(String revId, String msg) throws
Exception {
+ public CommitBuilder getCommitBuilder(Id revId, String msg) throws
Exception {
return new CommitBuilder(revId, msg, rs);
}
@@ -177,12 +177,12 @@ public class Repository {
* @throws NotFoundException if either path or revision doesn't exist
* @throws Exception if another error occurs
*/
- Id[] /* array of node id's */ resolvePath(String revId, String nodePath)
throws Exception {
+ Id[] /* array of node id's */ resolvePath(Id revId, String nodePath)
throws Exception {
if (!PathUtils.isAbsolute(nodePath)) {
throw new IllegalArgumentException("illegal path");
}
- Commit commit = rs.getCommit(Id.fromString(revId));
+ Commit commit = rs.getCommit(revId);
if (PathUtils.denotesRoot(nodePath)) {
return new Id[]{commit.getRootNodeId()};
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/model/CommitBuilder.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/model/CommitBuilder.java?rev=1298829&r1=1298828&r2=1298829&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/model/CommitBuilder.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/model/CommitBuilder.java
Fri Mar 9 13:58:54 2012
@@ -44,8 +44,8 @@ public class CommitBuilder {
// change log
private final List<Change> changeLog = new ArrayList<Change>();
- public CommitBuilder(String baseRevId, String msg, RevisionStore store)
throws Exception {
- this.baseRevId = Id.fromString(baseRevId);
+ public CommitBuilder(Id baseRevId, String msg, RevisionStore store) throws
Exception {
+ this.baseRevId = baseRevId;
this.msg = msg;
this.store = store;
}
@@ -169,10 +169,10 @@ public class CommitBuilder {
changeLog.add(new SetProperties(nodePath, properties));
}
- public String /* new revId */ doCommit() throws Exception {
+ public Id /* new revId */ doCommit() throws Exception {
if (staged.isEmpty()) {
// nothing to commit
- return baseRevId.toString();
+ return baseRevId;
}
Id currentHead = store.getHeadCommitId();
@@ -209,7 +209,7 @@ public class CommitBuilder {
if
(store.getCommit(currentHead).getRootNodeId().equals(rootNodeId)) {
// the commit didn't cause any changes,
// no need to create new commit object/update head revision
- return currentHead.toString();
+ return currentHead;
}
MutableCommit newCommit = new MutableCommit();
newCommit.setParentId(baseRevId);
@@ -227,7 +227,7 @@ public class CommitBuilder {
staged.clear();
changeLog.clear();
- return newRevId.toString();
+ return newRevId;
}
MutableNode getOrCreateStagedNode(String nodePath) throws Exception {