jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1329202 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/mk/fs/ main/java/org/apache/jackrabbit/mk/index/ main/java/org/apache/jackrabbit/mk/simple/ main/java/org/apache/jackrabbit/mk/wrapper/ test/java/org/apache/j...
Date Mon, 23 Apr 2012 12:16:41 GMT
Author: thomasm
Date: Mon Apr 23 12:16:40 2012
New Revision: 1329202

URL: http://svn.apache.org/viewvc?rev=1329202&view=rev
Log:
OAK-48 MicroKernel.getNodes() should return null for not existing nodes

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/fs/FileChannelInputStream.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/IndexWrapper.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/simple/NodeId.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/simple/NodeImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/simple/NodeList.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/simple/NodeListSmall.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/simple/NodeListTrie.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/simple/Revision.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/SecurityWrapper.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/VirtualRepositoryWrapper.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/wrapper/IndexWrapperTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/wrapper/SecurityWrapperTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/wrapper/VirtualRepositoryWrapperTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/fs/FileChannelInputStream.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/fs/FileChannelInputStream.java?rev=1329202&r1=1329201&r2=1329202&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/fs/FileChannelInputStream.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/fs/FileChannelInputStream.java
Mon Apr 23 12:16:40 2012
@@ -24,6 +24,7 @@ public class FileChannelInputStream exte
      * Create a new file object input stream from the file channel.
      *
      * @param channel the file channel
+     * @param closeChannel close the channel when done
      */
     public FileChannelInputStream(FileChannel channel, boolean closeChannel) {
         this.channel = channel;

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/IndexWrapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/IndexWrapper.java?rev=1329202&r1=1329201&r2=1329202&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/IndexWrapper.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/IndexWrapper.java
Mon Apr 23 12:16:40 2012
@@ -160,7 +160,8 @@ public class IndexWrapper extends MicroK
         String index = PathUtils.relativize(INDEX_PATH, path);
         int idx = index.indexOf('?');
         if (idx < 0) {
-            throw ExceptionFactory.get("Invalid query. Expected: /index/prefix:x?y, got:
" + path);
+            // invalid query - expected: /index/prefix:x?y
+            return null;
         }
         String data = index.substring(idx + 1);
         index = index.substring(0, idx);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/simple/NodeId.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/simple/NodeId.java?rev=1329202&r1=1329201&r2=1329202&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/simple/NodeId.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/simple/NodeId.java
Mon Apr 23 12:16:40 2012
@@ -42,6 +42,7 @@ public class NodeId {
         return map.getNode(x);
     }
 
+    @Override
     public String toString() {
         return Long.toString(x);
     }
@@ -79,6 +80,7 @@ public class NodeId {
             return node;
         }
 
+        @Override
         public String toString() {
             return node.toString();
         }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/simple/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/simple/NodeImpl.java?rev=1329202&r1=1329201&r2=1329202&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/simple/NodeImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/simple/NodeImpl.java
Mon Apr 23 12:16:40 2012
@@ -39,8 +39,6 @@ import java.util.Iterator;
  */
 public class NodeImpl implements Cache.Value {
 
-    private static final boolean NODE_NAME_AS_PROPERTY = false;
-
     /**
      * The child node count.
      */
@@ -83,6 +81,8 @@ public class NodeImpl implements Cache.V
      */
     static final String COUNT = ":childCount";
 
+    private static final boolean NODE_NAME_AS_PROPERTY = false;
+
     /**
      * The node name.
      */
@@ -179,7 +179,8 @@ public class NodeImpl implements Cache.V
     }
 
     private NodeImpl getChildNode(String name) {
-        return childNodes.get(name).getNode(map);
+        NodeId id = childNodes.get(name);
+        return id == null ? null : id.getNode(map);
     }
 
     public NodeImpl cloneAndAddChildNode(String path, boolean before, String position, NodeImpl
newNode, long revId) {
@@ -526,6 +527,7 @@ public class NodeImpl implements Cache.V
         return propertyValuePairs[index + index + 1];
     }
 
+    @Override
     public String toString() {
         String s = asString();
         if (path != null) {
@@ -710,6 +712,7 @@ public class NodeImpl implements Cache.V
         return memory;
     }
 
+    @Override
     public int hashCode() {
         int hash = Arrays.hashCode(propertyValuePairs);
         if (childNodes != null) {
@@ -718,6 +721,7 @@ public class NodeImpl implements Cache.V
         return hash;
     }
 
+    @Override
     public boolean equals(Object other) {
         if (other == this) {
             return true;

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/simple/NodeList.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/simple/NodeList.java?rev=1329202&r1=1329201&r2=1329202&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/simple/NodeList.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/simple/NodeList.java
Mon Apr 23 12:16:40 2012
@@ -129,6 +129,7 @@ interface NodeList {
      *
      * @param map the node map
      * @param out the output stream
+     * @throws IOException if writing to the stream failed
      */
     void updateHash(NodeMap map, OutputStream out) throws IOException;
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/simple/NodeListSmall.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/simple/NodeListSmall.java?rev=1329202&r1=1329201&r2=1329202&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/simple/NodeListSmall.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/simple/NodeListSmall.java
Mon Apr 23 12:16:40 2012
@@ -108,7 +108,7 @@ public class NodeListSmall implements No
     public NodeId get(String name) {
         int index = find(name);
         if (index < 0) {
-            throw ExceptionFactory.get("Node not found: " + name);
+            return null;
         }
         return children[sort[index]];
     }
@@ -184,6 +184,7 @@ public class NodeListSmall implements No
         return result;
     }
 
+    @Override
     public String toString() {
         JsopWriter json = new JsopBuilder();
         json.object();
@@ -232,6 +233,7 @@ public class NodeListSmall implements No
         return memory;
     }
 
+    @Override
     public int hashCode() {
         if (size == 0) {
             return 0;
@@ -241,6 +243,7 @@ public class NodeListSmall implements No
                 Arrays.hashCode(sort);
     }
 
+    @Override
     public boolean equals(Object other) {
         if (other == this) {
             return true;

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/simple/NodeListTrie.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/simple/NodeListTrie.java?rev=1329202&r1=1329201&r2=1329202&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/simple/NodeListTrie.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/simple/NodeListTrie.java
Mon Apr 23 12:16:40 2012
@@ -269,6 +269,7 @@ public class NodeListTrie implements Nod
         NodeId id;
         String prefix;
 
+        @Override
         public String toString() {
             return prefix;
         }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/simple/Revision.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/simple/Revision.java?rev=1329202&r1=1329201&r2=1329202&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/simple/Revision.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/simple/Revision.java
Mon Apr 23 12:16:40 2012
@@ -102,6 +102,7 @@ public class Revision implements Compara
         return id < o.id ? -1 : id > o.id ? 1 : 0;
     }
 
+    @Override
     public String toString() {
         return new JsopBuilder().object().
             key("id").value(formatId(id)).

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/SecurityWrapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/SecurityWrapper.java?rev=1329202&r1=1329201&r2=1329202&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/SecurityWrapper.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/SecurityWrapper.java
Mon Apr 23 12:16:40 2012
@@ -52,6 +52,10 @@ public class SecurityWrapper extends Mic
      * Decorates the given {@link MicroKernel} with authentication and
      * authorization. The responsibility of properly disposing the given
      * MikroKernel instance remains with the caller.
+     *
+     * @param mk the wrapped kernel
+     * @param user the user name
+     * @param pass the password
      */
     public SecurityWrapper(MicroKernel mk, String user, String pass) {
         this.mk = MicroKernelWrapperBase.wrap(mk);
@@ -93,6 +97,7 @@ public class SecurityWrapper extends Mic
 
     @Override
     public void dispose() {
+        // do nothing
     }
 
     @Override
@@ -288,7 +293,7 @@ public class SecurityWrapper extends Mic
     public JsopReader getNodesStream(String path, String revisionId, int depth, long offset,
int count, String filter) {
         rightsRevision = getHeadRevision();
         if (!checkRights(path, false)) {
-            throw ExceptionFactory.get("Node not found: " + path);
+            return null;
         }
         JsopReader t = mk.getNodesStream(path, revisionId, depth, offset, count, filter);
         if (admin || t == null) {
@@ -299,7 +304,7 @@ public class SecurityWrapper extends Mic
         n = filterAccess(path, n);
         JsopStream buff = new JsopStream();
         if (n == null) {
-            throw ExceptionFactory.get("Node not found: " + path);
+            return null;
         } else {
             // TODO childNodeCount properties might be wrong
             // when count and offset are used

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/VirtualRepositoryWrapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/VirtualRepositoryWrapper.java?rev=1329202&r1=1329201&r2=1329202&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/VirtualRepositoryWrapper.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/VirtualRepositoryWrapper.java
Mon Apr 23 12:16:40 2012
@@ -280,7 +280,8 @@ public class VirtualRepositoryWrapper ex
     public JsopReader getNodesStream(String path, String revisionId, int depth, long offset,
int count, String filter) {
         String mount = getMount(path);
         if (mount == null) {
-            throw ExceptionFactory.get("Not mapped: " + path);
+            // not mapped
+            return null;
         }
         String rev = getRevision(mount, revisionId);
         MicroKernelWrapper mk = mounts.get(mount);

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/wrapper/IndexWrapperTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/wrapper/IndexWrapperTest.java?rev=1329202&r1=1329201&r2=1329202&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/wrapper/IndexWrapperTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/wrapper/IndexWrapperTest.java
Mon Apr 23 12:16:40 2012
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.mk.wrapper;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.index.IndexWrapper;
 import org.apache.jackrabbit.mk.simple.SimpleKernelImpl;
@@ -34,6 +35,12 @@ public class IndexWrapperTest {
     private String head;
 
     @Test
+    public void getNodes() {
+        assertNull(mk.getNodes("/index/unknown", head));
+        assertNull(mk.getNodes("/unknown", head));
+    }
+
+    @Test
     public void prefix() {
         head = mk.commit("/index", "+ \"prefix:x\": {}", head, "");
         head = mk.commit("/", "+ \"n1\": { \"value\":\"a:no\" }", head, "");

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/wrapper/SecurityWrapperTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/wrapper/SecurityWrapperTest.java?rev=1329202&r1=1329201&r2=1329202&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/wrapper/SecurityWrapperTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/wrapper/SecurityWrapperTest.java
Mon Apr 23 12:16:40 2012
@@ -18,6 +18,7 @@ package org.apache.jackrabbit.mk.wrapper
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 import junit.framework.Assert;
@@ -102,10 +103,14 @@ public class SecurityWrapperTest {
         head = mk.getHeadRevision();
         assertTrue(mkAdmin.nodeExists("/:user", head));
         assertFalse(mkGuest.nodeExists("/:user", head));
+        assertNull(mkGuest.getNodes("/:user", head));
         head = mkAdmin.commit("/", "^ \":rights\": \"read\"", head, "");
         head = mkAdmin.commit("/", "+ \"test\": { \"data\": \"Hello\" }", head, "");
         assertTrue(mkAdmin.nodeExists("/", head));
+        assertNull(mkGuest.getNodes("/unknown", head));
+        assertNull(mkGuest.getNodes("/unknown/node", head));
         assertTrue(mkGuest.nodeExists("/", head));
+        assertNull(mkGuest.getNodes("/unknown", head));
         assertEquals("{\":rights\":\"read\",\":childNodeCount\":2,\":user\":{\":rights\":\"admin\",\":childNodeCount\":2,\"guest\":{},\"sa\":{}},\"test\":{\"data\":\"Hello\",\":childNodeCount\":0}}",
mkAdmin.getNodes("/", head));
         assertEquals("{\":childNodeCount\":1,\"test\":{\"data\":\"Hello\",\":childNodeCount\":0}}",
mkGuest.getNodes("/", head));
     }

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/wrapper/VirtualRepositoryWrapperTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/wrapper/VirtualRepositoryWrapperTest.java?rev=1329202&r1=1329201&r2=1329202&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/wrapper/VirtualRepositoryWrapperTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/wrapper/VirtualRepositoryWrapperTest.java
Mon Apr 23 12:16:40 2012
@@ -15,6 +15,7 @@ package org.apache.jackrabbit.mk.wrapper
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import java.io.ByteArrayInputStream;
 import java.util.Arrays;
@@ -91,6 +92,8 @@ public class VirtualRepositoryWrapperTes
         head = mkVirtual.commit("/", "+ \"data\": {} ", head, "");
         head = mkVirtual.commit("/", "+ \"data/a\": { \"data\": \"Hello\" }", head, "");
         head = mkVirtual.commit("/", "+ \"data/b\": { \"data\": \"World\" }", head, "");
+
+        // get nodes
         String m1 = mkRep1.getNodes("/data", mkRep1.getHeadRevision());
         assertEquals("{\":childNodeCount\":1,\"a\":{\"data\":\"Hello\",\":childNodeCount\":0}}",
m1);
         String m2 = mkRep2.getNodes("/data", mkRep2.getHeadRevision());
@@ -100,6 +103,12 @@ public class VirtualRepositoryWrapperTes
         m = mkVirtual.getNodes("/data/b", mkVirtual.getHeadRevision());
         assertEquals("{\"data\":\"World\",\":childNodeCount\":0}", m);
 
+        // get nodes on unknown nodes
+        m = mkVirtual.getNodes("/notMapped", mkVirtual.getHeadRevision());
+        assertNull(m);
+        m = mkVirtual.getNodes("/data/a/notExist", mkVirtual.getHeadRevision());
+        assertNull(m);
+
         // set property
         head = mkVirtual.commit("/", "^ \"data/a/data\": \"Hallo\"", head, "");
         head = mkVirtual.commit("/", "^ \"data/b/data\": \"Welt\"", head, "");



Mime
View raw message