You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by re...@apache.org on 2015/05/29 16:54:44 UTC

svn commit: r1682494 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb: RDBBlobStore.java RDBConnectionHandler.java RDBDocumentStore.java

Author: reschke
Date: Fri May 29 14:54:44 2015
New Revision: 1682494

URL: http://svn.apache.org/r1682494
Log:
OAK-2930 - RDBBlob/DocumentStore: do not NPE calls after dispose()

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBBlobStore.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBConnectionHandler.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBBlobStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBBlobStore.java?rev=1682494&r1=1682493&r2=1682494&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBBlobStore.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBBlobStore.java Fri May 29 14:54:44 2015
@@ -100,12 +100,16 @@ public class RDBBlobStore extends Cachin
                 }
             }
         }
-        this.ch = null;
+        try {
+            this.ch.close();
+        } catch (IOException ex) {
+            LOG.error("closing connection handler", ex);
+        }
     }
 
     @Override
     protected void finalize() {
-        if (this.ch != null && this.callStack != null) {
+        if (!this.ch.isClosed() && this.callStack != null) {
             LOG.debug("finalizing RDBDocumentStore that was not disposed", this.callStack);
         }
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBConnectionHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBConnectionHandler.java?rev=1682494&r1=1682493&r2=1682494&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBConnectionHandler.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBConnectionHandler.java Fri May 29 14:54:44 2015
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.oak.plugins.document.rdb;
 
+import java.io.Closeable;
+import java.io.IOException;
 import java.sql.Connection;
 import java.sql.ResultSet;
 import java.sql.SQLException;
@@ -32,9 +34,10 @@ import org.slf4j.LoggerFactory;
 /**
  * Utility functions for connection handling.
  */
-public class RDBConnectionHandler {
+public class RDBConnectionHandler implements Closeable {
 
-    private final DataSource ds;
+    private DataSource ds;
+    private long closedTime = 0L;
 
     private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(RDBConnectionHandler.class);
 
@@ -56,7 +59,7 @@ public class RDBConnectionHandler {
      * Obtain a {@link Connection} suitable for read-only operations.
      */
     public @Nonnull Connection getROConnection() throws SQLException {
-        Connection c = this.ds.getConnection();
+        Connection c = getDataSource().getConnection();
         c.setAutoCommit(false);
         setReadOnly(c, true);
         return c;
@@ -66,7 +69,7 @@ public class RDBConnectionHandler {
      * Obtain a {@link Connection} suitable for read-write operations.
      */
     public @Nonnull Connection getRWConnection() throws SQLException {
-        Connection c = this.ds.getConnection();
+        Connection c = getDataSource().getConnection();
         c.setAutoCommit(false);
         setReadOnly(c, false);
         return c;
@@ -139,6 +142,24 @@ public class RDBConnectionHandler {
         return null;
     }
 
+    public boolean isClosed() {
+        return this.ds == null;
+    }
+
+    @Override
+    public void close() throws IOException {
+        this.ds = null;
+        this.closedTime = System.currentTimeMillis();
+    }
+
+    private DataSource getDataSource() throws IllegalStateException {
+        DataSource result = this.ds;
+        if (result == null) {
+            throw new IllegalStateException("Connection handler is already closed ("
+                    + (System.currentTimeMillis() - this.closedTime) + "ms ago)");
+        }
+        return result;
+    }
 
     // workaround for broken connection wrappers
     // see https://issues.apache.org/jira/browse/OAK-2918

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java?rev=1682494&r1=1682493&r2=1682494&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java Fri May 29 14:54:44 2015
@@ -347,7 +347,11 @@ public class RDBDocumentStore implements
             }
             this.droppedTables = dropped.trim();
         }
-        this.ch = null;
+        try {
+            this.ch.close();
+        } catch (IOException ex) {
+            LOG.error("closing connection handler", ex);
+        }
     }
 
     @Override
@@ -911,7 +915,7 @@ public class RDBDocumentStore implements
 
     @Override
     protected void finalize() {
-        if (this.ch != null && this.callStack != null) {
+        if (!this.ch.isClosed() && this.callStack != null) {
             LOG.debug("finalizing RDBDocumentStore that was not disposed", this.callStack);
         }
     }