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/10/18 23:24:48 UTC

[sling-org-apache-sling-mongodb] branch master created (now df2c32b)

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

rombert pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-mongodb.git.


      at df2c32b  SLING-7167 Adjust READMEs

This branch includes the following new commits:

     new 45b6b2a  New MongoDB resource provider
     new 4bb7170  New MongoDB resource provider
     new b786d73  New MongoDB resource provider
     new 0fada4c  New MongoDB resource provider
     new 6536b75  New MongoDB resource provider
     new db60601  New MongoDB resource provider
     new a51a804  SLING-2530 : Implement CRUD based on resources
     new ab55fbc  SLING-2530 : Implement CRUD based on resources
     new de303c8  Send notification events for changes
     new b2fc1f0  Set dependencies to latest snapshots after release
     new 8b47558  Update to released bundles
     new 9f1884c  Use latest releases and update to new parent pom
     new e8b9087  Update to latest parent pom and use latest releases in launchpad
     new 9738422  SLING-2739 :  Add methods for handling the resource type hierarchy to the resource resolver
     new a7876d6  Use latest snapshot
     new 98644a0  Distribute events in a cluster
     new 0d6b213  Use released versions after release.
     new a117cff  Correct reactor pom and update to parent pom 16
     new 0305f91  Update to latest parent pom
     new 4c0625f  SLING-3002 : Make the Mongo Resource Provider easier to subclass. Apply patch from Dan McWeeney
     new c1260b0  Update to parent pom 18
     new 26027ca  Use latest mongo driver
     new 4964922  SLING-3451 : Support for deep reads from a value map
     new cca81f8  SLING-3451 : Support for deep reads from a value map
     new 3131883  extensions/mongodb: use released versions for dependencies
     new be42568  Update to parent pom v19
     new b958be8  Update to latest parent pom 20
     new 39d6fdb  SLING-3916 - Add simple query support to the MongoDBResourceProvider
     new 5e36443  Update to Sling Parent POM 22 with baselining enabled
     new 1930088  Update contrib modules to Parent 23
     new ca7145d  set parent version to 24 and add empty relativePath where missing
     new e7b9ae0  SLING-5024 add/update readme
     new 12ce72a  Update the contrib reactor to parent 25
     new 943c789  Switch to parent pom 26
     new c940f8a  SLING-7167 Adjust READMEs
     new df2c32b  SLING-7167 Adjust READMEs

The 36 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


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

[sling-org-apache-sling-mongodb] 19/36: Update to latest parent pom

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-mongodb.git

commit 0305f913f3226a2b8e0cfdc0718a11639ffeb330
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Fri Jul 19 07:04:15 2013 +0000

    Update to latest parent pom
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1504788 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index 2ec2748..7967332 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
     <parent>
         <groupId>org.apache.sling</groupId>
         <artifactId>sling</artifactId>
-        <version>16</version>
+        <version>17</version>
     </parent>
 
     <groupId>org.apache.sling</groupId>

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

[sling-org-apache-sling-mongodb] 07/36: SLING-2530 : Implement CRUD based on resources

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-mongodb.git

commit a51a80425115340935af1c3dd86df74687ce57bb
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Wed Sep 26 09:55:47 2012 +0000

    SLING-2530 : Implement CRUD based on resources
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1390361 13f79535-47bb-0310-9956-ffa450edef68
---
 .../apache/sling/mongodb/impl/MongoDBResourceProvider.java | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProvider.java b/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProvider.java
index eafb2b9..49356b5 100644
--- a/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProvider.java
+++ b/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProvider.java
@@ -165,17 +165,17 @@ public class MongoDBResourceProvider implements ResourceProvider, ModifyingResou
     }
 
     /**
-     * @see org.apache.sling.api.resource.ModifyingResourceProvider#revert()
+     * @see org.apache.sling.api.resource.ModifyingResourceProvider#revert(ResourceResolver)
      */
-    public void revert() {
+    public void revert(final ResourceResolver resolver) {
         this.changedResources.clear();
         this.deletedResources.clear();
     }
 
     /**
-     * @see org.apache.sling.api.resource.ModifyingResourceProvider#commit()
+     * @see org.apache.sling.api.resource.ModifyingResourceProvider#commit(ResourceResolver)
      */
-    public void commit() throws PersistenceException {
+    public void commit(final ResourceResolver resolver) throws PersistenceException {
         try {
             for(final String deleted : this.deletedResources) {
                 final String[] info = this.extractResourceInfo(deleted);
@@ -203,14 +203,14 @@ public class MongoDBResourceProvider implements ResourceProvider, ModifyingResou
                 }
             }
         } finally {
-            this.revert();
+            this.revert(resolver);
         }
     }
 
     /**
-     * @see org.apache.sling.api.resource.ModifyingResourceProvider#hasChanges()
+     * @see org.apache.sling.api.resource.ModifyingResourceProvider#hasChanges(ResourceResolver)
      */
-    public boolean hasChanges() {
+    public boolean hasChanges(final ResourceResolver resolver) {
         return this.changedResources.size() > 0 || this.deletedResources.size() > 0;
     }
 

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

[sling-org-apache-sling-mongodb] 09/36: Send notification events for changes

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-mongodb.git

commit de303c8c6788b27e70e33f6967b820c99f38b88c
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Tue Oct 2 09:33:35 2012 +0000

    Send notification events for changes
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1392811 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml                                            |  6 +-
 .../apache/sling/mongodb/impl/MongoDBContext.java  | 82 ++++++++++++++--------
 .../mongodb/impl/MongoDBResourceProvider.java      | 68 +++++++++---------
 .../impl/MongoDBResourceProviderFactory.java       | 30 ++++++--
 4 files changed, 117 insertions(+), 69 deletions(-)

diff --git a/pom.xml b/pom.xml
index f73379a..b491fbb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -76,10 +76,14 @@
         <dependency>
         	<groupId>org.mongodb</groupId>
         	<artifactId>mongo-java-driver</artifactId>
-        	<version>2.8.0</version>
+        	<version>2.9.1</version>
             <scope>provided</scope>
         </dependency>
         <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+        </dependency>
+        <dependency>
         	<groupId>org.apache.felix</groupId>
         	<artifactId>org.apache.felix.scr.annotations</artifactId>
         </dependency>
diff --git a/src/main/java/org/apache/sling/mongodb/impl/MongoDBContext.java b/src/main/java/org/apache/sling/mongodb/impl/MongoDBContext.java
index c801e8b..b1dc3fa 100644
--- a/src/main/java/org/apache/sling/mongodb/impl/MongoDBContext.java
+++ b/src/main/java/org/apache/sling/mongodb/impl/MongoDBContext.java
@@ -16,20 +16,24 @@
  */
 package org.apache.sling.mongodb.impl;
 
-import java.util.ArrayList;
+import java.util.Dictionary;
 import java.util.HashSet;
-import java.util.List;
+import java.util.Hashtable;
 import java.util.Set;
 
+import org.apache.sling.api.SlingConstants;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventAdmin;
+
 import com.mongodb.DB;
 
 public class MongoDBContext {
 
     /** The roots. */
-    private final String[] roots;
+    private final String root;
 
     /** The roots ended by a slash. */
-    private final String[] rootsWithSlash;
+    private final String rootWithSlash;
 
     /** Don't show these collections. */
     private final Set<String> filterCollectionNames = new HashSet<String>();
@@ -37,46 +41,45 @@ public class MongoDBContext {
     /** The database to be used. */
     private final DB database;
 
+    private final EventAdmin eventAdmin;
+
     public MongoDBContext(final DB database,
-                    final String[] configuredRoots,
-                    final String[] configuredFilterCollectionNames) {
+            final String configuredRoot,
+            final String[] configuredFilterCollectionNames,
+            final EventAdmin eventAdmin) {
         this.database = database;
-        if ( configuredRoots != null ) {
-            final List<String> rootsList = new ArrayList<String>();
-            final List<String> rootsWithSlashList = new ArrayList<String>();
-            for(final String r : configuredRoots) {
-                if ( r != null ) {
-                    final String value = r.trim();
-                    if ( value.length() > 0 ) {
-                        if ( value.endsWith("/") ) {
-                            rootsWithSlashList.add(value);
-                            rootsList.add(value.substring(0, value.length() - 1));
-                        } else {
-                            rootsWithSlashList.add(value + "/");
-                            rootsList.add(value);
-                        }
-                    }
+        if ( configuredRoot != null ) {
+            final String value = configuredRoot.trim();
+            if ( value.length() > 0 ) {
+                if ( value.endsWith("/") ) {
+                    this.rootWithSlash = configuredRoot;
+                    this.root = configuredRoot.substring(0, configuredRoot.length() - 1);
+                } else {
+                    this.rootWithSlash = configuredRoot + "/";
+                    this.root = configuredRoot;
                 }
+            } else {
+                this.root = "";
+                this.rootWithSlash = "/";
             }
-            this.roots = rootsList.toArray(new String[rootsList.size()]);
-            this.rootsWithSlash = rootsWithSlashList.toArray(new String[rootsWithSlashList.size()]);
         } else {
-            this.roots = new String[0];
-            this.rootsWithSlash = new String[0];
+            this.root = "";
+            this.rootWithSlash = "/";
         }
         if ( configuredFilterCollectionNames != null ) {
             for(final String name : configuredFilterCollectionNames) {
                 this.filterCollectionNames.add(name);
             }
         }
+        this.eventAdmin = eventAdmin;
     }
 
-    public String[] getRoots() {
-        return roots;
+    public String getRoot() {
+        return root;
     }
 
-    public String[] getRootsWithSlash() {
-        return this.rootsWithSlash;
+    public String getRootWithSlash() {
+        return this.rootWithSlash;
     }
 
     public boolean isFilterCollectionName(final String name) {
@@ -90,4 +93,25 @@ public class MongoDBContext {
     public DB getDatabase() {
         return this.database;
     }
+
+    public void notifyRemoved(final String[] info) {
+        final Dictionary<String, Object> props = new Hashtable<String, Object>();
+        props.put(SlingConstants.PROPERTY_PATH, this.rootWithSlash + info[0] + '/' + info[1]);
+        final Event event = new Event(SlingConstants.TOPIC_RESOURCE_REMOVED, props);
+        this.eventAdmin.postEvent(event);
+    }
+
+    public void notifyAddeed(final String[] info) {
+        final Dictionary<String, Object> props = new Hashtable<String, Object>();
+        props.put(SlingConstants.PROPERTY_PATH, this.rootWithSlash + info[0] + '/' + info[1]);
+        final Event event = new Event(SlingConstants.TOPIC_RESOURCE_ADDED, props);
+        this.eventAdmin.postEvent(event);
+    }
+
+    public void notifyUpdated(final String[] info) {
+        final Dictionary<String, Object> props = new Hashtable<String, Object>();
+        props.put(SlingConstants.PROPERTY_PATH, this.rootWithSlash + info[0] + '/' + info[1]);
+        final Event event = new Event(SlingConstants.TOPIC_RESOURCE_CHANGED, props);
+        this.eventAdmin.postEvent(event);
+    }
 }
diff --git a/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProvider.java b/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProvider.java
index 49356b5..b362e16 100644
--- a/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProvider.java
+++ b/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProvider.java
@@ -86,7 +86,7 @@ public class MongoDBResourceProvider implements ResourceProvider, ModifyingResou
      * @see org.apache.sling.api.resource.ModifyingResourceProvider#create(org.apache.sling.api.resource.ResourceResolver, java.lang.String, java.util.Map)
      */
     public Resource create(final ResourceResolver resolver, final String path, final Map<String, Object> properties)
-    throws PersistenceException {
+            throws PersistenceException {
         final String[] info = this.extractResourceInfo(path);
         if ( info != null && info.length == 2) {
             final boolean deleted = this.deletedResources.remove(path);
@@ -122,7 +122,7 @@ public class MongoDBResourceProvider implements ResourceProvider, ModifyingResou
      * @see org.apache.sling.api.resource.ModifyingResourceProvider#delete(org.apache.sling.api.resource.ResourceResolver, java.lang.String)
      */
     public void delete(final ResourceResolver resolver, final String path)
-    throws PersistenceException {
+            throws PersistenceException {
         final String[] info = this.extractResourceInfo(path);
         if ( info != null ) {
             boolean deletedResource = false;
@@ -183,20 +183,26 @@ public class MongoDBResourceProvider implements ResourceProvider, ModifyingResou
                 // check if the collection still exists
                 final DBCollection col = this.getCollection(info[0]);
                 if ( col != null ) {
-                    col.findAndRemove(QueryBuilder.start(PROP_PATH).is(info[1]).get());
+                    if ( col.findAndRemove(QueryBuilder.start(PROP_PATH).is(info[1]).get()) != null ) {
+                        this.context.notifyRemoved(info);
+                    }
                 }
             }
             for(final MongoDBResource changed : this.changedResources.values()) {
 
                 final DBCollection col = this.context.getDatabase().getCollection(changed.getCollection());
                 if ( col != null ) {
+                    final String[] info = new String[] {changed.getCollection(),
+                            changed.getProperties().get(PROP_PATH).toString()};
                     // create or update?
                     if ( changed.getProperties().get(PROP_ID) != null ) {
                         col.update(QueryBuilder.start(PROP_PATH).is(changed.getProperties().get(PROP_PATH)).get(),
-                                        changed.getProperties());
+                                changed.getProperties());
+                        this.context.notifyUpdated(info);
                     } else {
                         // create
                         col.save(changed.getProperties());
+                        this.context.notifyUpdated(info);
                     }
                 } else {
                     throw new PersistenceException("Unable to create collection " + changed.getCollection(), null, changed.getPath(), null);
@@ -279,7 +285,7 @@ public class MongoDBResourceProvider implements ResourceProvider, ModifyingResou
 
                 final DBObject query = QueryBuilder.start(PROP_PATH).regex(Pattern.compile(pattern)).get();
                 final DBCursor cur = col.find(query).
-                                sort(BasicDBObjectBuilder.start(PROP_PATH, 1).get());
+                        sort(BasicDBObjectBuilder.start(PROP_PATH, 1).get());
                 return new Iterator<Resource>() {
 
                     public boolean hasNext() {
@@ -297,10 +303,10 @@ public class MongoDBResourceProvider implements ResourceProvider, ModifyingResou
                             name = objPath.substring(lastSlash + 1);
                         }
                         return new MongoDBResource(parent.getResourceResolver(),
-                                        parent.getPath() + '/' + name,
-                                        info[0],
-                                        obj,
-                                        MongoDBResourceProvider.this);
+                                parent.getPath() + '/' + name,
+                                info[0],
+                                obj,
+                                MongoDBResourceProvider.this);
                     }
 
                     public void remove() {
@@ -318,8 +324,8 @@ public class MongoDBResourceProvider implements ResourceProvider, ModifyingResou
      */
     @SuppressWarnings("javadoc")
     public Resource getResource(final ResourceResolver resourceResolver,
-                    final HttpServletRequest request,
-                    final String path) {
+            final HttpServletRequest request,
+            final String path) {
         return this.getResource(resourceResolver, path);
     }
 
@@ -327,27 +333,25 @@ public class MongoDBResourceProvider implements ResourceProvider, ModifyingResou
      * Extract info about collection and path
      */
     private String[] extractResourceInfo(final String path) {
-        for(final String root : this.context.getRootsWithSlash()) {
-            if ( path.startsWith(root) ) {
-                if ( path.length() == root.length() ) {
-                    // special resource - show all collections
-                    return new String[0];
-                }
-                final String info = path.substring(root.length());
-                final int slashPos = info.indexOf('/');
-                if ( slashPos != -1 ) {
-                    return new String[] {info.substring(0, slashPos), info.substring(slashPos + 1)};
-                }
-                // special resource - collection
-                return new String[] {info};
-            }
-        }
-        for(final String root : this.context.getRoots()) {
-            if ( path.equals(root) ) {
+        if ( path.startsWith(this.context.getRootWithSlash()) ) {
+            if ( path.length() == this.context.getRootWithSlash().length() ) {
                 // special resource - show all collections
                 return new String[0];
             }
+            final String info = path.substring(this.context.getRootWithSlash().length());
+            final int slashPos = info.indexOf('/');
+            if ( slashPos != -1 ) {
+                return new String[] {info.substring(0, slashPos), info.substring(slashPos + 1)};
+            }
+            // special resource - collection
+            return new String[] {info};
+        }
+
+        if ( path.equals(this.context.getRoot()) ) {
+            // special resource - show all collections
+            return new String[0];
         }
+
         return null;
     }
 
@@ -390,10 +394,10 @@ public class MongoDBResourceProvider implements ResourceProvider, ModifyingResou
             logger.debug("Found {}", obj);
             if ( obj != null ) {
                 return new MongoDBResource(resourceResolver,
-                                path,
-                                info[0],
-                                obj,
-                                this);
+                        path,
+                        info[0],
+                        obj,
+                        this);
             }
         }
 
diff --git a/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProviderFactory.java b/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProviderFactory.java
index a632215..5eaeca0 100644
--- a/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProviderFactory.java
+++ b/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProviderFactory.java
@@ -24,11 +24,13 @@ import org.apache.felix.scr.annotations.ConfigurationPolicy;
 import org.apache.felix.scr.annotations.Properties;
 import org.apache.felix.scr.annotations.Property;
 import org.apache.felix.scr.annotations.PropertyUnbounded;
+import org.apache.felix.scr.annotations.Reference;
 import org.apache.felix.scr.annotations.Service;
 import org.apache.sling.api.resource.LoginException;
 import org.apache.sling.api.resource.ResourceProvider;
 import org.apache.sling.api.resource.ResourceProviderFactory;
 import org.apache.sling.commons.osgi.PropertiesUtil;
+import org.osgi.service.event.EventAdmin;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -40,10 +42,10 @@ import com.mongodb.Mongo;
  * in MongoDB.
  */
 @Component(label="%factory.name",
-           description="%factory.description",
-           configurationFactory=true,
-           policy=ConfigurationPolicy.REQUIRE,
-           metatype=true)
+description="%factory.description",
+configurationFactory=true,
+policy=ConfigurationPolicy.REQUIRE,
+metatype=true)
 @Service(value=ResourceProviderFactory.class)
 @Properties({
     @Property(name=ResourceProvider.ROOTS, value="/mongo")
@@ -74,21 +76,35 @@ public class MongoDBResourceProviderFactory implements ResourceProviderFactory {
     /** The global context passed to each resource provider. */
     private MongoDBContext context;
 
+    @Reference
+    private EventAdmin eventAdmin;
+
     @Activate
     protected void activate(final Map<String, Object> props) throws Exception {
+        final String[] roots = PropertiesUtil.toStringArray(props.get(ResourceProvider.ROOTS));
+        if ( roots == null || roots.length == 0 ) {
+            throw new Exception("Roots configuration is missing.");
+        }
+        if ( roots.length > 1 ) {
+            throw new Exception("Only a single root should be configured.");
+        }
+        if ( roots[0] == null || roots[0].trim().length() == 0 ) {
+            throw new Exception("Roots configuration is missing.");
+        }
         final String host = PropertiesUtil.toString(props.get(PROP_HOST), DEFAULT_HOST);
         final int port = PropertiesUtil.toInteger(props.get(PROP_PORT), DEFAULT_PORT);
         final String db = PropertiesUtil.toString(props.get(PROP_DB), DEFAULT_DB);
         logger.info("Starting MongoDB resource provider with host={}, port={}, db={}",
-                        new Object[] {host, port, db});
+                new Object[] {host, port, db});
 
         final Mongo m = new Mongo( host , port );
         final DB database = m.getDB( db );
         logger.info("Connected to database {}", database);
 
         this.context = new MongoDBContext(database,
-                        PropertiesUtil.toStringArray(props.get(ResourceProvider.ROOTS)),
-                        PropertiesUtil.toStringArray(props.get(PROP_FILTER_COLLECTIONS)));
+                roots[0],
+                PropertiesUtil.toStringArray(props.get(PROP_FILTER_COLLECTIONS)),
+                this.eventAdmin);
     }
 
     /**

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

[sling-org-apache-sling-mongodb] 24/36: SLING-3451 : Support for deep reads from a value map

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-mongodb.git

commit cca81f8cebe4768e044f9579694bc5036d499f91
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Sun Mar 16 09:42:06 2014 +0000

    SLING-3451 : Support for deep reads from a value map
    
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1578011 13f79535-47bb-0310-9956-ffa450edef68
---
 .../org/apache/sling/mongodb/impl/MongoDBResource.java  |  3 ++-
 .../org/apache/sling/mongodb/impl/ReadableValueMap.java | 17 +++++++++--------
 2 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/src/main/java/org/apache/sling/mongodb/impl/MongoDBResource.java b/src/main/java/org/apache/sling/mongodb/impl/MongoDBResource.java
index 5bae7fa..a45335b 100644
--- a/src/main/java/org/apache/sling/mongodb/impl/MongoDBResource.java
+++ b/src/main/java/org/apache/sling/mongodb/impl/MongoDBResource.java
@@ -23,6 +23,7 @@ import org.apache.sling.api.resource.ModifiableValueMap;
 import org.apache.sling.api.resource.ResourceMetadata;
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.api.wrappers.DeepReadModifiableValueMapDecorator;
 import org.apache.sling.api.wrappers.DeepReadValueMapDecorator;
 
 import com.mongodb.DBObject;
@@ -122,7 +123,7 @@ public class MongoDBResource extends AbstractResource {
             return (AdapterType) new DeepReadValueMapDecorator(this, new ReadableValueMap(this.dbObject));
         } else if ( type == ModifiableValueMap.class ) {
             this.dbObject = this.provider.getUpdatedDBObject(this.resourcePath, this.dbObject);
-            return (AdapterType) new DeepReadValueMapDecorator(this, new ChangeableValueMap(this));
+            return (AdapterType) new DeepReadModifiableValueMapDecorator(this, new ChangeableValueMap(this));
         }
 
         return super.adaptTo(type);
diff --git a/src/main/java/org/apache/sling/mongodb/impl/ReadableValueMap.java b/src/main/java/org/apache/sling/mongodb/impl/ReadableValueMap.java
index a363591..f3eee76 100644
--- a/src/main/java/org/apache/sling/mongodb/impl/ReadableValueMap.java
+++ b/src/main/java/org/apache/sling/mongodb/impl/ReadableValueMap.java
@@ -38,17 +38,18 @@ public class ReadableValueMap implements ValueMap {
     }
 
     protected void createValueMap(final DBObject dbObject) {
-        final Map<String, Object> map = new HashMap<String, Object>();
         if (dbObject == null) {
             this.valueMap = Collections.<String, Object> emptyMap();
-        }
-        for(final String key : dbObject.keySet()) {
-            final String name = MongoDBResourceProvider.keyToPropName(key);
-            if ( name != null ) {
-                map.put(key, dbObject.get(name));
+        } else {
+            final Map<String, Object> map = new HashMap<String, Object>();
+            for(final String key : dbObject.keySet()) {
+                final String name = MongoDBResourceProvider.keyToPropName(key);
+                if ( name != null ) {
+                    map.put(key, dbObject.get(name));
+                }
             }
+            this.valueMap = Collections.unmodifiableMap(map);
         }
-        this.valueMap = Collections.unmodifiableMap(map);
     }
 
     /**
@@ -204,7 +205,7 @@ public class ReadableValueMap implements ValueMap {
 
     /**
      * Converts the object to an array of the given type
-     * @param obj tje object or object array
+     * @param obj the object or object array
      * @param type the component type of the array
      * @return and array of type T
      */

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

[sling-org-apache-sling-mongodb] 35/36: SLING-7167 Adjust READMEs

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-mongodb.git

commit c940f8a74ff310a2e1db43975f2cdfea25a47cc9
Author: Oliver Lietz <ol...@apache.org>
AuthorDate: Mon Oct 2 16:18:38 2017 +0000

    SLING-7167 Adjust READMEs
    
    switch from plain text to Markdown
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1810509 13f79535-47bb-0310-9956-ffa450edef68
---
 README.txt => README.md | 0
 1 file changed, 0 insertions(+), 0 deletions(-)

diff --git a/README.txt b/README.md
similarity index 100%
rename from README.txt
rename to README.md

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

[sling-org-apache-sling-mongodb] 05/36: New MongoDB resource provider

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-mongodb.git

commit 6536b754f6384d6d2713f150f157673f9c1af248
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Thu Aug 2 06:17:18 2012 +0000

    New MongoDB resource provider
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1368356 13f79535-47bb-0310-9956-ffa450edef68
---
 .../mongodb/impl/MongoDBResourceProvider.java      | 50 ++++++++++++++--------
 1 file changed, 31 insertions(+), 19 deletions(-)

diff --git a/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProvider.java b/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProvider.java
index 8bea67a..c35a8f1 100644
--- a/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProvider.java
+++ b/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProvider.java
@@ -118,27 +118,39 @@ public class MongoDBResourceProvider implements ResourceProvider, ModifyingResou
      */
     public void delete(final ResourceResolver resolver, final String path)
     throws PersistenceException {
-        if ( deletedResources.contains(path) ) {
-            return;
-        }
-
         final String[] info = this.extractResourceInfo(path);
         if ( info != null ) {
-            final Resource rsrc = this.getResource(resolver, path, info);
-            if ( rsrc instanceof MongoDBResource ) {
-                this.deletedResources.add(path);
-                this.changedResources.remove(path);
-
-                final DBCollection col = this.getCollection(info[0]);
-                final String pattern = "^" + Pattern.quote(info[1]) + "/";
-
-                final DBObject query = QueryBuilder.start(PROP_PATH).regex(Pattern.compile(pattern)).get();
-                final DBCursor cur = col.find(query);
-                while ( cur.hasNext() ) {
-                    final DBObject dbObj = cur.next();
-                    final String childPath = info[0] + '/' + dbObj.get(PROP_PATH);
-                    this.deletedResources.add(childPath);
-                    this.changedResources.remove(childPath);
+            boolean deletedResource = false;
+            if ( !deletedResources.contains(path) ) {
+                final Resource rsrc = this.getResource(resolver, path, info);
+                if ( rsrc instanceof MongoDBResource ) {
+                    this.deletedResources.add(path);
+                    this.changedResources.remove(path);
+
+                    final DBCollection col = this.getCollection(info[0]);
+                    final String pattern = "^" + Pattern.quote(info[1]) + "/";
+
+                    final DBObject query = QueryBuilder.start(PROP_PATH).regex(Pattern.compile(pattern)).get();
+                    final DBCursor cur = col.find(query);
+                    while ( cur.hasNext() ) {
+                        final DBObject dbObj = cur.next();
+                        final String childPath = info[0] + '/' + dbObj.get(PROP_PATH);
+                        this.deletedResources.add(childPath);
+                        this.changedResources.remove(childPath);
+                    }
+                    deletedResource = true;
+                }
+            } else {
+                deletedResource = true;
+            }
+            if ( deletedResource ) {
+                final String prefix = path + "/";
+                final Iterator<Map.Entry<String, MongoDBResource>> i = this.changedResources.entrySet().iterator();
+                while ( i.hasNext() ) {
+                    final Map.Entry<String, MongoDBResource> entry = i.next();
+                    if ( entry.getKey().startsWith(prefix) ) {
+                        i.remove();
+                    }
                 }
                 return;
             }

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

[sling-org-apache-sling-mongodb] 31/36: set parent version to 24 and add empty relativePath where missing

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-mongodb.git

commit ca7145dcb9074ee80eb58620d4962d387540cce3
Author: Oliver Lietz <ol...@apache.org>
AuthorDate: Tue Jul 7 07:36:29 2015 +0000

    set parent version to 24 and add empty relativePath where missing
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1689588 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index f11af74..c1b19d1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,8 @@
     <parent>
         <groupId>org.apache.sling</groupId>
         <artifactId>sling</artifactId>
-        <version>23</version>
+        <version>24</version>
+        <relativePath/>
     </parent>
 
     <groupId>org.apache.sling</groupId>

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

[sling-org-apache-sling-mongodb] 34/36: Switch to parent pom 26

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-mongodb.git

commit 943c789d9aa0f153e77dc0c0bdde0c20444f6292
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Sun Jan 3 14:07:46 2016 +0000

    Switch to parent pom 26
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1722720 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index 861687d..4167e7a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
     <parent>
         <groupId>org.apache.sling</groupId>
         <artifactId>sling</artifactId>
-        <version>25</version>
+        <version>26</version>
         <relativePath/>
     </parent>
 

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

[sling-org-apache-sling-mongodb] 22/36: Use latest mongo driver

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-mongodb.git

commit 26027ca76802b86edee755edacdfb052a4bb3529
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Sun Sep 22 10:38:08 2013 +0000

    Use latest mongo driver
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1525343 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml                                                    |  2 +-
 .../org/apache/sling/mongodb/impl/MongoDBResource.java     |  7 +++++++
 .../apache/sling/mongodb/impl/MongoDBResourceProvider.java | 14 +++++++-------
 3 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/pom.xml b/pom.xml
index 5a5e1a9..07bb13d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -76,7 +76,7 @@
         <dependency>
         	<groupId>org.mongodb</groupId>
         	<artifactId>mongo-java-driver</artifactId>
-        	<version>2.9.1</version>
+        	<version>2.11.3</version>
             <scope>provided</scope>
         </dependency>
         <dependency>
diff --git a/src/main/java/org/apache/sling/mongodb/impl/MongoDBResource.java b/src/main/java/org/apache/sling/mongodb/impl/MongoDBResource.java
index 0aad630..93c51e4 100644
--- a/src/main/java/org/apache/sling/mongodb/impl/MongoDBResource.java
+++ b/src/main/java/org/apache/sling/mongodb/impl/MongoDBResource.java
@@ -58,6 +58,13 @@ public class MongoDBResource extends AbstractResource {
         this.provider = provider;
     }
 
+    public MongoDBResource(final MongoDBResource source) {
+        this.resourceResolver = source.resourceResolver;
+        this.resourcePath = source.resourcePath;
+        this.collection = source.collection;
+        this.dbObject = source.dbObject;
+        this.provider = source.provider;
+    }
     /**
      * @see org.apache.sling.api.resource.Resource#getPath()
      */
diff --git a/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProvider.java b/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProvider.java
index b1168ed..55fdb5f 100644
--- a/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProvider.java
+++ b/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProvider.java
@@ -230,7 +230,7 @@ public class MongoDBResourceProvider implements ResourceProvider, ModifyingResou
             return null;
         }
         if ( this.changedResources.containsKey(path) ) {
-            return this.changedResources.get(path);
+            return new MongoDBResource(this.changedResources.get(path));
         }
         final String[] info = this.extractResourceInfo(path);
         if ( info != null ) {
@@ -366,12 +366,12 @@ public class MongoDBResourceProvider implements ResourceProvider, ModifyingResou
         return names.contains(name) && !this.context.isFilterCollectionName(name);
     }
 
-    
+
     /**
      * Check if a collection with a given name exists and return it
      */
     protected DBCollection getCollection(final String name) {
-        if ( this.hasCollection(name) ) {            
+        if ( this.hasCollection(name) ) {
             return this.context.getDatabase().getCollection(name);
         }
         return null;
@@ -418,19 +418,19 @@ public class MongoDBResourceProvider implements ResourceProvider, ModifyingResou
         }
         return dbObj;
     }
-    
+
     protected Set<String> getDeletedResources() {
         return this.deletedResources;
     }
-    
+
     protected Map<String, MongoDBResource> getChangedResources() {
         return this.changedResources;
     }
-    
+
     protected MongoDBContext getContext() {
         return this.context;
     }
-    
+
     protected String getPROP_PATH() {
         return PROP_PATH;
     }

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

[sling-org-apache-sling-mongodb] 26/36: Update to parent pom v19

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-mongodb.git

commit be4256892d957c5fbedeb17933dc579c04fc4eaa
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Mon Mar 31 14:39:20 2014 +0000

    Update to parent pom v19
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1583337 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index e769857..a7cd22e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
     <parent>
         <groupId>org.apache.sling</groupId>
         <artifactId>sling</artifactId>
-        <version>18</version>
+        <version>19</version>
     </parent>
 
     <groupId>org.apache.sling</groupId>

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

[sling-org-apache-sling-mongodb] 14/36: SLING-2739 : Add methods for handling the resource type hierarchy to the resource resolver

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-mongodb.git

commit 97384222b01eaa196ea474a56684f3dab558dad3
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Fri Feb 22 09:09:59 2013 +0000

    SLING-2739 :  Add methods for handling the resource type hierarchy to the resource resolver
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1448950 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index c722a5a..e2b2d90 100644
--- a/pom.xml
+++ b/pom.xml
@@ -64,7 +64,7 @@
         <dependency>
     	    <groupId>org.apache.sling</groupId>
     	    <artifactId>org.apache.sling.api</artifactId>
-    	    <version>2.3.0</version>
+    	    <version>2.3.1-SNAPSHOT</version>
     	    <scope>provided</scope>
         </dependency>
         <dependency>

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

[sling-org-apache-sling-mongodb] 23/36: SLING-3451 : Support for deep reads from a value map

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-mongodb.git

commit 4964922cd85d349f2be31ef7b8298054d6132e05
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Fri Mar 14 13:49:01 2014 +0000

    SLING-3451 : Support for deep reads from a value map
    
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1577529 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml                                                             | 2 +-
 .../org/apache/sling/mongodb/impl/MongoDBCollectionResource.java    | 6 +-----
 src/main/java/org/apache/sling/mongodb/impl/MongoDBResource.java    | 5 +++--
 3 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/pom.xml b/pom.xml
index 07bb13d..4886c18 100644
--- a/pom.xml
+++ b/pom.xml
@@ -64,7 +64,7 @@
         <dependency>
     	    <groupId>org.apache.sling</groupId>
     	    <artifactId>org.apache.sling.api</artifactId>
-    	    <version>2.4.0</version>
+    	    <version>2.6.1-SNAPSHOT</version>
     	    <scope>provided</scope>
         </dependency>
         <dependency>
diff --git a/src/main/java/org/apache/sling/mongodb/impl/MongoDBCollectionResource.java b/src/main/java/org/apache/sling/mongodb/impl/MongoDBCollectionResource.java
index 6cccb4a..6b2ae0b 100644
--- a/src/main/java/org/apache/sling/mongodb/impl/MongoDBCollectionResource.java
+++ b/src/main/java/org/apache/sling/mongodb/impl/MongoDBCollectionResource.java
@@ -22,8 +22,6 @@ import java.util.Map;
 import org.apache.sling.api.resource.AbstractResource;
 import org.apache.sling.api.resource.ResourceMetadata;
 import org.apache.sling.api.resource.ResourceResolver;
-import org.apache.sling.api.resource.ValueMap;
-import org.apache.sling.api.wrappers.ValueMapDecorator;
 
 public class MongoDBCollectionResource extends AbstractResource {
 
@@ -80,9 +78,7 @@ public class MongoDBCollectionResource extends AbstractResource {
     @SuppressWarnings("unchecked")
     @Override
     public <AdapterType> AdapterType adaptTo(final Class<AdapterType> type) {
-        if ( type == ValueMap.class ) {
-            return (AdapterType) new ValueMapDecorator(Collections.EMPTY_MAP);
-        } else if ( type == Map.class ) {
+        if ( type == Map.class ) {
             return (AdapterType) Collections.EMPTY_MAP;
         }
         return super.adaptTo(type);
diff --git a/src/main/java/org/apache/sling/mongodb/impl/MongoDBResource.java b/src/main/java/org/apache/sling/mongodb/impl/MongoDBResource.java
index 93c51e4..5bae7fa 100644
--- a/src/main/java/org/apache/sling/mongodb/impl/MongoDBResource.java
+++ b/src/main/java/org/apache/sling/mongodb/impl/MongoDBResource.java
@@ -23,6 +23,7 @@ import org.apache.sling.api.resource.ModifiableValueMap;
 import org.apache.sling.api.resource.ResourceMetadata;
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.api.wrappers.DeepReadValueMapDecorator;
 
 import com.mongodb.DBObject;
 
@@ -118,10 +119,10 @@ public class MongoDBResource extends AbstractResource {
     public <AdapterType> AdapterType adaptTo(final Class<AdapterType> type) {
         if ( type == ValueMap.class || type == Map.class ) {
             this.dbObject = this.provider.getUpdatedDBObject(this.resourcePath, this.dbObject);
-            return (AdapterType) new ReadableValueMap(this.dbObject);
+            return (AdapterType) new DeepReadValueMapDecorator(this, new ReadableValueMap(this.dbObject));
         } else if ( type == ModifiableValueMap.class ) {
             this.dbObject = this.provider.getUpdatedDBObject(this.resourcePath, this.dbObject);
-            return (AdapterType) new ChangeableValueMap(this);
+            return (AdapterType) new DeepReadValueMapDecorator(this, new ChangeableValueMap(this));
         }
 
         return super.adaptTo(type);

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

[sling-org-apache-sling-mongodb] 13/36: Update to latest parent pom and use latest releases in launchpad

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-mongodb.git

commit e8b9087bd2875e03c2234cbe6e322b27f757bbbd
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Mon Feb 18 08:38:52 2013 +0000

    Update to latest parent pom and use latest releases in launchpad
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1447147 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index accacb2..c722a5a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
     <parent>
         <groupId>org.apache.sling</groupId>
         <artifactId>sling</artifactId>
-        <version>14</version>
+        <version>15</version>
     </parent>
 
     <groupId>org.apache.sling</groupId>

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

[sling-org-apache-sling-mongodb] 03/36: New MongoDB resource provider

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-mongodb.git

commit b786d7367e33fe3c1ef90a85f74b7454c1342e0b
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Wed Aug 1 18:42:28 2012 +0000

    New MongoDB resource provider
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1368189 13f79535-47bb-0310-9956-ffa450edef68
---
 .../sling/mongodb/impl/ChangeableValueMap.java     |  16 +-
 .../mongodb/impl/MongoDBResourceProvider.java      | 177 +++++++++++++--------
 .../sling/mongodb/impl/ReadableValueMap.java       |  16 +-
 3 files changed, 116 insertions(+), 93 deletions(-)

diff --git a/src/main/java/org/apache/sling/mongodb/impl/ChangeableValueMap.java b/src/main/java/org/apache/sling/mongodb/impl/ChangeableValueMap.java
index 493a737..5cc08b5 100644
--- a/src/main/java/org/apache/sling/mongodb/impl/ChangeableValueMap.java
+++ b/src/main/java/org/apache/sling/mongodb/impl/ChangeableValueMap.java
@@ -43,12 +43,8 @@ public class ChangeableValueMap
      */
     public Object put(final String name, final Object value) {
         final Object oldValue = this.valueMap.get(name);
-        final String key;
-        if ( name.startsWith("_") ) {
-            key = "_" + name;
-        } else {
-            key = name;
-        }
+        final String key = MongoDBResourceProvider.propNameToKey(name);
+
         this.resource.getProperties().put(key, value);
 
         // update map and resource
@@ -73,12 +69,8 @@ public class ChangeableValueMap
     public Object remove(final Object name) {
         final Object result = this.valueMap.get(name);
         if ( result != null ) {
-            final String key;
-            if ( name.toString().startsWith("_") ) {
-                key = "_" + name;
-            } else {
-                key = name.toString();
-            }
+            final String key = MongoDBResourceProvider.propNameToKey(name.toString());
+
             this.resource.getProperties().removeField(key);
 
             // update map and resource
diff --git a/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProvider.java b/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProvider.java
index 86a31c5..7ccbaf1 100644
--- a/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProvider.java
+++ b/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProvider.java
@@ -66,6 +66,22 @@ public class MongoDBResourceProvider implements ResourceProvider, ModifyingResou
         this.context = context;
     }
 
+    public static String propNameToKey(final String name) {
+        if ( name.startsWith("_") ) {
+            return "_" + name;
+        }
+        return name;
+    }
+
+    public static String keyToPropName(final String key) {
+        if ( key.startsWith("__") ) {
+            return key.substring(1);
+        } else if ( key.startsWith("_") ) {
+            return null;
+        }
+        return key;
+    }
+
     /**
      * @see org.apache.sling.api.resource.ModifyingResourceProvider#create(org.apache.sling.api.resource.ResourceResolver, java.lang.String, java.util.Map)
      */
@@ -82,12 +98,7 @@ public class MongoDBResourceProvider implements ResourceProvider, ModifyingResou
             dbObj.put(PROP_PATH, info[1]);
             if ( properties != null ) {
                 for(Map.Entry<String, Object> entry : properties.entrySet()) {
-                    final String key;
-                    if ( entry.getKey().startsWith("_") ) {
-                        key = "_" + entry.getKey();
-                    } else {
-                        key = entry.getKey();
-                    }
+                    final String key = propNameToKey(entry.getKey());
                     dbObj.put(key, entry.getValue());
                 }
             }
@@ -107,12 +118,33 @@ public class MongoDBResourceProvider implements ResourceProvider, ModifyingResou
      */
     public void delete(final ResourceResolver resolver, final String path)
     throws PersistenceException {
-        final Resource rsrc = this.getResource(resolver, path);
-        if ( rsrc != null ) {
-            // TODO - delete all child resources!
-            this.deletedResources.add(path);
-            this.changedResources.remove(path);
+        if ( deletedResources.contains(path) ) {
+            return;
         }
+
+        final String[] info = this.extractResourceInfo(path);
+        if ( info != null ) {
+            final Resource rsrc = this.getResource(resolver, path, info);
+            if ( rsrc instanceof MongoDBResource ) {
+                this.deletedResources.add(path);
+                this.changedResources.remove(path);
+
+                final DBCollection col = this.getCollection(info[0]);
+                final String pattern = "^" + Pattern.quote(info[1]) + "/";
+
+                final DBObject query = QueryBuilder.start(PROP_PATH).regex(Pattern.compile(pattern)).get();
+                final DBCursor cur = col.find(query);
+                while ( cur.hasNext() ) {
+                    final DBObject dbObj = cur.next();
+                    final String childPath = info[0] + '/' + dbObj.get(PROP_PATH);
+                    this.deletedResources.add(childPath);
+                    this.changedResources.remove(childPath);
+                }
+                return;
+            }
+
+        }
+        throw new PersistenceException("Unable to delete resource at {}" + path, null, path, null);
     }
 
     /**
@@ -131,12 +163,10 @@ public class MongoDBResourceProvider implements ResourceProvider, ModifyingResou
             for(final String deleted : this.deletedResources) {
                 final String[] info = this.extractResourceInfo(deleted);
 
-                // check if the database still exists
-                if ( this.hasDatabase(info[0]) ) {
-                    final DBCollection col = this.context.getDatabase().getCollection(info[0]);
-                    if ( col != null ) {
-                        col.findAndRemove(QueryBuilder.start(PROP_PATH).is(info[1]).get());
-                    }
+                // check if the collection still exists
+                final DBCollection col = this.getCollection(info[0]);
+                if ( col != null ) {
+                    col.findAndRemove(QueryBuilder.start(PROP_PATH).is(info[1]).get());
                 }
             }
             for(final MongoDBResource changed : this.changedResources.values()) {
@@ -217,48 +247,46 @@ public class MongoDBResourceProvider implements ResourceProvider, ModifyingResou
 
                 };
             }
-            if ( this.hasDatabase(info[0]) ) {
-                final DBCollection col = this.context.getDatabase().getCollection(info[0]);
-                if ( col != null ) {
-                    final String pattern;
-                    if ( info.length == 1 ) {
-                        pattern = "^([^/])*$";
-                    } else {
-                        pattern = "^" + Pattern.quote(info[1]) + "/([^/])*$";
-                    }
+            final DBCollection col = this.getCollection(info[0]);
+            if ( col != null ) {
+                final String pattern;
+                if ( info.length == 1 ) {
+                    pattern = "^([^/])*$";
+                } else {
+                    pattern = "^" + Pattern.quote(info[1]) + "/([^/])*$";
+                }
 
-                    final DBObject query = QueryBuilder.start(PROP_PATH).regex(Pattern.compile(pattern)).get();
-                    final DBCursor cur = col.find(query).
-                                    sort(BasicDBObjectBuilder.start(PROP_PATH, 1).get());
-                    return new Iterator<Resource>() {
+                final DBObject query = QueryBuilder.start(PROP_PATH).regex(Pattern.compile(pattern)).get();
+                final DBCursor cur = col.find(query).
+                                sort(BasicDBObjectBuilder.start(PROP_PATH, 1).get());
+                return new Iterator<Resource>() {
 
-                        public boolean hasNext() {
-                            return cur.hasNext();
-                        }
+                    public boolean hasNext() {
+                        return cur.hasNext();
+                    }
 
-                        public Resource next() {
-                            final DBObject obj = cur.next();
-                            final String objPath = obj.get(PROP_PATH).toString();
-                            final int lastSlash = objPath.lastIndexOf('/');
-                            final String name;
-                            if (lastSlash == -1) {
-                                name = objPath;
-                            } else {
-                                name = objPath.substring(lastSlash + 1);
-                            }
-                            return new MongoDBResource(parent.getResourceResolver(),
-                                            parent.getPath() + '/' + name,
-                                            info[0],
-                                            obj,
-                                            MongoDBResourceProvider.this);
+                    public Resource next() {
+                        final DBObject obj = cur.next();
+                        final String objPath = obj.get(PROP_PATH).toString();
+                        final int lastSlash = objPath.lastIndexOf('/');
+                        final String name;
+                        if (lastSlash == -1) {
+                            name = objPath;
+                        } else {
+                            name = objPath.substring(lastSlash + 1);
                         }
+                        return new MongoDBResource(parent.getResourceResolver(),
+                                        parent.getPath() + '/' + name,
+                                        info[0],
+                                        obj,
+                                        MongoDBResourceProvider.this);
+                    }
 
-                        public void remove() {
-                            throw new UnsupportedOperationException("remove");
-                        }
+                    public void remove() {
+                        throw new UnsupportedOperationException("remove");
+                    }
 
-                    };
-                }
+                };
             }
         }
         return null;
@@ -303,15 +331,25 @@ public class MongoDBResourceProvider implements ResourceProvider, ModifyingResou
     }
 
     /**
-     * Check if a database with a given name exists
+     * Check if a collection with a given name exists
      */
-    private boolean hasDatabase(final String name) {
+    private boolean hasCollection(final String name) {
         final Set<String> names = this.context.getDatabase().getCollectionNames();
         return names.contains(name) && !this.context.isFilterCollectionName(name);
     }
 
     /**
-     * Create a resource
+     * Check if a collection with a given name exists and return it
+     */
+    private DBCollection getCollection(final String name) {
+        if ( this.hasCollection(name) ) {
+            return this.context.getDatabase().getCollection(name);
+        }
+        return null;
+    }
+
+    /**
+     * Get a resource
      */
     private Resource getResource(final ResourceResolver resourceResolver, final String path, final String[] info) {
         if ( info.length == 0 ) {
@@ -319,26 +357,25 @@ public class MongoDBResourceProvider implements ResourceProvider, ModifyingResou
             return new MongoDBCollectionResource(resourceResolver, path);
         } else if ( info.length == 1 ) {
             // special resource : collection
-            if ( this.hasDatabase(info[0]) ) {
+            if ( this.hasCollection(info[0]) ) {
                 return new MongoDBCollectionResource(resourceResolver, path);
             }
             return null;
         }
-        logger.info("Searching {} in {}", info[1], info[0]);
-        if ( this.hasDatabase(info[0]) ) {
-            final DBCollection col = this.context.getDatabase().getCollection(info[0]);
-            if ( col != null ) {
-                final DBObject obj = col.findOne(QueryBuilder.start(PROP_PATH).is(info[1]).get());
-                logger.info("Result={}", obj);
-                if ( obj != null ) {
-                    return new MongoDBResource(resourceResolver,
-                                    path,
-                                    info[0],
-                                    obj,
-                                    this);
-                }
+        logger.debug("Searching {} in {}", info[1], info[0]);
+        final DBCollection col = this.getCollection(info[0]);
+        if ( col != null ) {
+            final DBObject obj = col.findOne(QueryBuilder.start(PROP_PATH).is(info[1]).get());
+            logger.debug("Found {}", obj);
+            if ( obj != null ) {
+                return new MongoDBResource(resourceResolver,
+                                path,
+                                info[0],
+                                obj,
+                                this);
             }
         }
+
         return null;
     }
 
diff --git a/src/main/java/org/apache/sling/mongodb/impl/ReadableValueMap.java b/src/main/java/org/apache/sling/mongodb/impl/ReadableValueMap.java
index 8da52d8..5bc0f15 100644
--- a/src/main/java/org/apache/sling/mongodb/impl/ReadableValueMap.java
+++ b/src/main/java/org/apache/sling/mongodb/impl/ReadableValueMap.java
@@ -20,7 +20,6 @@ import java.lang.reflect.Array;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
@@ -39,16 +38,11 @@ public class ReadableValueMap implements ValueMap {
     }
 
     protected void createValueMap(final DBObject dbObject) {
-        @SuppressWarnings("unchecked")
-        final Map<String, Object> map = new HashMap<String, Object>(dbObject.toMap());
-        final Set<String> names = new HashSet<String>(map.keySet());
-        for(final String name : names) {
-            if ( name.startsWith("__") ) {
-                final Object value = map.remove(name);
-                map.put(name.substring(1), value);
-            } else if ( name.startsWith("_") ) {
-                // remove internal props, like _id, _path
-                map.remove(name);
+        final Map<String, Object> map = new HashMap<String, Object>();
+        for(final Map.Entry<String, Object> entry : map.entrySet()) {
+            final String name = MongoDBResourceProvider.keyToPropName(entry.getKey());
+            if ( name != null ) {
+                map.put(name, entry.getValue());
             }
         }
         this.valueMap = Collections.unmodifiableMap(map);

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

[sling-org-apache-sling-mongodb] 25/36: extensions/mongodb: use released versions for dependencies

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-mongodb.git

commit 313188312198a5030a17306e7e417017baafa10b
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Thu Mar 27 08:39:01 2014 +0000

    extensions/mongodb: use released versions for dependencies
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1582219 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index 4886c18..e769857 100644
--- a/pom.xml
+++ b/pom.xml
@@ -64,7 +64,7 @@
         <dependency>
     	    <groupId>org.apache.sling</groupId>
     	    <artifactId>org.apache.sling.api</artifactId>
-    	    <version>2.6.1-SNAPSHOT</version>
+    	    <version>2.7.0</version>
     	    <scope>provided</scope>
         </dependency>
         <dependency>

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

[sling-org-apache-sling-mongodb] 18/36: Correct reactor pom and update to parent pom 16

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-mongodb.git

commit a117cffdc24e07a9e48ba1cc962d054b42c12589
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Sun May 5 14:38:24 2013 +0000

    Correct reactor pom and update to parent pom 16
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1479333 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index 4497f4c..2ec2748 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
     <parent>
         <groupId>org.apache.sling</groupId>
         <artifactId>sling</artifactId>
-        <version>15</version>
+        <version>16</version>
     </parent>
 
     <groupId>org.apache.sling</groupId>

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

[sling-org-apache-sling-mongodb] 08/36: SLING-2530 : Implement CRUD based on resources

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-mongodb.git

commit ab55fbc419effedcdfbd5353a1f63467bf6e0eb7
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Thu Sep 27 09:05:35 2012 +0000

    SLING-2530 : Implement CRUD based on resources
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1390902 13f79535-47bb-0310-9956-ffa450edef68
---
 src/main/java/org/apache/sling/mongodb/impl/ReadableValueMap.java | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/sling/mongodb/impl/ReadableValueMap.java b/src/main/java/org/apache/sling/mongodb/impl/ReadableValueMap.java
index 5bc0f15..c294d84 100644
--- a/src/main/java/org/apache/sling/mongodb/impl/ReadableValueMap.java
+++ b/src/main/java/org/apache/sling/mongodb/impl/ReadableValueMap.java
@@ -39,10 +39,10 @@ public class ReadableValueMap implements ValueMap {
 
     protected void createValueMap(final DBObject dbObject) {
         final Map<String, Object> map = new HashMap<String, Object>();
-        for(final Map.Entry<String, Object> entry : map.entrySet()) {
-            final String name = MongoDBResourceProvider.keyToPropName(entry.getKey());
+        for(final String key : dbObject.keySet()) {
+            final String name = MongoDBResourceProvider.keyToPropName(key);
             if ( name != null ) {
-                map.put(name, entry.getValue());
+                map.put(key, dbObject.get(name));
             }
         }
         this.valueMap = Collections.unmodifiableMap(map);

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

[sling-org-apache-sling-mongodb] 28/36: SLING-3916 - Add simple query support to the MongoDBResourceProvider

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-mongodb.git

commit 39d6fdb85b0aa4f17facdceaac0c0b4a9dd08e04
Author: Mike Müller <my...@apache.org>
AuthorDate: Tue Sep 9 06:11:23 2014 +0000

    SLING-3916 - Add simple query support to the MongoDBResourceProvider
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1623664 13f79535-47bb-0310-9956-ffa450edef68
---
 .../mongodb/impl/MongoDBResourceProvider.java      | 50 +++++++++++++++++++++-
 .../impl/MongoDBResourceProviderFactory.java       |  4 +-
 2 files changed, 51 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProvider.java b/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProvider.java
index 55fdb5f..4e73d1f 100644
--- a/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProvider.java
+++ b/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProvider.java
@@ -37,10 +37,12 @@ import org.slf4j.LoggerFactory;
 
 import com.mongodb.BasicDBObject;
 import com.mongodb.BasicDBObjectBuilder;
+import com.mongodb.CommandResult;
 import com.mongodb.DBCollection;
 import com.mongodb.DBCursor;
 import com.mongodb.DBObject;
 import com.mongodb.QueryBuilder;
+import com.mongodb.util.JSON;
 
 /**
  * The MongoDB resource provider creates resources based on MongoDB entries.
@@ -435,8 +437,52 @@ public class MongoDBResourceProvider implements ResourceProvider, ModifyingResou
         return PROP_PATH;
     }
 
-    public Iterator<Resource> findResources(ResourceResolver resolver, String query, String language) {
-        return null;
+    public Iterator<Resource> findResources(final ResourceResolver resolver, String query, String language) {
+        if ( !language.equals( "mongodb") || query == null || query.length() == 0 || query.indexOf( ".find(" ) <= 0 )
+        {
+            return null;
+        }
+        Iterator<Resource> returnValue = null;
+        final String collectionName = query.substring( 0, query.indexOf( ".find(" ) );
+        DBCollection col = this.getCollection( collectionName );
+        if ( col != null )
+        {
+            String criteria = query.trim().substring( query.indexOf( ".find(" ) + 6, query.length() - 1 );
+            DBObject dbObject = (DBObject) JSON.parse( criteria );
+            final DBCursor cur = col.find( dbObject );
+            final String rootPath = context.getRootWithSlash();
+            
+            return new Iterator<Resource>() {
+
+                public boolean hasNext() {
+                    return cur.hasNext();
+                }
+
+                public Resource next() {
+                    final DBObject obj = cur.next();
+                    final String objPath = obj.get(getPROP_PATH()).toString();
+                    final int lastSlash = objPath.lastIndexOf('/');
+                    final String name;
+                    if (lastSlash == -1) {
+                        name = objPath;
+                    } else {
+                        name = objPath.substring(lastSlash + 1);
+                    }
+                    return new MongoDBResource(resolver,
+                            rootPath + collectionName + "/" + name,
+                            collectionName,
+                            obj,
+                            MongoDBResourceProvider.this);
+                }
+
+                public void remove() {
+                    throw new UnsupportedOperationException("remove");
+                }
+
+            };
+        }
+        
+        return returnValue;
     }
 
     public Iterator<ValueMap> queryResources(ResourceResolver resolver, String query, String language) {
diff --git a/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProviderFactory.java b/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProviderFactory.java
index 9bcf562..0f0f670 100644
--- a/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProviderFactory.java
+++ b/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProviderFactory.java
@@ -28,6 +28,7 @@ import org.apache.felix.scr.annotations.Reference;
 import org.apache.felix.scr.annotations.Service;
 import org.apache.sling.api.resource.LoginException;
 import org.apache.sling.api.resource.ResourceProvider;
+import org.apache.sling.api.resource.QueriableResourceProvider;
 import org.apache.sling.api.resource.ResourceProviderFactory;
 import org.apache.sling.commons.osgi.PropertiesUtil;
 import org.osgi.service.event.EventAdmin;
@@ -50,7 +51,8 @@ policy=ConfigurationPolicy.REQUIRE,
 metatype=true)
 @Service(value=ResourceProviderFactory.class)
 @Properties({
-    @Property(name=ResourceProvider.ROOTS, value="/mongo")
+    @Property(name=ResourceProvider.ROOTS, value="/mongo"),
+    @Property(name=QueriableResourceProvider.LANGUAGES, value="mongodb")
 })
 public class MongoDBResourceProviderFactory implements ResourceProviderFactory {
 

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

[sling-org-apache-sling-mongodb] 32/36: SLING-5024 add/update readme

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-mongodb.git

commit e7b9ae07ac7a9766f0760fe559e284dcb1b7819e
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Mon Sep 14 21:31:48 2015 +0000

    SLING-5024 add/update readme
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1703067 13f79535-47bb-0310-9956-ffa450edef68
---
 README.txt | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/README.txt b/README.txt
new file mode 100644
index 0000000..2c101be
--- /dev/null
+++ b/README.txt
@@ -0,0 +1,6 @@
+This is a Sling Resource Provider for MongoDB implementation (from 2012)
+
+The Sling provides also a different implementation based on the Generic NoSQL Resource Provider for MongoDB:
+https://svn.apache.org/repos/asf/sling/trunk/contrib/nosql/mongodb-resourceprovider
+
+Please note that both implementations are not interchangeable because they store the data in MongoDB in different formats.

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

[sling-org-apache-sling-mongodb] 04/36: New MongoDB resource provider

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-mongodb.git

commit 0fada4c33c1e1b59c0a481c1974fa3f8084c1f2f
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Wed Aug 1 18:51:27 2012 +0000

    New MongoDB resource provider
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1368192 13f79535-47bb-0310-9956-ffa450edef68
---
 .../java/org/apache/sling/mongodb/impl/MongoDBResourceProvider.java | 3 +++
 src/main/resources/OSGI-INF/metatype/metatype.properties            | 6 +++++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProvider.java b/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProvider.java
index 7ccbaf1..8bea67a 100644
--- a/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProvider.java
+++ b/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProvider.java
@@ -214,6 +214,9 @@ public class MongoDBResourceProvider implements ResourceProvider, ModifyingResou
         return null;
     }
 
+    /**
+     * Inform about changes of a resource.
+     */
     public void changed(final MongoDBResource resource) {
         this.deletedResources.remove(resource.getPath());
         this.changedResources.put(resource.getPath(), resource);
diff --git a/src/main/resources/OSGI-INF/metatype/metatype.properties b/src/main/resources/OSGI-INF/metatype/metatype.properties
index 4d380cc..4771886 100644
--- a/src/main/resources/OSGI-INF/metatype/metatype.properties
+++ b/src/main/resources/OSGI-INF/metatype/metatype.properties
@@ -21,7 +21,7 @@
 #
 # This file contains localization strings for configuration labels and
 # descriptions as used in the metatype.xml descriptor generated by the
-# the SCR plugin
+# the Apache Felix SCR plugin
 
 #
 # Localizations for FsResourceProvider configuration
@@ -32,6 +32,7 @@ factory.description = Configure an instance of the MongoDB \
 provider.roots.name = Provider Root
 provider.roots.description = Location in the virtual resource tree where the \
  resources are mapped in. This property must not be an empty string.
+
 host.name = MongoDB Host
 host.description = The host to connect to.
 
@@ -40,3 +41,6 @@ port.description = The port to connect to.
 
 db.name MongoDB Database
 db.description = The database to use.
+
+filter.collections.name = Filter Collections
+filter.collections.description = These collections are not available as resources.
\ No newline at end of file

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

[sling-org-apache-sling-mongodb] 01/36: New MongoDB resource provider

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-mongodb.git

commit 45b6b2a64ee774e7c8d66eb42d08df58382f6d93
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Wed Aug 1 17:53:47 2012 +0000

    New MongoDB resource provider
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1368139 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml                                            |  90 ++++++
 .../sling/mongodb/impl/ChangeableValueMap.java     |  90 ++++++
 .../mongodb/impl/MongoDBCollectionResource.java    |  90 ++++++
 .../apache/sling/mongodb/impl/MongoDBContext.java  |  93 ++++++
 .../apache/sling/mongodb/impl/MongoDBResource.java | 146 +++++++++
 .../mongodb/impl/MongoDBResourceProvider.java      | 355 +++++++++++++++++++++
 .../impl/MongoDBResourceProviderFactory.java       | 109 +++++++
 .../sling/mongodb/impl/ReadableValueMap.java       | 227 +++++++++++++
 .../OSGI-INF/metatype/metatype.properties          |  42 +++
 9 files changed, 1242 insertions(+)

diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..d43dcc1
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,90 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.sling</groupId>
+        <artifactId>sling</artifactId>
+        <version>13</version>
+    </parent>
+
+    <groupId>org.apache.sling</groupId>
+    <artifactId>org.apache.sling.mongodb</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+    <packaging>bundle</packaging>
+
+    <name>org.apache.sling.mongodb</name>
+    <url>http://maven.apache.org</url>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-scr-plugin</artifactId>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Private-Package>
+                            org.apache.sling.mongodb.impl
+                        </Private-Package>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+    
+    <dependencies>
+        <dependency>
+    	    <groupId>org.apache.sling</groupId>
+    	    <artifactId>org.apache.sling.api</artifactId>
+    	    <version>2.2.5-SNAPSHOT</version>
+    	    <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.commons.osgi</artifactId>
+            <version>2.1.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+        	<groupId>org.mongodb</groupId>
+        	<artifactId>mongo-java-driver</artifactId>
+        	<version>2.8.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+        	<groupId>org.apache.felix</groupId>
+        	<artifactId>org.apache.felix.scr.annotations</artifactId>
+        </dependency>
+        <dependency>
+        	<groupId>org.slf4j</groupId>
+        	<artifactId>slf4j-api</artifactId>
+        </dependency>
+        <dependency>
+        	<groupId>javax.servlet</groupId>
+        	<artifactId>servlet-api</artifactId>
+        </dependency>
+    </dependencies>
+</project>
diff --git a/src/main/java/org/apache/sling/mongodb/impl/ChangeableValueMap.java b/src/main/java/org/apache/sling/mongodb/impl/ChangeableValueMap.java
new file mode 100644
index 0000000..493a737
--- /dev/null
+++ b/src/main/java/org/apache/sling/mongodb/impl/ChangeableValueMap.java
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.mongodb.impl;
+
+import java.util.Map;
+
+import org.apache.sling.api.resource.ModifiableValueMap;
+
+public class ChangeableValueMap
+    extends ReadableValueMap
+    implements ModifiableValueMap {
+
+    private final MongoDBResource resource;
+
+    public ChangeableValueMap(final MongoDBResource resource) {
+        super(resource.getProperties());
+        this.resource = resource;
+    }
+
+    /**
+     * @see java.util.Map#clear()
+     */
+    public void clear() {
+        throw new UnsupportedOperationException("clear");
+    }
+
+    /**
+     * @see java.util.Map#put(java.lang.Object, java.lang.Object)
+     */
+    public Object put(final String name, final Object value) {
+        final Object oldValue = this.valueMap.get(name);
+        final String key;
+        if ( name.startsWith("_") ) {
+            key = "_" + name;
+        } else {
+            key = name;
+        }
+        this.resource.getProperties().put(key, value);
+
+        // update map and resource
+        this.createValueMap(this.resource.getProperties());
+        this.resource.changed();
+
+        return oldValue;
+    }
+
+    /**
+     * @see java.util.Map#putAll(java.util.Map)
+     */
+    public void putAll(final Map<? extends String, ? extends Object> m) {
+        for(final Map.Entry<? extends String, ? extends Object> e : m.entrySet() ) {
+            this.put(e.getKey(), e.getValue());
+        }
+    }
+
+    /**
+     * @see java.util.Map#remove(java.lang.Object)
+     */
+    public Object remove(final Object name) {
+        final Object result = this.valueMap.get(name);
+        if ( result != null ) {
+            final String key;
+            if ( name.toString().startsWith("_") ) {
+                key = "_" + name;
+            } else {
+                key = name.toString();
+            }
+            this.resource.getProperties().removeField(key);
+
+            // update map and resource
+            this.createValueMap(this.resource.getProperties());
+            this.resource.changed();
+        }
+        return result;
+    }
+}
diff --git a/src/main/java/org/apache/sling/mongodb/impl/MongoDBCollectionResource.java b/src/main/java/org/apache/sling/mongodb/impl/MongoDBCollectionResource.java
new file mode 100644
index 0000000..6cccb4a
--- /dev/null
+++ b/src/main/java/org/apache/sling/mongodb/impl/MongoDBCollectionResource.java
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.mongodb.impl;
+
+import java.util.Collections;
+import java.util.Map;
+
+import org.apache.sling.api.resource.AbstractResource;
+import org.apache.sling.api.resource.ResourceMetadata;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.api.wrappers.ValueMapDecorator;
+
+public class MongoDBCollectionResource extends AbstractResource {
+
+    private final String path;
+
+    private final ResourceResolver resourceResolver;
+
+    private final ResourceMetadata metadata = new ResourceMetadata();
+
+    public MongoDBCollectionResource(final ResourceResolver resolver, final String path) {
+        this.resourceResolver = resolver;
+        this.path = path;
+        this.metadata.setResolutionPath(this.path);
+    }
+
+    /**
+     * @see org.apache.sling.api.resource.Resource#getPath()
+     */
+    public String getPath() {
+        return this.path;
+    }
+
+    /**
+     * @see org.apache.sling.api.resource.Resource#getResourceType()
+     */
+    public String getResourceType() {
+        return "mongodb:collection";
+    }
+
+    /**
+     * @see org.apache.sling.api.resource.Resource#getResourceSuperType()
+     */
+    public String getResourceSuperType() {
+        return null;
+    }
+
+    /**
+     * @see org.apache.sling.api.resource.Resource#getResourceMetadata()
+     */
+    public ResourceMetadata getResourceMetadata() {
+        return this.metadata;
+    }
+
+    /**
+     * @see org.apache.sling.api.resource.Resource#getResourceResolver()
+     */
+    public ResourceResolver getResourceResolver() {
+        return this.resourceResolver;
+    }
+
+    /**
+     * @see org.apache.sling.api.adapter.SlingAdaptable#adaptTo(java.lang.Class)
+     */
+    @SuppressWarnings("unchecked")
+    @Override
+    public <AdapterType> AdapterType adaptTo(final Class<AdapterType> type) {
+        if ( type == ValueMap.class ) {
+            return (AdapterType) new ValueMapDecorator(Collections.EMPTY_MAP);
+        } else if ( type == Map.class ) {
+            return (AdapterType) Collections.EMPTY_MAP;
+        }
+        return super.adaptTo(type);
+    }
+}
diff --git a/src/main/java/org/apache/sling/mongodb/impl/MongoDBContext.java b/src/main/java/org/apache/sling/mongodb/impl/MongoDBContext.java
new file mode 100644
index 0000000..c801e8b
--- /dev/null
+++ b/src/main/java/org/apache/sling/mongodb/impl/MongoDBContext.java
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.mongodb.impl;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import com.mongodb.DB;
+
+public class MongoDBContext {
+
+    /** The roots. */
+    private final String[] roots;
+
+    /** The roots ended by a slash. */
+    private final String[] rootsWithSlash;
+
+    /** Don't show these collections. */
+    private final Set<String> filterCollectionNames = new HashSet<String>();
+
+    /** The database to be used. */
+    private final DB database;
+
+    public MongoDBContext(final DB database,
+                    final String[] configuredRoots,
+                    final String[] configuredFilterCollectionNames) {
+        this.database = database;
+        if ( configuredRoots != null ) {
+            final List<String> rootsList = new ArrayList<String>();
+            final List<String> rootsWithSlashList = new ArrayList<String>();
+            for(final String r : configuredRoots) {
+                if ( r != null ) {
+                    final String value = r.trim();
+                    if ( value.length() > 0 ) {
+                        if ( value.endsWith("/") ) {
+                            rootsWithSlashList.add(value);
+                            rootsList.add(value.substring(0, value.length() - 1));
+                        } else {
+                            rootsWithSlashList.add(value + "/");
+                            rootsList.add(value);
+                        }
+                    }
+                }
+            }
+            this.roots = rootsList.toArray(new String[rootsList.size()]);
+            this.rootsWithSlash = rootsWithSlashList.toArray(new String[rootsWithSlashList.size()]);
+        } else {
+            this.roots = new String[0];
+            this.rootsWithSlash = new String[0];
+        }
+        if ( configuredFilterCollectionNames != null ) {
+            for(final String name : configuredFilterCollectionNames) {
+                this.filterCollectionNames.add(name);
+            }
+        }
+    }
+
+    public String[] getRoots() {
+        return roots;
+    }
+
+    public String[] getRootsWithSlash() {
+        return this.rootsWithSlash;
+    }
+
+    public boolean isFilterCollectionName(final String name) {
+        return this.filterCollectionNames.contains(name);
+    }
+
+    public Set<String> getFilterCollectionNames() {
+        return this.filterCollectionNames;
+    }
+
+    public DB getDatabase() {
+        return this.database;
+    }
+}
diff --git a/src/main/java/org/apache/sling/mongodb/impl/MongoDBResource.java b/src/main/java/org/apache/sling/mongodb/impl/MongoDBResource.java
new file mode 100644
index 0000000..6ad685c
--- /dev/null
+++ b/src/main/java/org/apache/sling/mongodb/impl/MongoDBResource.java
@@ -0,0 +1,146 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.mongodb.impl;
+
+import java.util.Map;
+
+import org.apache.sling.api.resource.AbstractResource;
+import org.apache.sling.api.resource.ModifiableValueMap;
+import org.apache.sling.api.resource.ResourceMetadata;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.resource.ValueMap;
+
+import com.mongodb.DBObject;
+
+public class MongoDBResource extends AbstractResource {
+
+    /** The complete resource path. */
+    private final String resourcePath;
+
+    /** The collection */
+    private final String collection;
+
+    /** The resource resolver. */
+    private final ResourceResolver resourceResolver;
+
+    /** Metadata. */
+    private final ResourceMetadata metadata = new ResourceMetadata();
+
+    /** The db object. */
+    private DBObject dbObject;
+
+    /** The MongoDB resource provider. */
+    private final MongoDBResourceProvider provider;
+
+    public MongoDBResource(final ResourceResolver resolver,
+                    final String resourcePath,
+                    final String collection,
+                    final DBObject dbObject,
+                    final MongoDBResourceProvider provider) {
+        this.resourceResolver = resolver;
+        this.resourcePath = resourcePath;
+        this.collection = collection;
+        this.dbObject = dbObject;
+        this.provider = provider;
+    }
+
+    /**
+     * @see org.apache.sling.api.resource.Resource#getPath()
+     */
+    public String getPath() {
+        return this.resourcePath;
+    }
+
+    /**
+     * @see org.apache.sling.api.resource.Resource#getResourceType()
+     */
+    public String getResourceType() {
+        // get resource type from data
+        final Object rt = this.dbObject.get("sling:resourceType");
+        if ( rt != null ) {
+            return rt.toString();
+        }
+        return "nt:unstructured";
+    }
+
+    /**
+     * @see org.apache.sling.api.resource.Resource#getResourceSuperType()
+     */
+    public String getResourceSuperType() {
+        // get resource type from data
+        final Object rt = this.dbObject.get("sling:resourceSuperType");
+        if ( rt != null ) {
+            return rt.toString();
+        }
+        return null;
+    }
+
+    /**
+     * @see org.apache.sling.api.resource.Resource#getResourceMetadata()
+     */
+    public ResourceMetadata getResourceMetadata() {
+        return this.metadata;
+    }
+
+    /**
+     * @see org.apache.sling.api.resource.Resource#getResourceResolver()
+     */
+    public ResourceResolver getResourceResolver() {
+        return this.resourceResolver;
+    }
+
+    /**
+     * @see org.apache.sling.api.adapter.SlingAdaptable#adaptTo(java.lang.Class)
+     */
+    @SuppressWarnings("unchecked")
+    @Override
+    public <AdapterType> AdapterType adaptTo(final Class<AdapterType> type) {
+        if ( type == ValueMap.class || type == Map.class ) {
+            this.dbObject = this.provider.getUpdatedDBObject(this.resourcePath, this.dbObject);
+            return (AdapterType) new ReadableValueMap(this.dbObject);
+        } else if ( type == ModifiableValueMap.class ) {
+            this.dbObject = this.provider.getUpdatedDBObject(this.resourcePath, this.dbObject);
+            return (AdapterType) new ChangeableValueMap(this);
+        }
+
+        return super.adaptTo(type);
+    }
+
+    /**
+     * Return the collection.
+     */
+    public String getCollection() {
+        return this.collection;
+    }
+
+    /**
+     * Get the current properties.
+     */
+    public DBObject getProperties() {
+        return this.dbObject;
+    }
+
+    @Override
+    public String toString() {
+        return "MongoDBResource [resourcePath=" + resourcePath + ", dbPath=" + this.dbObject.get(MongoDBResourceProvider.PROP_PATH) + ", collection=" + collection
+                        + ", resourceResolver=" + resourceResolver + "]";
+    }
+
+    public void changed() {
+        this.provider.changed(this);
+    }
+}
diff --git a/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProvider.java b/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProvider.java
new file mode 100644
index 0000000..86a31c5
--- /dev/null
+++ b/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProvider.java
@@ -0,0 +1,355 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.mongodb.impl;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Pattern;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.sling.api.resource.ModifyingResourceProvider;
+import org.apache.sling.api.resource.PersistenceException;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceProvider;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.mongodb.BasicDBObject;
+import com.mongodb.BasicDBObjectBuilder;
+import com.mongodb.DBCollection;
+import com.mongodb.DBCursor;
+import com.mongodb.DBObject;
+import com.mongodb.QueryBuilder;
+
+/**
+ * The MongoDB resource provider creates resources based on MongoDB entries.
+ * The resources contain all properties stored in the MongoDB except those starting with a "_".
+ */
+public class MongoDBResourceProvider implements ResourceProvider, ModifyingResourceProvider {
+
+    /** The special path property containing the (relative) path of the resource in the tree. */
+    public static final String PROP_PATH = "_path";
+
+    /** The id property. */
+    public static final String PROP_ID = "_id";
+
+    /** Logger. */
+    private final Logger logger = LoggerFactory.getLogger(this.getClass());
+
+    /** The global context .*/
+    private final MongoDBContext context;
+
+    private final Map<String, MongoDBResource> changedResources = new HashMap<String, MongoDBResource>();
+
+    private final Set<String> deletedResources = new HashSet<String>();
+
+    public MongoDBResourceProvider(final MongoDBContext context) {
+        this.context = context;
+    }
+
+    /**
+     * @see org.apache.sling.api.resource.ModifyingResourceProvider#create(org.apache.sling.api.resource.ResourceResolver, java.lang.String, java.util.Map)
+     */
+    public Resource create(final ResourceResolver resolver, final String path, final Map<String, Object> properties)
+    throws PersistenceException {
+        final String[] info = this.extractResourceInfo(path);
+        if ( info != null && info.length == 2) {
+            final boolean deleted = this.deletedResources.remove(path);
+            final MongoDBResource oldResource = (MongoDBResource)this.getResource(resolver, path, info);
+            if ( !deleted && oldResource != null ) {
+                throw new PersistenceException("Resource already exists at " + path, null, path, null);
+            }
+            final DBObject dbObj = new BasicDBObject();
+            dbObj.put(PROP_PATH, info[1]);
+            if ( properties != null ) {
+                for(Map.Entry<String, Object> entry : properties.entrySet()) {
+                    final String key;
+                    if ( entry.getKey().startsWith("_") ) {
+                        key = "_" + entry.getKey();
+                    } else {
+                        key = entry.getKey();
+                    }
+                    dbObj.put(key, entry.getValue());
+                }
+            }
+            if ( deleted && oldResource != null ) {
+                dbObj.put(PROP_ID, oldResource.getProperties().get(PROP_ID));
+            }
+            final MongoDBResource rsrc = new MongoDBResource(resolver, path, info[0], dbObj, this);
+            this.changedResources.put(path, rsrc);
+
+            return rsrc;
+        }
+        throw new PersistenceException("Illegal path - unable to create resource at " + path, null, path, null);
+    }
+
+    /**
+     * @see org.apache.sling.api.resource.ModifyingResourceProvider#delete(org.apache.sling.api.resource.ResourceResolver, java.lang.String)
+     */
+    public void delete(final ResourceResolver resolver, final String path)
+    throws PersistenceException {
+        final Resource rsrc = this.getResource(resolver, path);
+        if ( rsrc != null ) {
+            // TODO - delete all child resources!
+            this.deletedResources.add(path);
+            this.changedResources.remove(path);
+        }
+    }
+
+    /**
+     * @see org.apache.sling.api.resource.ModifyingResourceProvider#revert()
+     */
+    public void revert() {
+        this.changedResources.clear();
+        this.deletedResources.clear();
+    }
+
+    /**
+     * @see org.apache.sling.api.resource.ModifyingResourceProvider#commit()
+     */
+    public void commit() throws PersistenceException {
+        try {
+            for(final String deleted : this.deletedResources) {
+                final String[] info = this.extractResourceInfo(deleted);
+
+                // check if the database still exists
+                if ( this.hasDatabase(info[0]) ) {
+                    final DBCollection col = this.context.getDatabase().getCollection(info[0]);
+                    if ( col != null ) {
+                        col.findAndRemove(QueryBuilder.start(PROP_PATH).is(info[1]).get());
+                    }
+                }
+            }
+            for(final MongoDBResource changed : this.changedResources.values()) {
+
+                final DBCollection col = this.context.getDatabase().getCollection(changed.getCollection());
+                if ( col != null ) {
+                    // create or update?
+                    if ( changed.getProperties().get(PROP_ID) != null ) {
+                        col.update(QueryBuilder.start(PROP_PATH).is(changed.getProperties().get(PROP_PATH)).get(),
+                                        changed.getProperties());
+                    } else {
+                        // create
+                        col.save(changed.getProperties());
+                    }
+                } else {
+                    throw new PersistenceException("Unable to create collection " + changed.getCollection(), null, changed.getPath(), null);
+                }
+            }
+        } finally {
+            this.revert();
+        }
+    }
+
+    /**
+     * @see org.apache.sling.api.resource.ModifyingResourceProvider#hasChanges()
+     */
+    public boolean hasChanges() {
+        return this.changedResources.size() > 0 || this.deletedResources.size() > 0;
+    }
+
+    /**
+     * @see org.apache.sling.api.resource.ResourceProvider#getResource(org.apache.sling.api.resource.ResourceResolver, java.lang.String)
+     */
+    public Resource getResource(final ResourceResolver resourceResolver, final String path) {
+        if ( this.deletedResources.contains(path) ) {
+            return null;
+        }
+        if ( this.changedResources.containsKey(path) ) {
+            return this.changedResources.get(path);
+        }
+        final String[] info = this.extractResourceInfo(path);
+        if ( info != null ) {
+            return this.getResource(resourceResolver, path, info);
+        }
+        return null;
+    }
+
+    public void changed(final MongoDBResource resource) {
+        this.deletedResources.remove(resource.getPath());
+        this.changedResources.put(resource.getPath(), resource);
+    }
+
+    /**
+     * @see org.apache.sling.api.resource.ResourceProvider#listChildren(org.apache.sling.api.resource.Resource)
+     */
+    public Iterator<Resource> listChildren(final Resource parent) {
+        final String[] info = this.extractResourceInfo(parent.getPath());
+        if ( info != null ) {
+            if ( info.length == 0 ) {
+                // all collections
+                final Set<String> names = new HashSet<String>(context.getDatabase().getCollectionNames());
+                names.removeAll(this.context.getFilterCollectionNames());
+                final Iterator<String> i = names.iterator();
+                return new Iterator<Resource>() {
+
+                    public boolean hasNext() {
+                        return i.hasNext();
+                    }
+
+                    public Resource next() {
+                        final String name = i.next();
+                        return new MongoDBCollectionResource(parent.getResourceResolver(), parent.getPath() + '/' + name);
+                    }
+
+                    public void remove() {
+                        throw new UnsupportedOperationException("remove");
+                    }
+
+                };
+            }
+            if ( this.hasDatabase(info[0]) ) {
+                final DBCollection col = this.context.getDatabase().getCollection(info[0]);
+                if ( col != null ) {
+                    final String pattern;
+                    if ( info.length == 1 ) {
+                        pattern = "^([^/])*$";
+                    } else {
+                        pattern = "^" + Pattern.quote(info[1]) + "/([^/])*$";
+                    }
+
+                    final DBObject query = QueryBuilder.start(PROP_PATH).regex(Pattern.compile(pattern)).get();
+                    final DBCursor cur = col.find(query).
+                                    sort(BasicDBObjectBuilder.start(PROP_PATH, 1).get());
+                    return new Iterator<Resource>() {
+
+                        public boolean hasNext() {
+                            return cur.hasNext();
+                        }
+
+                        public Resource next() {
+                            final DBObject obj = cur.next();
+                            final String objPath = obj.get(PROP_PATH).toString();
+                            final int lastSlash = objPath.lastIndexOf('/');
+                            final String name;
+                            if (lastSlash == -1) {
+                                name = objPath;
+                            } else {
+                                name = objPath.substring(lastSlash + 1);
+                            }
+                            return new MongoDBResource(parent.getResourceResolver(),
+                                            parent.getPath() + '/' + name,
+                                            info[0],
+                                            obj,
+                                            MongoDBResourceProvider.this);
+                        }
+
+                        public void remove() {
+                            throw new UnsupportedOperationException("remove");
+                        }
+
+                    };
+                }
+            }
+        }
+        return null;
+    }
+
+    /**
+     * @see org.apache.sling.api.resource.ResourceProvider#getResource(org.apache.sling.api.resource.ResourceResolver, javax.servlet.http.HttpServletRequest, java.lang.String)
+     */
+    @SuppressWarnings("javadoc")
+    public Resource getResource(final ResourceResolver resourceResolver,
+                    final HttpServletRequest request,
+                    final String path) {
+        return this.getResource(resourceResolver, path);
+    }
+
+    /**
+     * Extract info about collection and path
+     */
+    private String[] extractResourceInfo(final String path) {
+        for(final String root : this.context.getRootsWithSlash()) {
+            if ( path.startsWith(root) ) {
+                if ( path.length() == root.length() ) {
+                    // special resource - show all collections
+                    return new String[0];
+                }
+                final String info = path.substring(root.length());
+                final int slashPos = info.indexOf('/');
+                if ( slashPos != -1 ) {
+                    return new String[] {info.substring(0, slashPos), info.substring(slashPos + 1)};
+                }
+                // special resource - collection
+                return new String[] {info};
+            }
+        }
+        for(final String root : this.context.getRoots()) {
+            if ( path.equals(root) ) {
+                // special resource - show all collections
+                return new String[0];
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Check if a database with a given name exists
+     */
+    private boolean hasDatabase(final String name) {
+        final Set<String> names = this.context.getDatabase().getCollectionNames();
+        return names.contains(name) && !this.context.isFilterCollectionName(name);
+    }
+
+    /**
+     * Create a resource
+     */
+    private Resource getResource(final ResourceResolver resourceResolver, final String path, final String[] info) {
+        if ( info.length == 0 ) {
+            // special resource : all collections
+            return new MongoDBCollectionResource(resourceResolver, path);
+        } else if ( info.length == 1 ) {
+            // special resource : collection
+            if ( this.hasDatabase(info[0]) ) {
+                return new MongoDBCollectionResource(resourceResolver, path);
+            }
+            return null;
+        }
+        logger.info("Searching {} in {}", info[1], info[0]);
+        if ( this.hasDatabase(info[0]) ) {
+            final DBCollection col = this.context.getDatabase().getCollection(info[0]);
+            if ( col != null ) {
+                final DBObject obj = col.findOne(QueryBuilder.start(PROP_PATH).is(info[1]).get());
+                logger.info("Result={}", obj);
+                if ( obj != null ) {
+                    return new MongoDBResource(resourceResolver,
+                                    path,
+                                    info[0],
+                                    obj,
+                                    this);
+                }
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Check if there is a newer db object for that path.
+     */
+    public DBObject getUpdatedDBObject(final String path, final DBObject dbObj) {
+        final MongoDBResource stored = this.changedResources.get(path);
+        if ( stored != null ) {
+            return stored.getProperties();
+        }
+        return dbObj;
+    }
+}
diff --git a/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProviderFactory.java b/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProviderFactory.java
new file mode 100644
index 0000000..a632215
--- /dev/null
+++ b/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProviderFactory.java
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.mongodb.impl;
+
+import java.util.Map;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.ConfigurationPolicy;
+import org.apache.felix.scr.annotations.Properties;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.PropertyUnbounded;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.api.resource.LoginException;
+import org.apache.sling.api.resource.ResourceProvider;
+import org.apache.sling.api.resource.ResourceProviderFactory;
+import org.apache.sling.commons.osgi.PropertiesUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.mongodb.DB;
+import com.mongodb.Mongo;
+
+/**
+ * The MongoDB resource provider factory allows to provided resources stored
+ * in MongoDB.
+ */
+@Component(label="%factory.name",
+           description="%factory.description",
+           configurationFactory=true,
+           policy=ConfigurationPolicy.REQUIRE,
+           metatype=true)
+@Service(value=ResourceProviderFactory.class)
+@Properties({
+    @Property(name=ResourceProvider.ROOTS, value="/mongo")
+})
+public class MongoDBResourceProviderFactory implements ResourceProviderFactory {
+
+    private static final String DEFAULT_HOST = "localhost";
+
+    private static final int DEFAULT_PORT = 27017;
+
+    private static final String DEFAULT_DB = "sling";
+
+    @Property(value=DEFAULT_HOST)
+    private static final String PROP_HOST = "host";
+
+    @Property(intValue=DEFAULT_PORT)
+    private static final String PROP_PORT = "port";
+
+    @Property(value=DEFAULT_DB)
+    private static final String PROP_DB = "db";
+
+    @Property(unbounded=PropertyUnbounded.ARRAY, value="system.indexes")
+    private static final String PROP_FILTER_COLLECTIONS = "filter.collections";
+
+    /** Logger. */
+    private final Logger logger = LoggerFactory.getLogger(this.getClass());
+
+    /** The global context passed to each resource provider. */
+    private MongoDBContext context;
+
+    @Activate
+    protected void activate(final Map<String, Object> props) throws Exception {
+        final String host = PropertiesUtil.toString(props.get(PROP_HOST), DEFAULT_HOST);
+        final int port = PropertiesUtil.toInteger(props.get(PROP_PORT), DEFAULT_PORT);
+        final String db = PropertiesUtil.toString(props.get(PROP_DB), DEFAULT_DB);
+        logger.info("Starting MongoDB resource provider with host={}, port={}, db={}",
+                        new Object[] {host, port, db});
+
+        final Mongo m = new Mongo( host , port );
+        final DB database = m.getDB( db );
+        logger.info("Connected to database {}", database);
+
+        this.context = new MongoDBContext(database,
+                        PropertiesUtil.toStringArray(props.get(ResourceProvider.ROOTS)),
+                        PropertiesUtil.toStringArray(props.get(PROP_FILTER_COLLECTIONS)));
+    }
+
+    /**
+     * @see org.apache.sling.api.resource.ResourceProviderFactory#getResourceProvider(java.util.Map)
+     */
+    public ResourceProvider getResourceProvider(final Map<String, Object> authenticationInfo) throws LoginException {
+        // for now we allow anonymous access
+        return new MongoDBResourceProvider(this.context);
+    }
+
+    /**
+     * @see org.apache.sling.api.resource.ResourceProviderFactory#getAdministrativeResourceProvider(java.util.Map)
+     */
+    public ResourceProvider getAdministrativeResourceProvider(final Map<String, Object> authenticationInfo) throws LoginException {
+        // for now we allow anonymous access
+        return new MongoDBResourceProvider(this.context);
+    }
+}
diff --git a/src/main/java/org/apache/sling/mongodb/impl/ReadableValueMap.java b/src/main/java/org/apache/sling/mongodb/impl/ReadableValueMap.java
new file mode 100644
index 0000000..8da52d8
--- /dev/null
+++ b/src/main/java/org/apache/sling/mongodb/impl/ReadableValueMap.java
@@ -0,0 +1,227 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.mongodb.impl;
+
+import java.lang.reflect.Array;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.sling.api.resource.ValueMap;
+
+import com.mongodb.DBObject;
+
+public class ReadableValueMap implements ValueMap {
+
+    protected Map<String, Object> valueMap;
+
+    public ReadableValueMap(final DBObject dbObject) {
+        this.createValueMap(dbObject);
+    }
+
+    protected void createValueMap(final DBObject dbObject) {
+        @SuppressWarnings("unchecked")
+        final Map<String, Object> map = new HashMap<String, Object>(dbObject.toMap());
+        final Set<String> names = new HashSet<String>(map.keySet());
+        for(final String name : names) {
+            if ( name.startsWith("__") ) {
+                final Object value = map.remove(name);
+                map.put(name.substring(1), value);
+            } else if ( name.startsWith("_") ) {
+                // remove internal props, like _id, _path
+                map.remove(name);
+            }
+        }
+        this.valueMap = Collections.unmodifiableMap(map);
+    }
+
+    /**
+     * @see java.util.Map#containsKey(java.lang.Object)
+     */
+    public boolean containsKey(final Object key) {
+        return this.valueMap.containsKey(key);
+    }
+
+    /**
+     * @see java.util.Map#containsValue(java.lang.Object)
+     */
+    public boolean containsValue(final Object value) {
+        return this.valueMap.containsValue(value);
+    }
+
+    /**
+     * @see java.util.Map#entrySet()
+     */
+    public Set<java.util.Map.Entry<String, Object>> entrySet() {
+        return this.valueMap.entrySet();
+    }
+
+    /**
+     * @see java.util.Map#get(java.lang.Object)
+     */
+    public Object get(final Object key) {
+        return this.valueMap.get(key);
+    }
+
+    /**
+     * @see java.util.Map#isEmpty()
+     */
+    public boolean isEmpty() {
+        return this.valueMap.isEmpty();
+    }
+
+    /**
+     * @see java.util.Map#keySet()
+     */
+    public Set<String> keySet() {
+        return this.valueMap.keySet();
+    }
+
+    /**
+     * @see java.util.Map#size()
+     */
+    public int size() {
+        return this.valueMap.size();
+    }
+
+    /**
+     * @see java.util.Map#values()
+     */
+    public Collection<Object> values() {
+        return this.valueMap.values();
+    }
+
+    /**
+     * @see org.apache.sling.api.resource.ValueMap#get(java.lang.String, java.lang.Class)
+     */
+    @SuppressWarnings("unchecked")
+    public <T> T get(final String key, final Class<T> type) {
+        if (type == null) {
+            return (T) get(key);
+        }
+
+        final Object val = this.get(key);
+        if ( val == null ) {
+            return null;
+        }
+        return convertToType(val, type);
+    }
+
+    /**
+     * @see org.apache.sling.api.resource.ValueMap#get(java.lang.String, java.lang.Object)
+     */
+    @SuppressWarnings("unchecked")
+    public <T> T get(final String key,final T defaultValue) {
+        if (defaultValue == null) {
+            return (T) get(key);
+        }
+
+        T value = get(key, (Class<T>) defaultValue.getClass());
+        if (value == null) {
+            value = defaultValue;
+        }
+
+        return value;
+    }
+
+    /**
+     * @see java.util.Map#clear()
+     */
+    public void clear() {
+        throw new UnsupportedOperationException("clear");
+    }
+
+    /**
+     * @see java.util.Map#put(java.lang.Object, java.lang.Object)
+     */
+    public Object put(String key, Object value) {
+        throw new UnsupportedOperationException("put");
+    }
+
+    /**
+     * @see java.util.Map#putAll(java.util.Map)
+     */
+    public void putAll(Map<? extends String, ? extends Object> m) {
+        throw new UnsupportedOperationException("putAll");
+    }
+
+    /**
+     * @see java.util.Map#remove(java.lang.Object)
+     */
+    public Object remove(Object key) {
+        throw new UnsupportedOperationException("remove");
+    }
+
+    /**
+     * Converts the object to the given type.
+     * @param obj object
+     * @param type type
+     * @return the converted object
+     */
+    @SuppressWarnings("unchecked")
+    private <T> T convertToType(final Object obj, final Class<T> type) {
+        // todo: do smarter checks
+        try {
+            if (obj == null) {
+                return null;
+            } else if (type.isAssignableFrom(obj.getClass())) {
+                return (T) obj;
+            } else if (type.isArray()) {
+                return (T) convertToArray(obj, type.getComponentType());
+            } else if (type == String.class) {
+                return (T) String.valueOf(obj);
+            } else if (type == Integer.class) {
+                return (T) (Integer) Integer.parseInt(obj.toString());
+            } else if (type == Long.class) {
+                return (T) (Long) Long.parseLong(obj.toString());
+            } else if (type == Double.class) {
+                return (T) (Double) Double.parseDouble(obj.toString());
+            } else if (type == Boolean.class) {
+                return (T) (Boolean) Boolean.parseBoolean(obj.toString());
+            } else {
+                return null;
+            }
+        } catch (final NumberFormatException e) {
+            return null;
+        }
+    }
+
+    /**
+     * Converts the object to an array of the given type
+     * @param obj tje object or object array
+     * @param type the component type of the array
+     * @return and array of type T
+     */
+    private <T> T[] convertToArray(Object obj, Class<T> type) {
+        List<T> values = new LinkedList<T>();
+        if (obj.getClass().isArray()) {
+            for (Object o: (Object[]) obj) {
+                values.add(convertToType(o, type));
+            }
+        } else {
+            values.add(convertToType(obj, type));
+        }
+        @SuppressWarnings("unchecked")
+        T[] result = (T[]) Array.newInstance(type, values.size());
+        return values.toArray(result);
+    }
+}
diff --git a/src/main/resources/OSGI-INF/metatype/metatype.properties b/src/main/resources/OSGI-INF/metatype/metatype.properties
new file mode 100644
index 0000000..4d380cc
--- /dev/null
+++ b/src/main/resources/OSGI-INF/metatype/metatype.properties
@@ -0,0 +1,42 @@
+#
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing,
+#  software distributed under the License is distributed on an
+#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#  KIND, either express or implied.  See the License for the
+#  specific language governing permissions and limitations
+#  under the License.
+#
+
+
+#
+# This file contains localization strings for configuration labels and
+# descriptions as used in the metatype.xml descriptor generated by the
+# the SCR plugin
+
+#
+# Localizations for FsResourceProvider configuration
+factory.name = Apache Sling MongoDB Resource Provider
+factory.description = Configure an instance of the MongoDB \
+ resource provider in terms of provider root and connection
+
+provider.roots.name = Provider Root
+provider.roots.description = Location in the virtual resource tree where the \
+ resources are mapped in. This property must not be an empty string.
+host.name = MongoDB Host
+host.description = The host to connect to.
+
+port.name = MongoDB Port
+port.description = The port to connect to.
+
+db.name MongoDB Database
+db.description = The database to use.

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

[sling-org-apache-sling-mongodb] 15/36: Use latest snapshot

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-mongodb.git

commit a7876d6346e6ea4854df92ad7086ef65974df881
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Mon Apr 15 13:04:17 2013 +0000

    Use latest snapshot
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1468018 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index e2b2d90..bdd1052 100644
--- a/pom.xml
+++ b/pom.xml
@@ -64,7 +64,7 @@
         <dependency>
     	    <groupId>org.apache.sling</groupId>
     	    <artifactId>org.apache.sling.api</artifactId>
-    	    <version>2.3.1-SNAPSHOT</version>
+    	    <version>2.4.1-SNAPSHOT</version>
     	    <scope>provided</scope>
         </dependency>
         <dependency>

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

[sling-org-apache-sling-mongodb] 17/36: Use released versions after release.

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-mongodb.git

commit 0d6b213035455acf8ce17dc12c10812c5dc0ec87
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Mon Apr 22 08:40:51 2013 +0000

    Use released versions after release.
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1470410 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index bdd1052..4497f4c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -64,7 +64,7 @@
         <dependency>
     	    <groupId>org.apache.sling</groupId>
     	    <artifactId>org.apache.sling.api</artifactId>
-    	    <version>2.4.1-SNAPSHOT</version>
+    	    <version>2.4.0</version>
     	    <scope>provided</scope>
         </dependency>
         <dependency>

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

[sling-org-apache-sling-mongodb] 12/36: Use latest releases and update to new parent pom

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-mongodb.git

commit 9f1884c8a692560d896d24a56f66bc6478886810
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Sun Dec 23 06:53:35 2012 +0000

    Use latest releases and update to new parent pom
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1425425 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index 985a866..accacb2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
     <parent>
         <groupId>org.apache.sling</groupId>
         <artifactId>sling</artifactId>
-        <version>13</version>
+        <version>14</version>
     </parent>
 
     <groupId>org.apache.sling</groupId>

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

[sling-org-apache-sling-mongodb] 02/36: New MongoDB resource provider

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-mongodb.git

commit 4bb7170e9e1161d131410f220cd17ff00c75218a
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Wed Aug 1 18:00:32 2012 +0000

    New MongoDB resource provider
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1368142 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/pom.xml b/pom.xml
index d43dcc1..f73379a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,8 +31,13 @@
     <version>0.0.1-SNAPSHOT</version>
     <packaging>bundle</packaging>
 
-    <name>org.apache.sling.mongodb</name>
-    <url>http://maven.apache.org</url>
+    <name>Apache Sling MongoDB Resource Provider</name>
+
+    <scm>
+        <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/mongodb</connection>
+        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/mongodb</developerConnection>
+        <url>http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/mongodb</url>
+    </scm>
 
     <build>
         <plugins>

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

[sling-org-apache-sling-mongodb] 27/36: Update to latest parent pom 20

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-mongodb.git

commit b958be8741a9ad8b0c8b7b10eb454e3f1274b76b
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Tue Sep 2 14:49:28 2014 +0000

    Update to latest parent pom 20
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1622027 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index a7cd22e..2d3d0ae 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
     <parent>
         <groupId>org.apache.sling</groupId>
         <artifactId>sling</artifactId>
-        <version>19</version>
+        <version>20</version>
     </parent>
 
     <groupId>org.apache.sling</groupId>

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

[sling-org-apache-sling-mongodb] 10/36: Set dependencies to latest snapshots after release

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-mongodb.git

commit b2fc1f04c8e7274d76ab9917b16263b21ed9fe8d
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Mon Nov 12 10:18:08 2012 +0000

    Set dependencies to latest snapshots after release
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1408241 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index b491fbb..2c5e8f9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -64,7 +64,7 @@
         <dependency>
     	    <groupId>org.apache.sling</groupId>
     	    <artifactId>org.apache.sling.api</artifactId>
-    	    <version>2.2.5-SNAPSHOT</version>
+    	    <version>2.3.1-SNAPSHOT</version>
     	    <scope>provided</scope>
         </dependency>
         <dependency>

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

[sling-org-apache-sling-mongodb] 11/36: Update to released bundles

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-mongodb.git

commit 8b47558550f9434a158a612228587a2e3db71ffb
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Fri Nov 16 07:08:53 2012 +0000

    Update to released bundles
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1410214 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index 2c5e8f9..985a866 100644
--- a/pom.xml
+++ b/pom.xml
@@ -64,7 +64,7 @@
         <dependency>
     	    <groupId>org.apache.sling</groupId>
     	    <artifactId>org.apache.sling.api</artifactId>
-    	    <version>2.3.1-SNAPSHOT</version>
+    	    <version>2.3.0</version>
     	    <scope>provided</scope>
         </dependency>
         <dependency>

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

[sling-org-apache-sling-mongodb] 21/36: Update to parent pom 18

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-mongodb.git

commit c1260b03c98eae19fc07d160d8c529b11c7533c1
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Fri Sep 6 12:15:57 2013 +0000

    Update to parent pom 18
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1520554 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index 7967332..5a5e1a9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
     <parent>
         <groupId>org.apache.sling</groupId>
         <artifactId>sling</artifactId>
-        <version>17</version>
+        <version>18</version>
     </parent>
 
     <groupId>org.apache.sling</groupId>

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

[sling-org-apache-sling-mongodb] 16/36: Distribute events in a cluster

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-mongodb.git

commit 98644a07af7b469b6a83fa1e5357fece0541b2e0
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Fri Apr 19 11:41:43 2013 +0000

    Distribute events in a cluster
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1469789 13f79535-47bb-0310-9956-ffa450edef68
---
 src/main/java/org/apache/sling/mongodb/impl/MongoDBContext.java | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/main/java/org/apache/sling/mongodb/impl/MongoDBContext.java b/src/main/java/org/apache/sling/mongodb/impl/MongoDBContext.java
index b1dc3fa..cd8ccc1 100644
--- a/src/main/java/org/apache/sling/mongodb/impl/MongoDBContext.java
+++ b/src/main/java/org/apache/sling/mongodb/impl/MongoDBContext.java
@@ -97,6 +97,7 @@ public class MongoDBContext {
     public void notifyRemoved(final String[] info) {
         final Dictionary<String, Object> props = new Hashtable<String, Object>();
         props.put(SlingConstants.PROPERTY_PATH, this.rootWithSlash + info[0] + '/' + info[1]);
+        props.put("event.distribute", "");
         final Event event = new Event(SlingConstants.TOPIC_RESOURCE_REMOVED, props);
         this.eventAdmin.postEvent(event);
     }
@@ -104,6 +105,7 @@ public class MongoDBContext {
     public void notifyAddeed(final String[] info) {
         final Dictionary<String, Object> props = new Hashtable<String, Object>();
         props.put(SlingConstants.PROPERTY_PATH, this.rootWithSlash + info[0] + '/' + info[1]);
+        props.put("event.distribute", "");
         final Event event = new Event(SlingConstants.TOPIC_RESOURCE_ADDED, props);
         this.eventAdmin.postEvent(event);
     }
@@ -111,6 +113,7 @@ public class MongoDBContext {
     public void notifyUpdated(final String[] info) {
         final Dictionary<String, Object> props = new Hashtable<String, Object>();
         props.put(SlingConstants.PROPERTY_PATH, this.rootWithSlash + info[0] + '/' + info[1]);
+        props.put("event.distribute", "");
         final Event event = new Event(SlingConstants.TOPIC_RESOURCE_CHANGED, props);
         this.eventAdmin.postEvent(event);
     }

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

[sling-org-apache-sling-mongodb] 06/36: New MongoDB resource provider

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-mongodb.git

commit db60601327566ec0a98fe205d9373d97db9401c9
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Thu Aug 2 06:21:32 2012 +0000

    New MongoDB resource provider
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1368357 13f79535-47bb-0310-9956-ffa450edef68
---
 .../java/org/apache/sling/mongodb/impl/MongoDBResourceProvider.java | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProvider.java b/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProvider.java
index c35a8f1..eafb2b9 100644
--- a/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProvider.java
+++ b/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProvider.java
@@ -114,6 +114,11 @@ public class MongoDBResourceProvider implements ResourceProvider, ModifyingResou
     }
 
     /**
+     * TODO - we should handle delete different and not put all child resources into the
+     * deleted set.
+     * Instead when getting resources, the parents of the resource should be checked
+     * first.
+     * This minimizes concurrency issues.
      * @see org.apache.sling.api.resource.ModifyingResourceProvider#delete(org.apache.sling.api.resource.ResourceResolver, java.lang.String)
      */
     public void delete(final ResourceResolver resolver, final String path)
@@ -235,6 +240,7 @@ public class MongoDBResourceProvider implements ResourceProvider, ModifyingResou
     }
 
     /**
+     * TODO - we have to check for deleted and added resources
      * @see org.apache.sling.api.resource.ResourceProvider#listChildren(org.apache.sling.api.resource.Resource)
      */
     public Iterator<Resource> listChildren(final Resource parent) {

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

[sling-org-apache-sling-mongodb] 29/36: Update to Sling Parent POM 22 with baselining enabled

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-mongodb.git

commit 5e3644303e4dd0c3e21d29796c5438f41c23cfcc
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Wed Oct 1 06:52:29 2014 +0000

    Update to Sling Parent POM 22 with baselining enabled
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1628620 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index 2d3d0ae..97edc3c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
     <parent>
         <groupId>org.apache.sling</groupId>
         <artifactId>sling</artifactId>
-        <version>20</version>
+        <version>22</version>
     </parent>
 
     <groupId>org.apache.sling</groupId>

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

[sling-org-apache-sling-mongodb] 20/36: SLING-3002 : Make the Mongo Resource Provider easier to subclass. Apply patch from Dan McWeeney

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-mongodb.git

commit 4c0625f22ed94ff9be09c044858e20de047e2f73
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Fri Aug 9 06:13:24 2013 +0000

    SLING-3002 : Make the Mongo Resource Provider easier to subclass. Apply patch from Dan McWeeney
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1512146 13f79535-47bb-0310-9956-ffa450edef68
---
 .../sling/mongodb/impl/ChangeableValueMap.java     |  5 ++
 .../apache/sling/mongodb/impl/MongoDBContext.java  |  2 +-
 .../apache/sling/mongodb/impl/MongoDBResource.java |  4 +-
 .../mongodb/impl/MongoDBResourceProvider.java      | 64 ++++++++++++++++------
 .../impl/MongoDBResourceProviderFactory.java       | 23 +++++++-
 .../sling/mongodb/impl/ReadableValueMap.java       |  3 +
 .../OSGI-INF/metatype/metatype.properties          |  8 ++-
 7 files changed, 85 insertions(+), 24 deletions(-)

diff --git a/src/main/java/org/apache/sling/mongodb/impl/ChangeableValueMap.java b/src/main/java/org/apache/sling/mongodb/impl/ChangeableValueMap.java
index 5cc08b5..2061171 100644
--- a/src/main/java/org/apache/sling/mongodb/impl/ChangeableValueMap.java
+++ b/src/main/java/org/apache/sling/mongodb/impl/ChangeableValueMap.java
@@ -19,6 +19,7 @@ package org.apache.sling.mongodb.impl;
 import java.util.Map;
 
 import org.apache.sling.api.resource.ModifiableValueMap;
+import org.apache.sling.api.resource.Resource;
 
 public class ChangeableValueMap
     extends ReadableValueMap
@@ -79,4 +80,8 @@ public class ChangeableValueMap
         }
         return result;
     }
+    
+    protected MongoDBResource getResource() {
+        return this.resource;
+    }
 }
diff --git a/src/main/java/org/apache/sling/mongodb/impl/MongoDBContext.java b/src/main/java/org/apache/sling/mongodb/impl/MongoDBContext.java
index cd8ccc1..0c2e08a 100644
--- a/src/main/java/org/apache/sling/mongodb/impl/MongoDBContext.java
+++ b/src/main/java/org/apache/sling/mongodb/impl/MongoDBContext.java
@@ -116,5 +116,5 @@ public class MongoDBContext {
         props.put("event.distribute", "");
         final Event event = new Event(SlingConstants.TOPIC_RESOURCE_CHANGED, props);
         this.eventAdmin.postEvent(event);
-    }
+    }    
 }
diff --git a/src/main/java/org/apache/sling/mongodb/impl/MongoDBResource.java b/src/main/java/org/apache/sling/mongodb/impl/MongoDBResource.java
index 6ad685c..0aad630 100644
--- a/src/main/java/org/apache/sling/mongodb/impl/MongoDBResource.java
+++ b/src/main/java/org/apache/sling/mongodb/impl/MongoDBResource.java
@@ -38,7 +38,7 @@ public class MongoDBResource extends AbstractResource {
     private final ResourceResolver resourceResolver;
 
     /** Metadata. */
-    private final ResourceMetadata metadata = new ResourceMetadata();
+    protected ResourceMetadata metadata = new ResourceMetadata();
 
     /** The db object. */
     private DBObject dbObject;
@@ -136,7 +136,7 @@ public class MongoDBResource extends AbstractResource {
 
     @Override
     public String toString() {
-        return "MongoDBResource [resourcePath=" + resourcePath + ", dbPath=" + this.dbObject.get(MongoDBResourceProvider.PROP_PATH) + ", collection=" + collection
+        return "MongoDBResource [resourcePath=" + resourcePath + ", dbPath=" + this.dbObject.get(provider.getPROP_PATH()) + ", collection=" + collection
                         + ", resourceResolver=" + resourceResolver + "]";
     }
 
diff --git a/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProvider.java b/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProvider.java
index b362e16..b1168ed 100644
--- a/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProvider.java
+++ b/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProvider.java
@@ -27,9 +27,11 @@ import javax.servlet.http.HttpServletRequest;
 
 import org.apache.sling.api.resource.ModifyingResourceProvider;
 import org.apache.sling.api.resource.PersistenceException;
+import org.apache.sling.api.resource.QueriableResourceProvider;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceProvider;
 import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.resource.ValueMap;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -44,13 +46,13 @@ import com.mongodb.QueryBuilder;
  * The MongoDB resource provider creates resources based on MongoDB entries.
  * The resources contain all properties stored in the MongoDB except those starting with a "_".
  */
-public class MongoDBResourceProvider implements ResourceProvider, ModifyingResourceProvider {
+public class MongoDBResourceProvider implements ResourceProvider, ModifyingResourceProvider, QueriableResourceProvider {
 
     /** The special path property containing the (relative) path of the resource in the tree. */
-    public static final String PROP_PATH = "_path";
+    private static final String PROP_PATH = "_path";
 
     /** The id property. */
-    public static final String PROP_ID = "_id";
+    private static final String PROP_ID = "_id";
 
     /** Logger. */
     private final Logger logger = LoggerFactory.getLogger(this.getClass());
@@ -95,7 +97,7 @@ public class MongoDBResourceProvider implements ResourceProvider, ModifyingResou
                 throw new PersistenceException("Resource already exists at " + path, null, path, null);
             }
             final DBObject dbObj = new BasicDBObject();
-            dbObj.put(PROP_PATH, info[1]);
+            dbObj.put(getPROP_PATH(), info[1]);
             if ( properties != null ) {
                 for(Map.Entry<String, Object> entry : properties.entrySet()) {
                     final String key = propNameToKey(entry.getKey());
@@ -135,11 +137,11 @@ public class MongoDBResourceProvider implements ResourceProvider, ModifyingResou
                     final DBCollection col = this.getCollection(info[0]);
                     final String pattern = "^" + Pattern.quote(info[1]) + "/";
 
-                    final DBObject query = QueryBuilder.start(PROP_PATH).regex(Pattern.compile(pattern)).get();
+                    final DBObject query = QueryBuilder.start(getPROP_PATH()).regex(Pattern.compile(pattern)).get();
                     final DBCursor cur = col.find(query);
                     while ( cur.hasNext() ) {
                         final DBObject dbObj = cur.next();
-                        final String childPath = info[0] + '/' + dbObj.get(PROP_PATH);
+                        final String childPath = info[0] + '/' + dbObj.get(getPROP_PATH());
                         this.deletedResources.add(childPath);
                         this.changedResources.remove(childPath);
                     }
@@ -183,7 +185,7 @@ public class MongoDBResourceProvider implements ResourceProvider, ModifyingResou
                 // check if the collection still exists
                 final DBCollection col = this.getCollection(info[0]);
                 if ( col != null ) {
-                    if ( col.findAndRemove(QueryBuilder.start(PROP_PATH).is(info[1]).get()) != null ) {
+                    if ( col.findAndRemove(QueryBuilder.start(getPROP_PATH()).is(info[1]).get()) != null ) {
                         this.context.notifyRemoved(info);
                     }
                 }
@@ -193,10 +195,10 @@ public class MongoDBResourceProvider implements ResourceProvider, ModifyingResou
                 final DBCollection col = this.context.getDatabase().getCollection(changed.getCollection());
                 if ( col != null ) {
                     final String[] info = new String[] {changed.getCollection(),
-                            changed.getProperties().get(PROP_PATH).toString()};
+                            changed.getProperties().get(getPROP_PATH()).toString()};
                     // create or update?
                     if ( changed.getProperties().get(PROP_ID) != null ) {
-                        col.update(QueryBuilder.start(PROP_PATH).is(changed.getProperties().get(PROP_PATH)).get(),
+                        col.update(QueryBuilder.start(getPROP_PATH()).is(changed.getProperties().get(getPROP_PATH())).get(),
                                 changed.getProperties());
                         this.context.notifyUpdated(info);
                     } else {
@@ -283,9 +285,9 @@ public class MongoDBResourceProvider implements ResourceProvider, ModifyingResou
                     pattern = "^" + Pattern.quote(info[1]) + "/([^/])*$";
                 }
 
-                final DBObject query = QueryBuilder.start(PROP_PATH).regex(Pattern.compile(pattern)).get();
+                final DBObject query = QueryBuilder.start(getPROP_PATH()).regex(Pattern.compile(pattern)).get();
                 final DBCursor cur = col.find(query).
-                        sort(BasicDBObjectBuilder.start(PROP_PATH, 1).get());
+                        sort(BasicDBObjectBuilder.start(getPROP_PATH(), 1).get());
                 return new Iterator<Resource>() {
 
                     public boolean hasNext() {
@@ -294,7 +296,7 @@ public class MongoDBResourceProvider implements ResourceProvider, ModifyingResou
 
                     public Resource next() {
                         final DBObject obj = cur.next();
-                        final String objPath = obj.get(PROP_PATH).toString();
+                        final String objPath = obj.get(getPROP_PATH()).toString();
                         final int lastSlash = objPath.lastIndexOf('/');
                         final String name;
                         if (lastSlash == -1) {
@@ -332,7 +334,7 @@ public class MongoDBResourceProvider implements ResourceProvider, ModifyingResou
     /**
      * Extract info about collection and path
      */
-    private String[] extractResourceInfo(final String path) {
+    protected String[] extractResourceInfo(final String path) {
         if ( path.startsWith(this.context.getRootWithSlash()) ) {
             if ( path.length() == this.context.getRootWithSlash().length() ) {
                 // special resource - show all collections
@@ -358,16 +360,18 @@ public class MongoDBResourceProvider implements ResourceProvider, ModifyingResou
     /**
      * Check if a collection with a given name exists
      */
-    private boolean hasCollection(final String name) {
+    protected boolean hasCollection(final String name) {
+        logger.info("Mongo: Getting collection names");
         final Set<String> names = this.context.getDatabase().getCollectionNames();
         return names.contains(name) && !this.context.isFilterCollectionName(name);
     }
 
+    
     /**
      * Check if a collection with a given name exists and return it
      */
-    private DBCollection getCollection(final String name) {
-        if ( this.hasCollection(name) ) {
+    protected DBCollection getCollection(final String name) {
+        if ( this.hasCollection(name) ) {            
             return this.context.getDatabase().getCollection(name);
         }
         return null;
@@ -376,7 +380,7 @@ public class MongoDBResourceProvider implements ResourceProvider, ModifyingResou
     /**
      * Get a resource
      */
-    private Resource getResource(final ResourceResolver resourceResolver, final String path, final String[] info) {
+    protected Resource getResource(final ResourceResolver resourceResolver, final String path, final String[] info) {
         if ( info.length == 0 ) {
             // special resource : all collections
             return new MongoDBCollectionResource(resourceResolver, path);
@@ -390,7 +394,7 @@ public class MongoDBResourceProvider implements ResourceProvider, ModifyingResou
         logger.debug("Searching {} in {}", info[1], info[0]);
         final DBCollection col = this.getCollection(info[0]);
         if ( col != null ) {
-            final DBObject obj = col.findOne(QueryBuilder.start(PROP_PATH).is(info[1]).get());
+            final DBObject obj = col.findOne(QueryBuilder.start(getPROP_PATH()).is(info[1]).get());
             logger.debug("Found {}", obj);
             if ( obj != null ) {
                 return new MongoDBResource(resourceResolver,
@@ -414,4 +418,28 @@ public class MongoDBResourceProvider implements ResourceProvider, ModifyingResou
         }
         return dbObj;
     }
+    
+    protected Set<String> getDeletedResources() {
+        return this.deletedResources;
+    }
+    
+    protected Map<String, MongoDBResource> getChangedResources() {
+        return this.changedResources;
+    }
+    
+    protected MongoDBContext getContext() {
+        return this.context;
+    }
+    
+    protected String getPROP_PATH() {
+        return PROP_PATH;
+    }
+
+    public Iterator<Resource> findResources(ResourceResolver resolver, String query, String language) {
+        return null;
+    }
+
+    public Iterator<ValueMap> queryResources(ResourceResolver resolver, String query, String language) {
+        return null;
+    }
 }
diff --git a/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProviderFactory.java b/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProviderFactory.java
index 5eaeca0..9bcf562 100644
--- a/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProviderFactory.java
+++ b/src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProviderFactory.java
@@ -35,7 +35,9 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.mongodb.DB;
+import com.mongodb.DBAddress;
 import com.mongodb.Mongo;
+import com.mongodb.MongoOptions;
 
 /**
  * The MongoDB resource provider factory allows to provided resources stored
@@ -66,10 +68,18 @@ public class MongoDBResourceProviderFactory implements ResourceProviderFactory {
 
     @Property(value=DEFAULT_DB)
     private static final String PROP_DB = "db";
-
+    
     @Property(unbounded=PropertyUnbounded.ARRAY, value="system.indexes")
     private static final String PROP_FILTER_COLLECTIONS = "filter.collections";
 
+    private static final int DEFAULT_NUMCONNECTIONS = 10;
+    @Property(intValue=DEFAULT_NUMCONNECTIONS)
+    private static final String PROP_NUM_CONNECTIONS = "numconnections";
+
+    private static final int DEFAULT_THREAD_MULTIPLIER= 5;
+    @Property(intValue=DEFAULT_THREAD_MULTIPLIER)
+    private static final String  PROP_THREAD_MULTIPLIER = "threadmultiplier";
+    
     /** Logger. */
     private final Logger logger = LoggerFactory.getLogger(this.getClass());
 
@@ -96,8 +106,13 @@ public class MongoDBResourceProviderFactory implements ResourceProviderFactory {
         final String db = PropertiesUtil.toString(props.get(PROP_DB), DEFAULT_DB);
         logger.info("Starting MongoDB resource provider with host={}, port={}, db={}",
                 new Object[] {host, port, db});
+        final DBAddress address = new DBAddress(host, port, db);
+        final MongoOptions options = new MongoOptions();
+        
+        options.connectionsPerHost = PropertiesUtil.toInteger(props.get(PROP_NUM_CONNECTIONS), DEFAULT_NUMCONNECTIONS);
+        options.threadsAllowedToBlockForConnectionMultiplier = PropertiesUtil.toInteger(props.get(PROP_THREAD_MULTIPLIER), DEFAULT_THREAD_MULTIPLIER);
+        final Mongo m = new Mongo(address, options);
 
-        final Mongo m = new Mongo( host , port );
         final DB database = m.getDB( db );
         logger.info("Connected to database {}", database);
 
@@ -122,4 +137,8 @@ public class MongoDBResourceProviderFactory implements ResourceProviderFactory {
         // for now we allow anonymous access
         return new MongoDBResourceProvider(this.context);
     }
+    
+    protected MongoDBContext getContext() {
+        return this.context;
+    }
 }
diff --git a/src/main/java/org/apache/sling/mongodb/impl/ReadableValueMap.java b/src/main/java/org/apache/sling/mongodb/impl/ReadableValueMap.java
index c294d84..a363591 100644
--- a/src/main/java/org/apache/sling/mongodb/impl/ReadableValueMap.java
+++ b/src/main/java/org/apache/sling/mongodb/impl/ReadableValueMap.java
@@ -39,6 +39,9 @@ public class ReadableValueMap implements ValueMap {
 
     protected void createValueMap(final DBObject dbObject) {
         final Map<String, Object> map = new HashMap<String, Object>();
+        if (dbObject == null) {
+            this.valueMap = Collections.<String, Object> emptyMap();
+        }
         for(final String key : dbObject.keySet()) {
             final String name = MongoDBResourceProvider.keyToPropName(key);
             if ( name != null ) {
diff --git a/src/main/resources/OSGI-INF/metatype/metatype.properties b/src/main/resources/OSGI-INF/metatype/metatype.properties
index 4771886..22bcddd 100644
--- a/src/main/resources/OSGI-INF/metatype/metatype.properties
+++ b/src/main/resources/OSGI-INF/metatype/metatype.properties
@@ -43,4 +43,10 @@ db.name MongoDB Database
 db.description = The database to use.
 
 filter.collections.name = Filter Collections
-filter.collections.description = These collections are not available as resources.
\ No newline at end of file
+filter.collections.description = These collections are not available as resources.
+
+numconnections.name = Connections Per Host
+numconnections.description = MongoOptions.connectionsPerHost
+
+threadmultiplier.name = Thread Multiplier
+threadmultiplier.description = MongoOptions.threadsAllowedToBlockForConnectionMultiplier
\ No newline at end of file

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

[sling-org-apache-sling-mongodb] 36/36: SLING-7167 Adjust READMEs

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-mongodb.git

commit df2c32b0f5f8185a186d18446f6638bafce5cf32
Author: Oliver Lietz <ol...@apache.org>
AuthorDate: Tue Oct 3 10:04:12 2017 +0000

    SLING-7167 Adjust READMEs
    
    add uniform header linking to Sling project
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1810902 13f79535-47bb-0310-9956-ffa450edef68
---
 README.md | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/README.md b/README.md
index 2c101be..05b97dd 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,7 @@
+# Apache Sling MongoDB Resource Provider
+
+This module is part of the [Apache Sling](https://sling.apache.org) project.
+
 This is a Sling Resource Provider for MongoDB implementation (from 2012)
 
 The Sling provides also a different implementation based on the Generic NoSQL Resource Provider for MongoDB:

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

[sling-org-apache-sling-mongodb] 33/36: Update the contrib reactor to parent 25

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-mongodb.git

commit 12ce72a22a10e9d76a34fe9bfbbf38f41954c735
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Mon Oct 5 10:04:15 2015 +0000

    Update the contrib reactor to parent 25
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1706781 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index c1b19d1..861687d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
     <parent>
         <groupId>org.apache.sling</groupId>
         <artifactId>sling</artifactId>
-        <version>24</version>
+        <version>25</version>
         <relativePath/>
     </parent>
 

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

[sling-org-apache-sling-mongodb] 30/36: Update contrib modules to Parent 23

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-mongodb.git

commit 19300880964b2496301cf85231a18f8761fd6eba
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Thu Jun 25 13:10:59 2015 +0000

    Update contrib modules to Parent 23
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1687503 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index 97edc3c..f11af74 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
     <parent>
         <groupId>org.apache.sling</groupId>
         <artifactId>sling</artifactId>
-        <version>22</version>
+        <version>23</version>
     </parent>
 
     <groupId>org.apache.sling</groupId>

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