From 52d47be03c7c94d6c67e4f788ee7f5e4ec1b1465 Mon Sep 17 00:00:00 2001 From: Marco Zanon Date: Tue, 27 Oct 2015 13:29:56 +0000 Subject: [PATCH] Implemented MSqlConnectionPool.isGeneratorFor() to determine whether a connection belongs to a pool. --- .../macaco/sql/MSqlConnectionGenerator.java | 21 +++++++++++++++++++ .../macaco/sql/MSqlConnectionPool.java | 3 +++ 2 files changed, 24 insertions(+) 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."); } -- 2.30.2