jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r783383 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db: DbDataStore.java DerbyDataStore.java
Date Wed, 10 Jun 2009 14:57:38 GMT
Author: thomasm
Date: Wed Jun 10 14:57:37 2009
New Revision: 783383

URL: http://svn.apache.org/viewvc?rev=783383&view=rev
Log:
JCR-2128 DerbyDataStore to handle proper close of the embedded database

Added:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DerbyDataStore.java
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbDataStore.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=783383&r1=783382&r2=783383&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
Wed Jun 10 14:57:37 2009
@@ -828,7 +828,7 @@
     /**
      * {@inheritDoc}
      */
-    public synchronized void close() {
+    public synchronized void close() throws DataStoreException {
         ArrayList<ConnectionRecoveryManager> list = connectionPool.getAll();
         for (ConnectionRecoveryManager conn : list) {
             conn.close();

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DerbyDataStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DerbyDataStore.java?rev=783383&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DerbyDataStore.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DerbyDataStore.java
Wed Jun 10 14:57:37 2009
@@ -0,0 +1,65 @@
+package org.apache.jackrabbit.core.data.db;
+
+import java.sql.DriverManager;
+import java.sql.SQLException;
+
+import org.apache.jackrabbit.core.data.DataStoreException;
+import org.apache.jackrabbit.core.persistence.bundle.DerbyPersistenceManager;
+import org.apache.jackrabbit.core.persistence.bundle.util.ConnectionRecoveryManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The Derby data store closes the database when the data store is closed
+ * (embedded databases only).
+ */
+public class DerbyDataStore extends DbDataStore {
+
+    /**
+     * Logger instance
+     */
+    private static Logger log = LoggerFactory.getLogger(DerbyDataStore.class);
+
+    public synchronized void close() throws DataStoreException {
+        super.close();
+
+        // check for embedded driver
+        if (!DerbyPersistenceManager.DERBY_EMBEDDED_DRIVER.equals(getDriver())) {
+            return;
+        }
+
+        try {
+
+            // prepare connection url for issuing shutdown command
+            ConnectionRecoveryManager connectionManager = getConnection();
+
+            String url = connectionManager.getConnection().getMetaData().getURL();
+            int pos = url.lastIndexOf(';');
+            if (pos != -1) {
+                // strip any attributes from connection url
+                url = url.substring(0, pos);
+            }
+            url += ";shutdown=true";
+
+            // we have to reset the connection to 'autoCommit=true' before closing it;
+            // otherwise Derby would mysteriously complain about some pending uncommitted
+            // changes which can't possibly be true.
+            // @todo further investigate
+            connectionManager.getConnection().setAutoCommit(true);
+
+            // need to call it again because we just opened a connection,
+            // and super.close() closes it.
+            super.close();
+
+            // now it's safe to shutdown the embedded Derby database
+            try {
+                DriverManager.getConnection(url);
+            } catch (SQLException e) {
+                // a shutdown command always raises a SQLException
+                log.info(e.getMessage());
+            }
+        } catch (Exception e) {
+            throw new DataStoreException(e);
+        }
+    }
+}



Mime
View raw message