You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by re...@apache.org on 2014/04/14 16:08:20 UTC

svn commit: r1587212 - in /jackrabbit/oak/trunk/oak-core: pom.xml src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java

Author: reschke
Date: Mon Apr 14 14:08:20 2014
New Revision: 1587212

URL: http://svn.apache.org/r1587212
Log:
OAJ-1708 - hack DocumentNodeStoreService to support RDBDocumentStore (WIP)

Modified:
    jackrabbit/oak/trunk/oak-core/pom.xml
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java

Modified: jackrabbit/oak/trunk/oak-core/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/pom.xml?rev=1587212&r1=1587211&r2=1587212&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-core/pom.xml Mon Apr 14 14:08:20 2014
@@ -38,7 +38,12 @@
         <artifactId>maven-bundle-plugin</artifactId>
         <configuration>
           <instructions>
+            <Embed-Dependency>commons-dbcp,commons-pool,h2,json-simple</Embed-Dependency>
+            <Embed-Transitive>true</Embed-Transitive>
             <Import-Package>
+              org.apache.lucene.*;resolution:=optional,
+              org.osgi.service.jdbc.*;resolution:=optional,
+              com.vividsolutions.jts.*;resolution:=optional,
               *
             </Import-Package>
             <Export-Package>
@@ -212,7 +217,7 @@
       <groupId>com.googlecode.json-simple</groupId>
       <artifactId>json-simple</artifactId>
       <version>1.1.1</version>
-      <optional>true</optional>
+      <!--<optional>true</optional>-->
     </dependency>
     <dependency>
       <groupId>org.apache.jackrabbit</groupId>
@@ -277,14 +282,17 @@
       <groupId>com.h2database</groupId>
       <artifactId>h2</artifactId>
       <version>1.3.175</version>
-      <optional>true</optional>
     </dependency>
     <dependency>
       <groupId>commons-dbcp</groupId>
       <artifactId>commons-dbcp</artifactId>
       <version>1.4</version>
-      <optional>true</optional>
     </dependency>
+    <!--<dependency>
+      <groupId>commons-pool</groupId>
+      <artifactId>commons-pool</artifactId>
+      <version>1.6</version>
+    </dependency>-->
 
     <!-- Logging -->
     <dependency>

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java?rev=1587212&r1=1587211&r2=1587212&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java Mon Apr 14 14:08:20 2014
@@ -25,13 +25,12 @@ import java.util.ArrayList;
 import java.util.Dictionary;
 import java.util.Hashtable;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
 
-import com.mongodb.DB;
-import com.mongodb.MongoClient;
-import com.mongodb.MongoClientOptions;
-import com.mongodb.MongoClientURI;
+import javax.sql.DataSource;
+
 import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.ConfigurationPolicy;
@@ -50,6 +49,7 @@ import org.apache.jackrabbit.oak.plugins
 import org.apache.jackrabbit.oak.plugins.blob.BlobGCMBean;
 import org.apache.jackrabbit.oak.plugins.blob.BlobGarbageCollector;
 import org.apache.jackrabbit.oak.plugins.document.cache.CachingDocumentStore;
+import org.apache.jackrabbit.oak.plugins.document.rdb.RDBDataSourceFactory;
 import org.apache.jackrabbit.oak.plugins.document.util.MongoConnection;
 import org.apache.jackrabbit.oak.spi.blob.BlobStore;
 import org.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore;
@@ -66,6 +66,11 @@ import org.osgi.service.component.Compon
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.mongodb.DB;
+import com.mongodb.MongoClient;
+import com.mongodb.MongoClientOptions;
+import com.mongodb.MongoClientURI;
+
 /**
  * The OSGi service to start/stop a DocumentNodeStore instance.
  */
@@ -179,22 +184,6 @@ public class DocumentNodeStoreService {
         int changesSize = PropertiesUtil.toInteger(prop(PROP_CHANGES_SIZE), DEFAULT_CHANGES_SIZE);
         boolean useMK = PropertiesUtil.toBoolean(context.getProperties().get(PROP_USE_MK), false);
 
-
-        MongoClientOptions.Builder builder = MongoConnection.getDefaultBuilder();
-        MongoClientURI mongoURI = new MongoClientURI(uri, builder);
-
-        if (log.isInfoEnabled()) {
-            // Take care around not logging the uri directly as it
-            // might contain passwords
-            String type = useMK ? "MK" : "NodeStore";
-            log.info("Starting Document{} with host={}, db={}, cache size (MB)={}, Off Heap Cache size (MB)={}, 'changes' collection size (MB)={}",
-                    type, mongoURI.getHosts(), db, cacheSize, offHeapCache, changesSize);
-            log.info("Mongo Connection details {}", MongoConnection.toString(mongoURI.getOptions()));
-        }
-
-        MongoClient client = new MongoClient(mongoURI);
-        DB mongoDB = client.getDB(db);
-
         DocumentMK.Builder mkBuilder =
                 new DocumentMK.Builder().
                 memoryCacheSize(cacheSize * MB).
@@ -205,12 +194,60 @@ public class DocumentNodeStoreService {
             mkBuilder.setBlobStore(blobStore);
         }
 
-        mkBuilder.setMongoDB(mongoDB, changesSize);
+        String jdbcuri = System.getProperty("oak.jdbc.connection.uri", "");
+
+        log.info("jdbcuri {}", jdbcuri);
+
+        if (!jdbcuri.isEmpty()) {
+            // FIXME
+            String username = System.getProperty("oak.jdbc.username", "");
+            String passwd = System.getProperty("oak.jdbc.password", "");
+            String driver = System.getProperty("oak.jdbc.driver.class", "");
+
+            if (driver.length() > 0) {
+                try {
+                    Class.forName(driver);
+                } catch (ClassNotFoundException e) {
+                    // TODO Auto-generated catch block
+                    e.printStackTrace();
+                }
+            }
+
+            if (log.isInfoEnabled()) {
+                String type = useMK ? "MK" : "NodeStore";
+                log.info("Starting Document{} with uri={}, cache size (MB)={}, Off Heap Cache size (MB)={}, 'changes' collection size (MB)={}",
+                        type, jdbcuri, cacheSize, offHeapCache, changesSize);
+            }
+
+            DataSource ds = RDBDataSourceFactory.forJdbcUrl(jdbcuri, username, passwd);
+            mkBuilder.setRDBConnection(ds);
+
+            log.info("Connected to datasource {}", ds);
+        }
+        else {
+            MongoClientOptions.Builder builder = MongoConnection.getDefaultBuilder();
+            MongoClientURI mongoURI = new MongoClientURI(uri, builder);
+
+            if (log.isInfoEnabled()) {
+                // Take care around not logging the uri directly as it
+                // might contain passwords
+                String type = useMK ? "MK" : "NodeStore";
+                log.info("Starting Document{} with host={}, db={}, cache size (MB)={}, Off Heap Cache size (MB)={}, 'changes' collection size (MB)={}",
+                        type, mongoURI.getHosts(), db, cacheSize, offHeapCache, changesSize);
+                log.info("Mongo Connection details {}", MongoConnection.toString(mongoURI.getOptions()));
+            }
+
+            MongoClient client = new MongoClient(mongoURI);
+            DB mongoDB = client.getDB(db);
+
+            mkBuilder.setMongoDB(mongoDB, changesSize);
+
+            log.info("Connected to database {}", mongoDB);
+        }
+
         mkBuilder.setExecutor(executor);
         mk = mkBuilder.open();
 
-        log.info("Connected to database {}", mongoDB);
-
         registerJMXBeans(mk.getNodeStore());
         registerLastRevRecoveryJob(mk.getNodeStore());