Index: C:/data/jackrabbit/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleDbPersistenceManager.java
===================================================================
--- C:/data/jackrabbit/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleDbPersistenceManager.java	(revision 598953)
+++ C:/data/jackrabbit/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleDbPersistenceManager.java	(working copy)
@@ -197,7 +197,12 @@
     }
 
     /**
-     * Sets the JDBC connection url.
+     * Sets the JDBC connection URL.
+     * The connection can be created using a JNDI Data Source as well. 
+     * To do that, the driver class name must reference a javax.naming.Context class 
+     * (for example javax.naming.InitialContext), and the URL must be the JNDI URL 
+     * (for example java:comp/env/jdbc/Test).
+     * 
      * @param url the url to set.
      */
     public void setUrl(String url) {
@@ -247,6 +252,7 @@
     /**
      * Sets the class name of the JDBC driver. The driver class will be loaded
      * during {@link #init(PMContext) init} in order to assure the existence.
+     * If no driver is specified, the default driver for the database is used.
      *
      * @param driver the class name of the driver
      */
Index: C:/data/jackrabbit/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/MySqlPersistenceManager.java
===================================================================
--- C:/data/jackrabbit/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/MySqlPersistenceManager.java	(revision 598953)
+++ C:/data/jackrabbit/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/MySqlPersistenceManager.java	(working copy)
@@ -26,7 +26,7 @@
  * <li>&lt;param name="{@link #setBundleCacheSize(String) bundleCacheSize}" value="8"/>
  * <li>&lt;param name="{@link #setConsistencyCheck(String) consistencyCheck}" value="false"/>
  * <li>&lt;param name="{@link #setMinBlobSize(String) minBlobSize}" value="16384"/>
- * <li>&lt;param name="{@link #setDriver(String) driver}" value="org.gjt.mm.mysql.Drive"/>
+ * <li>&lt;param name="{@link #setDriver(String) driver}" value="org.gjt.mm.mysql.Driver"/>
  * <li>&lt;param name="{@link #setUrl(String) url}" value=""/>
  * <li>&lt;param name="{@link #setUser(String) user}" value=""/>
  * <li>&lt;param name="{@link #setPassword(String) password}" value=""/>
Index: C:/data/jackrabbit/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/OraclePersistenceManager.java
===================================================================
--- C:/data/jackrabbit/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/OraclePersistenceManager.java	(revision 598953)
+++ C:/data/jackrabbit/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/OraclePersistenceManager.java	(working copy)
@@ -128,7 +128,7 @@
     }
 
     /**
-     * Retruns a new instance of a NGKDbNameIndex.
+     * Returns a new instance of a NGKDbNameIndex.
      * @return a new instance of a NGKDbNameIndex.
      * @throws SQLException if an SQL error occurs.
      */
Index: C:/data/jackrabbit/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ConnectionRecoveryManager.java
===================================================================
--- C:/data/jackrabbit/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ConnectionRecoveryManager.java	(revision 598953)
+++ C:/data/jackrabbit/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ConnectionRecoveryManager.java	(working copy)
@@ -19,7 +19,6 @@
 import java.io.InputStream;
 import java.sql.Connection;
 import java.sql.DatabaseMetaData;
-import java.sql.DriverManager;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
@@ -326,18 +325,7 @@
      */
     private void setupConnection() throws SQLException, RepositoryException {
         try {
-            if (driver != null && driver.length() > 0) {
-                Class driverClass = Class.forName(driver);
-                // Workaround for Apache Derby:
-                // The JDBC specification recommends the Class.ForName method without the .newInstance() method call, 
-                // but adding the newInstance() guarantees that Derby will be booted on any Java Virtual Machine.
-                driverClass.newInstance();
-            }
-        } catch (Throwable e) {
-            throw new RepositoryException("Could not load or initialize the database driver class " + driver, e);
-        }
-        try {
-            connection = DriverManager.getConnection(url, user, password);
+            connection = ConnectionFactory.getConnection(driver, url, user, password);
         } catch (SQLException e) {
             log.warn("Could not connect; driver: " + driver + " url: " + url + " user: " + user + " error: " + e.toString(), e);
             throw e;
Index: C:/data/jackrabbit/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ConnectionFactory.java
===================================================================
--- C:/data/jackrabbit/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ConnectionFactory.java	(revision 0)
+++ C:/data/jackrabbit/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ConnectionFactory.java	(revision 0)
@@ -0,0 +1,81 @@
+/*
+ * 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.jackrabbit.core.persistence.bundle.util;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+
+import javax.jcr.RepositoryException;
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.sql.DataSource;
+
+/**
+ * A factory for new database connections.
+ * Supported are regular JDBC drivers, as well as
+ * JNDI resources.
+ */
+public class ConnectionFactory {
+    
+    /**
+     * Open a connection using the specified properties.
+     * The connection can be created using a JNDI Data Source as well. To do that,
+     * the driver class name must reference a javax.naming.Context class 
+     * (for example javax.naming.InitialContext), and the URL must be the JNDI URL 
+     * (for example java:comp/env/jdbc/Test).
+     * 
+     * @param driver the JDBC driver or the Context class
+     * @param url the database URL
+     * @param user the user name
+     * @param password the password 
+     * @return the connection
+     * @throws RepositoryException if the driver could not be loaded
+     * @throws SQLException if the connection could not be established
+     */
+    public static Connection getConnection(String driver, String url,
+            String user, String password) throws RepositoryException,
+            SQLException {
+        if (driver != null || driver.length() > 0) {
+            try {
+                Class d = Class.forName(driver);
+                if (javax.naming.Context.class.isAssignableFrom(d)) {
+                    // JNDI context
+                    Context context = (Context) d.newInstance();
+                    DataSource ds = (DataSource) context.lookup(url);
+                    return ds.getConnection(user, password);
+                } else {
+                    // Workaround for Apache Derby:
+                    // The JDBC specification recommends the Class.forName method without the .newInstance() method call, 
+                    // but adding the newInstance() guarantees that Derby will be booted on any Java Virtual Machine.
+                    // This is required after a Derby 'shutdown'.
+                    d.newInstance();
+                }
+            } catch (ClassNotFoundException e) {
+                throw new RepositoryException("Could not load class " + driver, e);
+            } catch (InstantiationException e) {
+                throw new RepositoryException("Could not instantiate context " + driver, e);
+            } catch (IllegalAccessException e) {
+                throw new RepositoryException("Could not instantiate context " + driver, e);
+            } catch (NamingException e) {
+                throw new RepositoryException("Naming exception using " + driver + " url: " + url, e);
+            }
+        }
+        return DriverManager.getConnection(url, user, password);
+    }
+
+}

Property changes on: C:\data\jackrabbit\jackrabbit-core\src\main\java\org\apache\jackrabbit\core\persistence\bundle\util\ConnectionFactory.java
___________________________________________________________________
Name: svn:eol-style
   + native

