jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chet...@apache.org
Subject svn commit: r1394968 - in /jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk: impl/MongoConnection.java util/MongoUtil.java
Date Sat, 06 Oct 2012 08:40:20 GMT
Author: chetanm
Date: Sat Oct  6 08:40:20 2012
New Revision: 1394968

URL: http://svn.apache.org/viewvc?rev=1394968&view=rev
Log:
OAK-366 - MongoDB microkernal integration with OSGi

* Adding bootstrap method to MongoUtil to create schema if it does not exist
* Adding a close method to dispose the underlying Mongo resources

Modified:
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/MongoConnection.java
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/util/MongoUtil.java

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/MongoConnection.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/MongoConnection.java?rev=1394968&r1=1394967&r2=1394968&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/MongoConnection.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/MongoConnection.java
Sat Oct  6 08:40:20 2012
@@ -32,11 +32,12 @@ import com.mongodb.gridfs.GridFS;
  */
 public class MongoConnection {
 
-    private static final String COLLECTION_COMMITS = "commits";
-    private static final String COLLECTION_HEAD = "head";
-    private static final String COLLECTION_NODES = "nodes";
+    public static final String COLLECTION_COMMITS = "commits";
+    public static final String COLLECTION_HEAD = "head";
+    public static final String COLLECTION_NODES = "nodes";
     private final DB db;
     private final GridFS gridFS;
+    private final Mongo mongo;
 
     /**
      * Constructs a new {@code MongoConnection}.
@@ -47,7 +48,8 @@ public class MongoConnection {
      * @throws Exception If an error occurred while trying to connect.
      */
     public MongoConnection(String host, int port, String database) throws Exception {
-        db = new Mongo(host, port).getDB(database);
+        mongo = new Mongo(host, port);
+        db = mongo.getDB(database);
         gridFS = new GridFS(db);
     }
 
@@ -81,6 +83,15 @@ public class MongoConnection {
     }
 
     /**
+     * Returns the {@link Mongo}.
+     *
+     * @return The {@link Mongo}.
+     */
+    public Mongo getMongo() {
+        return mongo;
+    }
+
+    /**
      * Returns the head {@link DBCollection}.
      *
      * @return The head {@link DBCollection}.
@@ -101,4 +112,13 @@ public class MongoConnection {
         nodeCollection.setObjectClass(NodeMongo.class);
         return nodeCollection;
     }
+
+    /**
+     * Closes the underlying Mongo instance
+     */
+    public void close(){
+        if(mongo != null){
+            mongo.close();
+        }
+    }
 }
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/util/MongoUtil.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/util/MongoUtil.java?rev=1394968&r1=1394967&r2=1394968&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/util/MongoUtil.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/util/MongoUtil.java
Sat Oct  6 08:40:20 2012
@@ -18,6 +18,7 @@ package org.apache.jackrabbit.mongomk.ut
 
 import java.util.Arrays;
 
+import com.mongodb.DB;
 import org.apache.jackrabbit.mongomk.impl.MongoConnection;
 import org.apache.jackrabbit.mongomk.model.CommitMongo;
 import org.apache.jackrabbit.mongomk.model.HeadMongo;
@@ -85,6 +86,19 @@ public class MongoUtil {
         initHeadCollection(mongoConnection);
     }
 
+    public static void bootstrap(MongoConnection mongoConnection){
+        DB db = mongoConnection.getDB();
+        if(!db.collectionExists(MongoConnection.COLLECTION_NODES)){
+            initNodeCollection(mongoConnection);
+        }
+        if(!db.collectionExists(MongoConnection.COLLECTION_COMMITS)){
+            initCommitCollection(mongoConnection);
+        }
+        if(!db.collectionExists(MongoConnection.COLLECTION_HEAD)){
+            initHeadCollection(mongoConnection);
+        }
+    }
+
     public static void initHeadCollection(MongoConnection mongoConnection) {
         DBCollection headCollection = mongoConnection.getHeadCollection();
         HeadMongo headMongo = new HeadMongo();



Mime
View raw message