Implemented MSqlConnectionPool.isGeneratorFor() to determine whether a connection...
authorMarco Zanon <info@marcozanon.com>
Tue, 27 Oct 2015 13:29:56 +0000 (13:29 +0000)
committerMarco Zanon <info@marcozanon.com>
Tue, 27 Oct 2015 13:29:56 +0000 (13:29 +0000)
4.x/src/java/com/marcozanon/macaco/sql/MSqlConnectionGenerator.java
4.x/src/java/com/marcozanon/macaco/sql/MSqlConnectionPool.java

index 574d1f1bf021527f84e8fe4d8079f0b7a9faa142..f33036537378473e49ac98625977d44f7c355153 100644 (file)
@@ -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;
+    }
+
 }
index 9aedb6e574986dc27a9c18e1d91d4e953f531491..5315211ea25abfc4519653537261cd7e35e9ae87 100644 (file)
@@ -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.");
         }