jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r386845 - in /incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/db: DatabasePersistenceManager.java DerbyPersistenceManager.java
Date Sat, 18 Mar 2006 13:03:43 GMT
Author: jukka
Date: Sat Mar 18 05:03:32 2006
New Revision: 386845

URL: http://svn.apache.org/viewcvs?rev=386845&view=rev
Log:
JCR-313: More javadocs.
Added a DatabasePersistenceManager.closeConnection() method to simplify the DerbyPersistenceManager
shutdown sequence.

Modified:
    incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/db/DatabasePersistenceManager.java
    incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/db/DerbyPersistenceManager.java

Modified: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/db/DatabasePersistenceManager.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/db/DatabasePersistenceManager.java?rev=386845&r1=386844&r2=386845&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/db/DatabasePersistenceManager.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/db/DatabasePersistenceManager.java
Sat Mar 18 05:03:32 2006
@@ -314,7 +314,7 @@
             blobStore = null;
 
             // close jdbc connection
-            con.close();
+            closeConnection(con);
 
         } finally {
             initialized = false;
@@ -785,13 +785,38 @@
     }
 
     //----------------------------------< misc. helper methods & overridables >
+
     /**
-     * Initialize the JDBC connection.
+     * Abstract factory method for creating a new database connection. This
+     * method is called by {@link #init(PMContext)} when the persistence
+     * manager is started. The returned connection should come with the default
+     * JDBC settings, as the {@link #init(PMContext)} method will explicitly
+     * set the <code>autoCommit</code> and other properties as needed.
+     * <p>
+     * Note that the returned database connection is kept during the entire
+     * lifetime of the persistence manager, after which it is closed by
+     * {@link #close()} using the {@link #closeConnection(Connection)} method.
      *
      * @return new connection
      * @throws Exception if an error occurs
      */
-    abstract Connection getConnection() throws Exception;
+    protected abstract Connection getConnection() throws Exception;
+
+    /**
+     * Closes the given database connection. This method is called by
+     * {@link #close()} to close the connection acquired using
+     * {@link #getConnection()} when the persistence manager was started.
+     * <p>
+     * The default implementation just calls the {@link Connection#close()}
+     * method of the given connection, but subclasses can override this
+     * method to provide more extensive database and connection cleanup.
+     * 
+     * @param connection
+     * @throws Exception
+     */
+    protected void closeConnection(Connection connection) throws Exception {
+        connection.close();
+    }
 
     /**
      * Resets the given <code>PreparedStatement</code> by clearing the parameters

Modified: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/db/DerbyPersistenceManager.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/db/DerbyPersistenceManager.java?rev=386845&r1=386844&r2=386845&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/db/DerbyPersistenceManager.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/db/DerbyPersistenceManager.java
Sat Mar 18 05:03:32 2006
@@ -19,6 +19,7 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.SQLException;
 
@@ -73,22 +74,21 @@
         schemaObjectPrefix = "";
         user = "";
         password = "";
-        initialized = false;
     }
 
-    //---------------------------------< SimpleDbPersistenceManager overrides >
+    //------------------------------------------< DatabasePersistenceManager >
+
     /**
-     * {@inheritDoc}
-     * <p/>
-     * Overridden in order to properly shutdown the embedded Derby database.
+     * Closes the given connection by shutting down the embedded Derby
+     * database.
+     *
+     * @param connection database connection
+     * @throws SQLException if an error occurs
+     * @see DatabasePersistenceManager#closeConnection(Connection)
      */
-    public synchronized void close() throws Exception {
-        if (!initialized) {
-            throw new IllegalStateException("not initialized");
-        }
-
+    protected void closeConnection(Connection connection) throws SQLException {
         // prepare connection url for issuing shutdown command
-        String url = con.getMetaData().getURL();
+        String url = connection.getMetaData().getURL();
         int pos = url.lastIndexOf(';');
         if (pos != -1) {
             // strip any attributes from connection url
@@ -100,10 +100,7 @@
         // otherwise Derby would mysteriously complain about some pending uncommitted
         // changes which can't possibly be true.
         // @todo further investigate
-        con.setAutoCommit(true);
-
-        // call base class implementation
-        super.close();
+        connection.setAutoCommit(true);
 
         // now it's safe to shutdown the embedded Derby database
         try {



Mime
View raw message