jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r735671 - /jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/main/java/org/apache/jackrabbit/jdbc/JCRDriver.java
Date Mon, 19 Jan 2009 12:02:52 GMT
Author: jukka
Date: Mon Jan 19 04:02:51 2009
New Revision: 735671

URL: http://svn.apache.org/viewvc?rev=735671&view=rev
Log:
jdbc2jcr: Support repository access through RMI (both http and rmiregistry) and JNDI.

Modified:
    jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/main/java/org/apache/jackrabbit/jdbc/JCRDriver.java

Modified: jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/main/java/org/apache/jackrabbit/jdbc/JCRDriver.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/main/java/org/apache/jackrabbit/jdbc/JCRDriver.java?rev=735671&r1=735670&r2=735671&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/main/java/org/apache/jackrabbit/jdbc/JCRDriver.java
(original)
+++ jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/main/java/org/apache/jackrabbit/jdbc/JCRDriver.java
Mon Jan 19 04:02:51 2009
@@ -18,6 +18,7 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.net.MalformedURLException;
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.DriverPropertyInfo;
@@ -31,8 +32,11 @@
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.SimpleCredentials;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
 
 import org.apache.derby.jdbc.EmbeddedDriver;
+import org.apache.jackrabbit.rmi.repository.RMIRemoteRepository;
 import org.apache.jackrabbit.rmi.repository.URLRemoteRepository;
 
 public class JCRDriver extends EmbeddedDriver {
@@ -48,6 +52,26 @@
         }
     }
 
+    private Repository getRepository(String url) throws SQLException {
+        if (url.startsWith("http://") || url.startsWith("https://")) {
+            try {
+                return new URLRemoteRepository(url);
+            } catch (MalformedURLException e) {
+                throw new SQLExceptionWithCause("Invalid URL: " + url, e);
+            }
+        } else if (url.startsWith("rmi://")) {
+            return new RMIRemoteRepository(url.substring(4));
+        } else if (url.startsWith("jndi://")) {
+            try {
+                return (Repository) new InitialContext().lookup(url.substring(7));
+            } catch (NamingException e) {
+                throw new SQLExceptionWithCause("Name not found: " + url, e);
+            }
+        } else {
+            throw new SQLException("Unknown JCR connect URL: " + url);
+        }
+    }
+
     @Override
     public Connection connect(String url, Properties info) throws SQLException {
         if (!url.startsWith("jdbc:jcr:")) {
@@ -55,7 +79,7 @@
         }
         try {
             Repository repository =
-                new URLRemoteRepository(url.substring("jdbc:jcr:".length()));
+                getRepository(url.substring("jdbc:jcr:".length()));
             String workspace = info.getProperty("workspace");
             Credentials credentials = null;
             String username = info.getProperty("username");



Mime
View raw message