Added a simple check to determine if a connection is closed.
authorMarco Zanon <info@marcozanon.com>
Fri, 23 Oct 2015 14:23:13 +0000 (14:23 +0000)
committerMarco Zanon <info@marcozanon.com>
Fri, 23 Oct 2015 14:23:13 +0000 (14:23 +0000)
4.x/src/java/com/marcozanon/macaco/sql/MSqlConnection.java
4.x/src/java/com/marcozanon/macaco/sql/MSqlConnectionPool.java

index 8a2d4f85c9ba5c79e1122c823c26e6144b4d9d2e..9ea683eb818f9a7b10ab32719e62db6cc127f220 100644 (file)
@@ -91,6 +91,15 @@ public class MSqlConnection extends MObject {
         }
     }
 
+    public boolean isClosed() throws MSqlConnectionFailureException {
+        try {
+            return this.getConnectionReference().isClosed();
+        }
+        catch (SQLException exception) {
+            throw new MSqlConnectionFailureException("Could not determine the state.", exception);
+        }
+    }
+
     protected void finalize() {
         try {
             this.close();
index 940eaff2bce4b36e8574d410080174f7d2cd2e8e..9aedb6e574986dc27a9c18e1d91d4e953f531491 100644 (file)
@@ -75,10 +75,13 @@ public class MSqlConnectionPool extends MObject {
         return connection;
     }
 
-    public synchronized void pushConnection(MSqlConnection connection) {
+    public synchronized void pushConnection(MSqlConnection connection) throws MSqlConnectionFailureException {
         if (null == connection) {
             throw new IllegalArgumentException("Invalid 'connection': null.");
         }
+        else if (connection.isClosed()) {
+            throw new IllegalArgumentException("Invalid 'connection': closed.");
+        }
         //
         LinkedList<MSqlConnection> connectionPool = this.getConnectionPool();
         if (this.getMaximumSize() >= connectionPool.size()) {