You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by th...@apache.org on 2008/01/21 16:15:32 UTC

svn commit: r613914 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: data/db/ fs/db/ journal/ persistence/db/

Author: thomasm
Date: Mon Jan 21 07:15:31 2008
New Revision: 613914

URL: http://svn.apache.org/viewvc?rev=613914&view=rev
Log:
JCR-1309 Refactor DBMS support for JNDI datasources

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbDataStore.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/DbFileSystem.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/JNDIDatabaseFileSystem.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/DatabaseJournal.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/JNDIDatabaseJournal.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/db/SimpleDbPersistenceManager.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbDataStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbDataStore.java?rev=613914&r1=613913&r2=613914&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbDataStore.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbDataStore.java Mon Jan 21 07:15:31 2008
@@ -67,6 +67,14 @@
  * The remaining settings are generated using the database URL sub-protocol from the
  * database type resource file.
  * <p>
+ * JNDI can be used to get the connection. In this case, use the javax.naming.InitialContext as the driver,
+ * and the JNDI name as the URL. If the user and password are configured in the JNDI resource,
+ * they should not be configured here. Example JNDI settings:
+ * <pre>
+ * &lt;param name="driver" value="javax.naming.InitialContext" />
+ * &lt;param name="url" value="java:comp/env/jdbc/Test" />
+ * </pre>
+ * <p>
  * A three level directory structure is used to avoid placing too many
  * files in a single directory. The chosen structure is designed to scale
  * up to billions of distinct records.

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/DbFileSystem.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/DbFileSystem.java?rev=613914&r1=613913&r2=613914&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/DbFileSystem.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/DbFileSystem.java Mon Jan 21 07:15:31 2008
@@ -16,10 +16,13 @@
  */
 package org.apache.jackrabbit.core.fs.db;
 
+import org.apache.jackrabbit.core.persistence.bundle.util.ConnectionFactory;
+
 import java.sql.Connection;
-import java.sql.DriverManager;
 import java.sql.SQLException;
 
+import javax.jcr.RepositoryException;
+
 /**
  * <code>DbFileSystem</code> is a generic JDBC-based <code>FileSystem</code>
  * implementation for Jackrabbit that persists file system entries in a
@@ -85,6 +88,13 @@
  *       &lt;param name="schemaObjectPrefix" value="rep_"/&gt;
  *   &lt;/FileSystem&gt;
  * </pre>
+ * JNDI can be used to get the connection. In this case, use the javax.naming.InitialContext as the driver,
+ * and the JNDI name as the URL. If the user and password are configured in the JNDI resource,
+ * they should not be configured here. Example JNDI settings:
+ * <pre>
+ * &lt;param name="driver" value="javax.naming.InitialContext" />
+ * &lt;param name="url" value="java:comp/env/jdbc/Test" />
+ * </pre>
  * See also {@link DerbyFileSystem}, {@link DB2FileSystem}, {@link OracleFileSystem}.
  */
 public class DbFileSystem extends DatabaseFileSystem {
@@ -182,9 +192,8 @@
      *
      * @throws SQLException if an error occurs
      */
-    protected Connection getConnection() throws ClassNotFoundException, SQLException {
-        Class.forName(driver);
-        return DriverManager.getConnection(url, user, password);
+    protected Connection getConnection() throws RepositoryException, SQLException {
+        return ConnectionFactory.getConnection(driver, url, user, password);
     }
 
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/JNDIDatabaseFileSystem.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/JNDIDatabaseFileSystem.java?rev=613914&r1=613913&r2=613914&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/JNDIDatabaseFileSystem.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/JNDIDatabaseFileSystem.java Mon Jan 21 07:15:31 2008
@@ -23,6 +23,12 @@
 import java.sql.SQLException;
 
 /**
+ * @deprecated
+ * This class should not be used because it is not database vendor specific. 
+ * Each DatabaseFileSystem now supports getting the connection via JNDI
+ * by setting the driver to javax.naming.InitialContext 
+ * and the URL to the JNDI name.
+ * <p>
  * Database file system that uses JNDI to acquire the database connection.
  * The JNDI location of the {@link DataSource} to be used in given as
  * the <code>dataSourceLocation</code> configuration property. See the

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/DatabaseJournal.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/DatabaseJournal.java?rev=613914&r1=613913&r2=613914&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/DatabaseJournal.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/DatabaseJournal.java Mon Jan 21 07:15:31 2008
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.core.journal;
 
+import org.apache.jackrabbit.core.persistence.bundle.util.ConnectionFactory;
 import org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver;
 import org.apache.jackrabbit.util.Text;
 import org.slf4j.Logger;
@@ -27,12 +28,13 @@
 import java.io.InputStreamReader;
 import java.sql.Connection;
 import java.sql.DatabaseMetaData;
-import java.sql.DriverManager;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
 
+import javax.jcr.RepositoryException;
+
 /**
  * Database-based journal implementation. Stores records inside a database table named
  * <code>JOURNAL</code>, whereas the table <code>GLOBAL_REVISION</code> contains the
@@ -55,6 +57,14 @@
  * <li><code>password</code>: password to specify when connecting</li>
  * <li><code>reconnectDelayMs</code>: number of milliseconds to wait before
  * trying to reconnect to the database.
+ * <p>
+ * JNDI can be used to get the connection. In this case, use the javax.naming.InitialContext as the driver,
+ * and the JNDI name as the URL. If the user and password are configured in the JNDI resource,
+ * they should not be configured here. Example JNDI settings:
+ * <pre>
+ * &lt;param name="driver" value="javax.naming.InitialContext" />
+ * &lt;param name="url" value="java:comp/env/jdbc/Test" />
+ * </pre> * 
  * </ul>
  */
 public class DatabaseJournal extends AbstractJournal {
@@ -243,7 +253,7 @@
         try {
             Class.forName(driver);
         } catch (ClassNotFoundException e) {
-            String msg = "Unable to load JDBC driver class.";
+            String msg = "Unable to load driver class.";
             throw new JournalException(msg, e);
         }
     }
@@ -257,10 +267,16 @@
      *
      * @see #init()
      * @return new connection
-     * @throws SQLException if an error occurs
+     * @throws JournalException if the driver could not be loaded
+     * @throws SQLException if the connection could not be established
      */
-    protected Connection getConnection() throws SQLException {
-        return DriverManager.getConnection(url, user, password);
+    protected Connection getConnection() throws SQLException, JournalException {
+        try {
+            return ConnectionFactory.getConnection(driver, url, user, password);
+        } catch (RepositoryException e) {
+            String msg = "Unable to load driver class.";
+            throw new JournalException(msg, e);        
+        }
     }
 
     /**
@@ -569,7 +585,7 @@
      * exists, waits until at least <code>reconnectTimeMs</code> have passed
      * since the error occurred and recreates the connection.
      */
-    private void checkConnection() throws SQLException {
+    private void checkConnection() throws SQLException, JournalException {
         if (connection == null) {
             long delayMs = reconnectTimeMs - System.currentTimeMillis();
             if (delayMs > 0) {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/JNDIDatabaseJournal.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/JNDIDatabaseJournal.java?rev=613914&r1=613913&r2=613914&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/JNDIDatabaseJournal.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/JNDIDatabaseJournal.java Mon Jan 21 07:15:31 2008
@@ -24,6 +24,12 @@
 import javax.sql.DataSource;
 
 /**
+ * @deprecated
+ * This class should not be used because it is not database vendor specific. 
+ * Each DatabaseJournal now supports getting the connection via JNDI
+ * by setting the driver to javax.naming.InitialContext 
+ * and the URL to the JNDI name.
+ * <p>
  * Database journal that uses JNDI to acquire the database connection.
  * The JNDI location of the {@link DataSource} to be used in given as
  * the <code>dataSourceLocation</code> configuration property.

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/db/SimpleDbPersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/db/SimpleDbPersistenceManager.java?rev=613914&r1=613913&r2=613914&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/db/SimpleDbPersistenceManager.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/db/SimpleDbPersistenceManager.java Mon Jan 21 07:15:31 2008
@@ -16,12 +16,15 @@
  */
 package org.apache.jackrabbit.core.persistence.db;
 
+import org.apache.jackrabbit.core.persistence.bundle.util.ConnectionFactory;
 import org.apache.jackrabbit.core.persistence.util.Serializer;
 
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.SQLException;
 
+import javax.jcr.RepositoryException;
+
 /**
  * <code>SimpleDbPersistenceManager</code> is a generic JDBC-based
  * <code>PersistenceManager</code> for Jackrabbit that persists
@@ -107,6 +110,13 @@
  *       &lt;param name="externalBLOBs" value="false"/&gt;
  *   &lt;/PersistenceManager&gt;
  * </pre>
+ * JNDI can be used to get the connection. In this case, use the javax.naming.InitialContext as the driver,
+ * and the JNDI name as the URL. If the user and password are configured in the JNDI resource,
+ * they should not be configured here. Example JNDI settings:
+ * <pre>
+ * &lt;param name="driver" value="javax.naming.InitialContext" />
+ * &lt;param name="url" value="java:comp/env/jdbc/Test" />
+ * </pre>
  * See also {@link DerbyPersistenceManager}, {@link OraclePersistenceManager}.
  */
 public class SimpleDbPersistenceManager extends DatabasePersistenceManager {
@@ -153,15 +163,14 @@
 
     /**
      * Returns a JDBC connection acquired using the JDBC {@link DriverManager}.
+     * @throws SQLException 
      *
-     * @throws ClassNotFoundException if the JDBC driver class is not found
-     * @throws SQLException if a database access error occurs
+     * @throws RepositoryException if the driver could not be loaded
+     * @throws SQLException if the connection could not be established
      * @see DatabasePersistenceManager#getConnection()
      */
-    protected Connection getConnection() throws ClassNotFoundException, SQLException {
-        Class.forName(driver);
-        Connection connection = DriverManager.getConnection(url, user, password);
-        return connection;
+    protected Connection getConnection() throws RepositoryException, SQLException {
+        return ConnectionFactory.getConnection(driver, url, user, password);
     }
 
 }