You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 09:56:33 UTC

[sling-org-apache-sling-nosql-generic] 06/18: SLING-5151 NoSQL: allow modifying the root resource

This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.nosql.generic-1.1.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-nosql-generic.git

commit df91c50010f19ea69e9fae222435a5e226c704f7
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Wed Feb 24 11:42:19 2016 +0000

    SLING-5151 NoSQL: allow modifying the root resource
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/nosql/generic@1732078 13f79535-47bb-0310-9956-ffa450edef68
---
 .../nosql/generic/resource/impl/NoSqlResourceProvider.java | 14 +++++---------
 .../impl/AbstractNoSqlResourceProviderRootTest.java        |  7 ++++++-
 2 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/src/main/java/org/apache/sling/nosql/generic/resource/impl/NoSqlResourceProvider.java b/src/main/java/org/apache/sling/nosql/generic/resource/impl/NoSqlResourceProvider.java
index 2649323..e5ad414 100644
--- a/src/main/java/org/apache/sling/nosql/generic/resource/impl/NoSqlResourceProvider.java
+++ b/src/main/java/org/apache/sling/nosql/generic/resource/impl/NoSqlResourceProvider.java
@@ -18,7 +18,6 @@
  */
 package org.apache.sling.nosql.generic.resource.impl;
 
-import java.util.Collections;
 import java.util.Dictionary;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -53,7 +52,6 @@ import org.osgi.service.event.EventAdmin;
 public class NoSqlResourceProvider implements ResourceProvider, ModifyingResourceProvider, QueriableResourceProvider {
     
     private static final String ROOT_PATH = "/";
-    private static final NoSqlData ROOT_DATA = new NoSqlData(ROOT_PATH, Collections.<String, Object>emptyMap());
     
     private final NoSqlAdapter adapter;
     private final EventAdmin eventAdmin;
@@ -69,10 +67,6 @@ public class NoSqlResourceProvider implements ResourceProvider, ModifyingResourc
     // ### READONLY ACCESS ###
     
     public Resource getResource(ResourceResolver resourceResolver, String path) {
-        if (ROOT_PATH.equals(path)) {
-            return new NoSqlResource(ROOT_DATA, resourceResolver, this);
-        }
-        
         if (!adapter.validPath(path)) {
             return null;
         }
@@ -91,6 +85,11 @@ public class NoSqlResourceProvider implements ResourceProvider, ModifyingResourc
         if (data != null) {
             return new NoSqlResource(data, resourceResolver, this);
         }
+        else if (ROOT_PATH.equals(path)) {
+            // root path exists implicitly - bot not yet in nosql store - return a "virtual" resource until something is stored in it
+            NoSqlData rootData = new NoSqlData(ROOT_PATH, new HashMap<String, Object>());
+            return new NoSqlResource(rootData, resourceResolver, this);
+        }
         return null;
     }
 
@@ -196,9 +195,6 @@ public class NoSqlResourceProvider implements ResourceProvider, ModifyingResourc
                notifyRemoved(path);
             }
             for (NoSqlData item : changedResources.values()) {
-                if (ROOT_PATH.equals(item.getPath())) {
-                    throw new PersistenceException("Unable to store resource at {}" + item.getPath(), null, item.getPath(), null);
-                }
                 boolean created = adapter.store(item);
                 if (created) {
                     notifyAdded(item.getPath());
diff --git a/src/test/java/org/apache/sling/nosql/generic/resource/impl/AbstractNoSqlResourceProviderRootTest.java b/src/test/java/org/apache/sling/nosql/generic/resource/impl/AbstractNoSqlResourceProviderRootTest.java
index 82d88f0..1fead01 100644
--- a/src/test/java/org/apache/sling/nosql/generic/resource/impl/AbstractNoSqlResourceProviderRootTest.java
+++ b/src/test/java/org/apache/sling/nosql/generic/resource/impl/AbstractNoSqlResourceProviderRootTest.java
@@ -18,8 +18,10 @@
  */
 package org.apache.sling.nosql.generic.resource.impl;
 
+import static org.hamcrest.CoreMatchers.equalTo;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 
 import java.io.IOException;
@@ -117,12 +119,15 @@ public abstract class AbstractNoSqlResourceProviderRootTest {
         context.resourceResolver().delete(root);
     }
 
-    @Test(expected = Throwable.class)
+    @Test
     public void testUpdateRootPath() throws PersistenceException {
         Resource root = context.resourceResolver().getResource("/");
         ModifiableValueMap props = root.adaptTo(ModifiableValueMap.class);
         props.put("prop1", "value1");
         context.resourceResolver().commit();
+        
+        root = context.resourceResolver().getResource("/");
+        assertThat(root.getValueMap().get("prop1", String.class), equalTo("value1"));
     }
 
 }

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.