From: Marco Zanon Date: Tue, 27 Oct 2015 13:29:56 +0000 (+0000) Subject: Implemented MSqlConnectionPool.isGeneratorFor() to determine whether a connection... X-Git-Tag: SVN-to-Git~88 X-Git-Url: https://gitweb.marcozanon.com/?a=commitdiff_plain;h=52d47be03c7c94d6c67e4f788ee7f5e4ec1b1465;p=Macaco Implemented MSqlConnectionPool.isGeneratorFor() to determine whether a connection belongs to a pool. --- diff --git a/4.x/src/java/com/marcozanon/macaco/sql/MSqlConnectionGenerator.java b/4.x/src/java/com/marcozanon/macaco/sql/MSqlConnectionGenerator.java index 574d1f1..f330365 100644 --- a/4.x/src/java/com/marcozanon/macaco/sql/MSqlConnectionGenerator.java +++ b/4.x/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/4.x/src/java/com/marcozanon/macaco/sql/MSqlConnectionPool.java b/4.x/src/java/com/marcozanon/macaco/sql/MSqlConnectionPool.java index 9aedb6e..5315211 100644 --- a/4.x/src/java/com/marcozanon/macaco/sql/MSqlConnectionPool.java +++ b/4.x/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."); }