From: Marco Zanon <info@marcozanon.com>
Date: Tue, 27 Oct 2015 13:29:56 +0000 (+0000)
Subject: Implemented MSqlConnectionPool.isGeneratorFor() to determine whether a connection... 
X-Git-Tag: 4.0~7
X-Git-Url: https://gitweb.marcozanon.com/?a=commitdiff_plain;h=8b9100f4762f42ac31da5cf84c133bf06a2e08d3;p=Macaco

Implemented MSqlConnectionPool.isGeneratorFor() to determine whether a connection belongs to a pool.
---

diff --git a/src/java/com/marcozanon/macaco/sql/MSqlConnectionGenerator.java b/src/java/com/marcozanon/macaco/sql/MSqlConnectionGenerator.java
index 574d1f1..f330365 100644
--- a/src/java/com/marcozanon/macaco/sql/MSqlConnectionGenerator.java
+++ b/src/java/com/marcozanon/macaco/sql/MSqlConnectionGenerator.java
@@ -70,4 +70,25 @@ public class MSqlConnectionGenerator extends MObject {
         return new MSqlConnection(this.getDriver(), this.getUrl(), this.getUsername(), this.getPassword());
     }
 
+    public boolean isGeneratorFor(MSqlConnection connection) {
+        if (null == connection) {
+            throw new IllegalArgumentException("Invalid 'connection': null.");
+        }
+        //
+        if (!connection.getDriver().equals(this.getDriver())) {
+            return false;
+        }
+        if (!connection.getUrl().equals(this.getUrl())) {
+            return false;
+        }
+        if (!connection.getUsername().equals(this.getUsername())) {
+            return false;
+        }
+        if (!connection.getPassword().equals(this.getPassword())) {
+            return false;
+        }
+        //
+        return true;
+    }
+
 }
diff --git a/src/java/com/marcozanon/macaco/sql/MSqlConnectionPool.java b/src/java/com/marcozanon/macaco/sql/MSqlConnectionPool.java
index 9aedb6e..5315211 100644
--- a/src/java/com/marcozanon/macaco/sql/MSqlConnectionPool.java
+++ b/src/java/com/marcozanon/macaco/sql/MSqlConnectionPool.java
@@ -79,6 +79,9 @@ public class MSqlConnectionPool extends MObject {
         if (null == connection) {
             throw new IllegalArgumentException("Invalid 'connection': null.");
         }
+        else if (!this.getConnectionGenerator().isGeneratorFor(connection)) {
+            throw new IllegalArgumentException("Invalid 'connection': not generated by this connection generator.");
+        }
         else if (connection.isClosed()) {
             throw new IllegalArgumentException("Invalid 'connection': closed.");
         }