You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by md...@apache.org on 2011/08/25 17:25:58 UTC
svn commit: r1161603 -
/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
Author: mduerig
Date: Thu Aug 25 15:25:58 2011
New Revision: 1161603
URL: http://svn.apache.org/viewvc?rev=1161603&view=rev
Log:
Microkernel based Jackrabbit prototype (WIP)
indexer
Modified:
jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java?rev=1161603&r1=1161602&r2=1161603&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java (original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java Thu Aug 25 15:25:58 2011
@@ -21,6 +21,8 @@ package org.apache.jackrabbit.spi2microk
import org.apache.commons.io.IOUtils;
import org.apache.jackrabbit.mk.api.MicroKernel;
import org.apache.jackrabbit.mk.api.MicroKernelException;
+import org.apache.jackrabbit.mk.index.Index;
+import org.apache.jackrabbit.mk.index.Indexer;
import org.apache.jackrabbit.mk.json.JsonBuilder;
import org.apache.jackrabbit.mk.util.PathUtils;
import org.apache.jackrabbit.spi.Batch;
@@ -173,6 +175,8 @@ public class RepositoryServiceImpl exten
}};
private final MicroKernel microKernel;
+ private final Indexer indexer;
+ private final Index jcrUuidIndex;
private final Map<SessionInfo, SessionState> sessions = new ConcurrentHashMap<SessionInfo, SessionState>();
private final NodeTypeStore nodeTypeStore;
private final String defaultWorkspace;
@@ -181,7 +185,7 @@ public class RepositoryServiceImpl exten
public RepositoryServiceImpl(MicroKernel microKernel, Map<?, ?> parameters) throws RepositoryException {
super(DESCRIPTORS, Collections.<String, String>emptyMap(), new QNodeTypeDefinition[0]);
- try {
+ try {
this.microKernel = microKernel; // todo who disposes the micro kernel?
defaultWorkspace = getWorkspaceName(parameters,
@@ -198,6 +202,9 @@ public class RepositoryServiceImpl exten
for (Entry<String, String> entry : namespaces.getPrefixToURIMapping().entrySet()) {
Paths.addKnownNamespace(entry.getKey(), entry.getValue());
}
+
+ indexer = new Indexer(microKernel, systemWorkspace);
+ jcrUuidIndex = indexer.createUniqueIndex("{jcr}uuid");
}
catch (MicroKernelException e) {
throw new RepositoryException(e.getMessage(), e);
@@ -325,14 +332,15 @@ public class RepositoryServiceImpl exten
@Override
public Iterator<? extends ItemInfo> getItemInfos(SessionInfo sessionInfo, ItemId itemId) throws RepositoryException {
try {
- Path itemPath = getPath(itemId);
+ String wspName = sessionInfo.getWorkspaceName();
+ Path itemPath = getPath(itemId, wspName);
if (!itemPath.isAbsolute()) {
throw new ItemNotFoundException(itemId.toString());
}
Path nodePath = itemId.denotesNode() ? itemPath : itemPath.getAncestor(1);
String rev = microKernel.getHeadRevision();
- String mkPath = Paths.pathToString(sessionInfo.getWorkspaceName(), nodePath);
+ String mkPath = Paths.pathToString(wspName, nodePath);
if (!microKernel.nodeExists(mkPath, rev)) {
throw new PathNotFoundException(itemPath.toString());
@@ -349,8 +357,9 @@ public class RepositoryServiceImpl exten
@Override
public Iterator<ChildInfo> getChildInfos(SessionInfo sessionInfo, NodeId parentId) throws RepositoryException {
try {
- Path path = getPath(parentId);
- String mkPath = Paths.pathToString(sessionInfo.getWorkspaceName(), path);
+ String wspName = sessionInfo.getWorkspaceName();
+ Path path = getPath(parentId, wspName);
+ String mkPath = Paths.pathToString(wspName, path);
String rev = microKernel.getHeadRevision();
if (!microKernel.nodeExists(mkPath, rev)) {
@@ -506,7 +515,7 @@ public class RepositoryServiceImpl exten
//------------------------------------------< private >---
- private static Path getPath(ItemId itemId) throws RepositoryException {
+ private Path getPath(ItemId itemId, String wspName) throws RepositoryException {
String uid = itemId.getUniqueID();
Path path = itemId.getPath();
@@ -514,8 +523,7 @@ public class RepositoryServiceImpl exten
return path;
}
- // todo: make uuid more stable
- Path basePath = Paths.stringToPath(PathUtils.isAbsolute(uid) ? uid : '/' + uid);
+ Path basePath = resolveId(uid, wspName);
if (path == null) {
return basePath;
}
@@ -524,6 +532,29 @@ public class RepositoryServiceImpl exten
}
}
+ private Path resolveId(String id, String wspName) throws ItemNotFoundException {
+ String path = jcrUuidIndex.getPath(JsonBuilder.encode(id), microKernel.getHeadRevision());
+ if (path == null) {
+ throw new ItemNotFoundException(id);
+ }
+
+ path = PathUtils.concat("/", PathUtils.relativize('/' + wspName, path));
+ return Paths.stringToPath(path);
+ }
+
+ private String createId(NodeId nodeId, Name childName) {
+ int nodeHash = nodeId.hashCode();
+ int childHash = childName == null ? 0 : childName.hashCode();
+ String id = Integer.toHexString(nodeHash + childHash);
+
+ // rehash while id is not unique
+ while (jcrUuidIndex.findFirst(id).hasNext()) {
+ id = Integer.toHexString(id.hashCode());
+ }
+
+ return id;
+ }
+
private static SubscriptionImpl subscription(Subscription subscription) throws RepositoryException {
if (subscription instanceof SubscriptionImpl) {
return (SubscriptionImpl) subscription;
@@ -532,7 +563,7 @@ public class RepositoryServiceImpl exten
throw new RepositoryException("Invalid subscription " + subscription);
}
}
-
+
private static ChangeLog changeLog(Batch batch) throws RepositoryException {
if (batch instanceof ChangeLog) {
return (ChangeLog) batch;
@@ -615,16 +646,16 @@ public class RepositoryServiceImpl exten
}
}
};
-
private final Function1<String, QValue> readFromDataStore = new Function1<String, QValue>(){
@Override
public QValue apply(String blobId) throws Exception {
return new QBinaryValue(blobId, microKernel);
}
};
-
private class CommitBuilder implements Batch {
+
private final SessionInfo sessionInfo;
+
private final StringBuilder jsop = new StringBuilder();
public CommitBuilder(SessionInfo sessionInfo) {
@@ -644,10 +675,7 @@ public class RepositoryServiceImpl exten
DefaultValueProvider defaultProvider = Values.getDefaultProvider(nodetypeName, nodeTypeDefs);
for (Name propertyName : defaultProvider.getDefaultProperties()) {
if (uuid == null) {
- // todo: make uuid more stable
- String parentPath = Paths.pathToString(getPath(parentId));
- String name = Paths.nameToString(nodeName);
- uuid = PathUtils.concat(parentPath, name);
+ uuid = createId(parentId, nodeName);
}
QValue value = defaultProvider.getValue(propertyName, sessionInfo, uuid);
setProperty(target(parentId, nodeName, propertyName), Values.valueToString(value, saveToDataStore));
@@ -682,7 +710,7 @@ public class RepositoryServiceImpl exten
public void remove(ItemId itemId) throws RepositoryException {
if (itemId.denotesNode()) {
NodeId nodeId = (NodeId) itemId;
- if (getPath(nodeId).denotesRoot()) {
+ if (getPath(nodeId, sessionInfo.getWorkspaceName()).denotesRoot()) {
throw new RepositoryException("Cannot remove root node");
}
@@ -715,8 +743,7 @@ public class RepositoryServiceImpl exten
for (Name mixin: mixinNodeTypeNames) {
DefaultValueProvider defaultProvider = Values.getDefaultProvider(mixin, nodeTypeDefs);
for (Name propertyName : defaultProvider.getDefaultProperties()) {
- // todo: make uuid more stable
- String uuid = Paths.pathToString(getPath(nodeId));
+ String uuid = createId(nodeId, null);
QValue value = defaultProvider.getValue(propertyName, sessionInfo, uuid);
setProperty(nodeId, propertyName, Values.valueToString(value, saveToDataStore));
}
@@ -745,14 +772,18 @@ public class RepositoryServiceImpl exten
}
});
}
-
+
private String target(NodeId nodeId) throws RepositoryException {
+ String wspName = sessionInfo.getWorkspaceName();
+ Path path = getPath(nodeId, wspName);
+
return JsonBuilder.quote(JsonBuilder.escape(
- PathUtils.relativize("/", Paths.pathToString(sessionInfo.getWorkspaceName(), getPath(nodeId)))));
+ PathUtils.relativize("/", Paths.pathToString(wspName, path))));
}
private String target(NodeId parentId, Name... itemNames) throws RepositoryException {
- String path = Paths.pathToString(sessionInfo.getWorkspaceName(), getPath(parentId));
+ String wspName = sessionInfo.getWorkspaceName();
+ String path = Paths.pathToString(wspName, getPath(parentId, wspName));
String relPath = PathUtils.relativize("/", path);
for (Name itemName : itemNames) {