jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1163310 - in /jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src: main/java/org/apache/jackrabbit/spi2microkernel/ main/java/org/apache/jackrabbit/spi2microkernel/util/ test/java/org/apache/jackrabbit/spi2microkernel/
Date Tue, 30 Aug 2011 18:01:25 GMT
Author: mduerig
Date: Tue Aug 30 18:01:24 2011
New Revision: 1163310

URL: http://svn.apache.org/viewvc?rev=1163310&view=rev
Log:
Microkernel based Jackrabbit prototype (WIP)
references

Modified:
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.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=1163310&r1=1163309&r2=1163310&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
Tue Aug 30 18:01:24 2011
@@ -22,6 +22,7 @@ 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.Indexer;
+import org.apache.jackrabbit.mk.index.PrefixIndex;
 import org.apache.jackrabbit.mk.index.PropertyIndex;
 import org.apache.jackrabbit.mk.json.JsonBuilder;
 import org.apache.jackrabbit.mk.util.PathUtils;
@@ -29,6 +30,7 @@ import org.apache.jackrabbit.spi.Batch;
 import org.apache.jackrabbit.spi.ChildInfo;
 import org.apache.jackrabbit.spi.EventBundle;
 import org.apache.jackrabbit.spi.EventFilter;
+import org.apache.jackrabbit.spi.IdFactory;
 import org.apache.jackrabbit.spi.ItemId;
 import org.apache.jackrabbit.spi.ItemInfo;
 import org.apache.jackrabbit.spi.ItemInfoCache;
@@ -48,8 +50,10 @@ import org.apache.jackrabbit.spi.commons
 import org.apache.jackrabbit.spi.commons.QNodeDefinitionImpl;
 import org.apache.jackrabbit.spi.commons.SessionInfoImpl;
 import org.apache.jackrabbit.spi.commons.batch.ConsolidatingChangeLog;
+import org.apache.jackrabbit.spi.commons.iterator.Iterators;
+import org.apache.jackrabbit.spi.commons.iterator.Predicate;
+import org.apache.jackrabbit.spi.commons.iterator.Transformer;
 import org.apache.jackrabbit.spi.commons.name.NameConstants;
-import org.apache.jackrabbit.spi.commons.name.PathFactoryImpl;
 import org.apache.jackrabbit.spi2microkernel.util.DefaultValueProvider;
 import org.apache.jackrabbit.spi2microkernel.util.Function1;
 import org.apache.jackrabbit.spi2microkernel.util.JsonHandlerBase;
@@ -66,6 +70,7 @@ import javax.jcr.ItemNotFoundException;
 import javax.jcr.NamespaceException;
 import javax.jcr.NoSuchWorkspaceException;
 import javax.jcr.PathNotFoundException;
+import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.jcr.version.OnParentVersionAction;
@@ -78,9 +83,9 @@ import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.UUID;
 import java.util.Map.Entry;
 import java.util.Set;
+import java.util.UUID;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ConcurrentHashMap;
 
@@ -178,6 +183,8 @@ public class RepositoryServiceImpl exten
     private final MicroKernel microKernel;
     private final Indexer indexer;
     private final PropertyIndex jcrUuidIndex;
+    private final PrefixIndex referenceIndex;
+    private final PrefixIndex weakReferenceIndex;
     private final Map<SessionInfo, SessionState> sessions = new ConcurrentHashMap<SessionInfo,
SessionState>();
     private final NodeTypeStore nodeTypeStore;
     private final String defaultWorkspace;
@@ -206,6 +213,8 @@ public class RepositoryServiceImpl exten
 
             indexer = new Indexer(microKernel, systemWorkspace);
             jcrUuidIndex = indexer.createPropertyIndex("{jcr}uuid", true);
+            referenceIndex = indexer.createPrefixIndex(Values.typePrefix(PropertyType.REFERENCE));
+            weakReferenceIndex = indexer.createPrefixIndex(Values.typePrefix(PropertyType.WEAKREFERENCE));
         }
         catch (MicroKernelException e) {
             throw new RepositoryException(e.getMessage(), e);
@@ -378,11 +387,47 @@ public class RepositoryServiceImpl exten
     }
 
     @Override
-    public Iterator<PropertyId> getReferences(SessionInfo sessionInfo, NodeId nodeId,
Name propertyName,
+    public Iterator<PropertyId> getReferences(SessionInfo sessionInfo, NodeId nodeId,
final Name propertyName,
         boolean weakReferences) throws RepositoryException {
 
-        // todo implement getReferences
-        throw new UnsupportedRepositoryOperationException();
+        String id = nodeId.getUniqueID();
+        if (id == null || nodeId.getPath() != null) {
+            throw new RepositoryException("NodeId is not a unique Id");
+        }
+
+        String prefix = Values.typePrefix(weakReferences ? PropertyType.WEAKREFERENCE : PropertyType.REFERENCE);
+        PrefixIndex index = weakReferences ? weakReferenceIndex : referenceIndex;
+        Iterator<String> paths = index.getPaths(prefix + id, microKernel.getHeadRevision());
+        final IdFactory idFactory = getIdFactory();
+        final String wspName = sessionInfo.getWorkspaceName();
+
+        Iterator<PropertyId> propertyIds = Iterators.transformIterator(paths, new Transformer<String,
PropertyId>() {
+            @Override
+            public PropertyId transform(String pathString) {
+                try {
+                    pathString = PathUtils.concat("/", PathUtils.relativize('/' + wspName,
pathString));
+                    Path path = Paths.stringToPath(pathString);
+                    NodeId parentId = idFactory.createNodeId((String) null, path.getAncestor(1));
+                    return idFactory.createPropertyId(parentId, path.getName());
+                }
+                catch (RepositoryException e) {
+                    log.debug(e.getMessage(), e);
+                    throw new IllegalStateException(e.getMessage(), e);
+                }
+            }
+        });
+
+        if (propertyName == null) {
+            return propertyIds;
+        }
+        else {
+            return Iterators.filterIterator(propertyIds, new Predicate<PropertyId>()
{
+                @Override
+                public boolean evaluate(PropertyId propertyId) {
+                    return propertyName.equals(propertyId);
+                }
+            });
+        }
     }
 
     //-----------------------------< write methods >----------------------------
@@ -529,7 +574,7 @@ public class RepositoryServiceImpl exten
             return basePath;
         }
         else {
-            return PathFactoryImpl.getInstance().create(basePath, path, true);
+            return getPathFactory().create(basePath, path, true);
         }
     }
 
@@ -650,12 +695,14 @@ 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;

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java?rev=1163310&r1=1163309&r2=1163310&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java
Tue Aug 30 18:01:24 2011
@@ -452,6 +452,10 @@ public final class Values {
         };
     }
 
+    public static String typePrefix(int type) {
+        return TYPES[type] + ":";
+    }
+
     //------------------------------------------< private >---
 
     private static Character toHex(int i) {
@@ -465,7 +469,7 @@ public final class Values {
     }
 
     private static String quoteAndEncode(int type, String value) {
-        return quote(TYPES[type] + ":" + value);
+        return quote(typePrefix(type) + value);
     }
 
     private static QValue create(boolean value) {

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java?rev=1163310&r1=1163309&r2=1163310&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
Tue Aug 30 18:01:24 2011
@@ -712,6 +712,19 @@ public class RepositoryTest {
     }
 
     @Test
+    public void references() throws RepositoryException, IOException {
+        Node parentNode = getNode(testPath);
+        Node referee = getSession().getNode("/foo");
+        referee.addMixin("mix:referenceable");
+        getSession().save();
+
+        addProperty(parentNode, "reference", getSession().getValueFactory().createValue(referee));
+        PropertyIterator references = referee.getReferences();
+        assertTrue(references.hasNext());
+        assertEquals(parentNode.getProperty("reference").getPath(), references.nextProperty().getPath());
+    }
+
+    @Test
     public void addMultiValuedReference() throws RepositoryException {
         Node parentNode = getNode(testPath);
         Node referee = getSession().getNode("/foo");



Mime
View raw message