From e6fb6e9c35b3b5a1d14b981c53069e842cbde37c Mon Sep 17 00:00:00 2001 From: Marco Zanon Date: Thu, 29 Oct 2015 14:06:42 +0000 Subject: [PATCH] Slightly changed some methods and variables ('connection' -> 'sqlConnection'). --- .../macaco/logging/MLogDatabaseTable.java | 4 +- .../macaco/sql/MSqlConnectionGenerator.java | 16 ++--- .../macaco/sql/MSqlConnectionPool.java | 58 +++++++++---------- .../com/marcozanon/macaco/sql/MSqlTable.java | 52 ++++++++--------- 4 files changed, 65 insertions(+), 65 deletions(-) diff --git a/src/java/com/marcozanon/macaco/logging/MLogDatabaseTable.java b/src/java/com/marcozanon/macaco/logging/MLogDatabaseTable.java index 6930b87..7e03230 100644 --- a/src/java/com/marcozanon/macaco/logging/MLogDatabaseTable.java +++ b/src/java/com/marcozanon/macaco/logging/MLogDatabaseTable.java @@ -95,13 +95,13 @@ public class MLogDatabaseTable extends MLogTarget { separator.append(" "); } // - MSqlConnection sqlConnection = this.getSqlConnectionPool().popConnection(); + MSqlConnection sqlConnection = this.getSqlConnectionPool().popSqlConnection(); // LinkedHashMap p = new LinkedHashMap(); p.put(this.getLogDatabaseField(), timestamp + separator + message); (new MSqlTable(sqlConnection, this.getLogDatabaseTable(), this.getLogDatabaseTablePrimaryKey())).setRecord(p, null); // - this.getSqlConnectionPool().pushConnection(sqlConnection); + this.getSqlConnectionPool().pushSqlConnection(sqlConnection); } catch (MSqlConnectionFailureException exception) { throw new MLoggingException("Could not write to database table.", exception); diff --git a/src/java/com/marcozanon/macaco/sql/MSqlConnectionGenerator.java b/src/java/com/marcozanon/macaco/sql/MSqlConnectionGenerator.java index 0bf6227..1a98ddf 100644 --- a/src/java/com/marcozanon/macaco/sql/MSqlConnectionGenerator.java +++ b/src/java/com/marcozanon/macaco/sql/MSqlConnectionGenerator.java @@ -66,25 +66,25 @@ public class MSqlConnectionGenerator extends MObject { /* Generator. */ - public MSqlConnection getNewConnection() throws MSqlConnectionFailureException { + public MSqlConnection getNewSqlConnection() throws MSqlConnectionFailureException { 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."); + public boolean isGeneratorFor(MSqlConnection sqlConnection) { + if (null == sqlConnection) { + throw new IllegalArgumentException("Invalid 'sqlConnection': null."); } // - if (!connection.getDriver().equals(this.getDriver())) { + if (!sqlConnection.getDriver().equals(this.getDriver())) { return false; } - if (!connection.getUrl().equals(this.getUrl())) { + if (!sqlConnection.getUrl().equals(this.getUrl())) { return false; } - if (!connection.getUsername().equals(this.getUsername())) { + if (!sqlConnection.getUsername().equals(this.getUsername())) { return false; } - if (!connection.getPassword().equals(this.getPassword())) { + if (!sqlConnection.getPassword().equals(this.getPassword())) { return false; } // diff --git a/src/java/com/marcozanon/macaco/sql/MSqlConnectionPool.java b/src/java/com/marcozanon/macaco/sql/MSqlConnectionPool.java index 36c5be3..4523bfd 100644 --- a/src/java/com/marcozanon/macaco/sql/MSqlConnectionPool.java +++ b/src/java/com/marcozanon/macaco/sql/MSqlConnectionPool.java @@ -11,11 +11,11 @@ import java.util.LinkedList; public class MSqlConnectionPool extends MObject { - protected MSqlConnectionGenerator connectionGenerator = null; + protected MSqlConnectionGenerator sqlConnectionGenerator = null; protected int minimumSize = 0; protected int maximumSize = 0; - protected LinkedList connectionPool = new LinkedList(); + protected LinkedList sqlConnectionPool = new LinkedList(); /* */ @@ -32,20 +32,20 @@ public class MSqlConnectionPool extends MObject { throw new IllegalArgumentException(String.format("Invalid 'maximumSize': %s < %s ('minimumSize').", maximumSize, minimumSize)); } // - this.connectionGenerator = new MSqlConnectionGenerator(driver, url, username, password); + this.sqlConnectionGenerator = new MSqlConnectionGenerator(driver, url, username, password); this.minimumSize = minimumSize; this.maximumSize = maximumSize; // - this.initializeConnectionPool(); + this.initializeSqlConnectionPool(); } - /* Connection generator. */ + /* Sql connection generator. */ - protected MSqlConnectionGenerator getConnectionGenerator() { - return this.connectionGenerator; + protected MSqlConnectionGenerator getSqlConnectionGenerator() { + return this.sqlConnectionGenerator; } - /* Connection pool. */ + /* Sql connection pool. */ protected int getMinimumSize() { return this.minimumSize; @@ -55,40 +55,40 @@ public class MSqlConnectionPool extends MObject { return this.maximumSize; } - protected LinkedList getConnectionPool() { - return this.connectionPool; + protected LinkedList getSqlConnectionPool() { + return this.sqlConnectionPool; } - protected void initializeConnectionPool() throws MSqlConnectionFailureException { + protected void initializeSqlConnectionPool() throws MSqlConnectionFailureException { for (int c = 0; c < this.getMinimumSize(); c++) { - MSqlConnection connection = this.getConnectionGenerator().getNewConnection(); - this.getConnectionPool().add(connection); + MSqlConnection sqlConnection = this.getSqlConnectionGenerator().getNewSqlConnection(); + this.getSqlConnectionPool().add(sqlConnection); } } - public synchronized MSqlConnection popConnection() throws MSqlConnectionFailureException { - LinkedList connectionPool = this.getConnectionPool(); - MSqlConnection connection = connectionPool.removeLast(); - if (this.getMinimumSize() > connectionPool.size()) { - connectionPool.add(this.getConnectionGenerator().getNewConnection()); + public synchronized MSqlConnection popSqlConnection() throws MSqlConnectionFailureException { + LinkedList sqlConnectionPool = this.getSqlConnectionPool(); + MSqlConnection sqlConnection = sqlConnectionPool.removeLast(); + if (this.getMinimumSize() > sqlConnectionPool.size()) { + sqlConnectionPool.add(this.getSqlConnectionGenerator().getNewSqlConnection()); } - return connection; + return sqlConnection; } - public synchronized void pushConnection(MSqlConnection connection) throws MSqlConnectionFailureException { - if (null == connection) { - throw new IllegalArgumentException("Invalid 'connection': null."); + public synchronized void pushSqlConnection(MSqlConnection sqlConnection) throws MSqlConnectionFailureException { + if (null == sqlConnection) { + throw new IllegalArgumentException("Invalid 'sqlConnection': null."); } - else if (!this.getConnectionGenerator().isGeneratorFor(connection)) { - throw new IllegalArgumentException("Invalid 'connection': not generated by this connection generator."); + else if (!this.getSqlConnectionGenerator().isGeneratorFor(sqlConnection)) { + throw new IllegalArgumentException("Invalid 'sqlConnection': not generated by this Sql connection generator."); } - else if (connection.isClosed()) { - throw new IllegalArgumentException("Invalid 'connection': closed."); + else if (sqlConnection.isClosed()) { + throw new IllegalArgumentException("Invalid 'sqlConnection': closed."); } // - LinkedList connectionPool = this.getConnectionPool(); - if (this.getMaximumSize() >= connectionPool.size()) { - connectionPool.add(connection); + LinkedList sqlConnectionPool = this.getSqlConnectionPool(); + if (this.getMaximumSize() >= sqlConnectionPool.size()) { + sqlConnectionPool.add(sqlConnection); } } diff --git a/src/java/com/marcozanon/macaco/sql/MSqlTable.java b/src/java/com/marcozanon/macaco/sql/MSqlTable.java index 1c7cca4..932e776 100644 --- a/src/java/com/marcozanon/macaco/sql/MSqlTable.java +++ b/src/java/com/marcozanon/macaco/sql/MSqlTable.java @@ -14,17 +14,17 @@ import java.util.LinkedList; public class MSqlTable extends MObject { - protected MSqlConnection connection = null; + protected MSqlConnection sqlConnection = null; protected String table = null; protected String primaryKey = null; /* */ - public MSqlTable(MSqlConnection connection, String table, String primaryKey) { + public MSqlTable(MSqlConnection sqlConnection, String table, String primaryKey) { super(); // - if (null == connection) { - throw new IllegalArgumentException("Invalid 'connection': null."); + if (null == sqlConnection) { + throw new IllegalArgumentException("Invalid 'sqlConnection': null."); } if (MText.isBlank(table)) { throw new IllegalArgumentException("Invalid 'table': null or empty."); @@ -33,15 +33,15 @@ public class MSqlTable extends MObject { throw new IllegalArgumentException("Invalid 'primaryKey': null or empty."); } // - this.connection = connection; + this.sqlConnection = sqlConnection; this.table = table; this.primaryKey = primaryKey; } - /* Connection. */ + /* Sql connection. */ - protected MSqlConnection getConnection() { - return this.connection; + protected MSqlConnection getSqlConnection() { + return this.sqlConnection; } /* Table. */ @@ -73,10 +73,10 @@ public class MSqlTable extends MObject { } fields.delete(fields.length() - 2, fields.length()); s.delete(s.length() - 2, s.length()); - return this.getConnection().executePreparedStatement(" INSERT INTO \"" + this.getTable() + "\"" - + " (" + fields + ")" - + " VALUES (" + s + ")", - p); + return this.getSqlConnection().executePreparedStatement(" INSERT INTO \"" + this.getTable() + "\"" + + " (" + fields + ")" + + " VALUES (" + s + ")", + p); } protected MSqlStatementResults updateRecord(LinkedHashMap map, Object id) throws MSqlStatementException { @@ -95,10 +95,10 @@ public class MSqlTable extends MObject { } s.delete(s.length() - 2, s.length()); p.add(id); - return this.getConnection().executePreparedStatement(" UPDATE \"" + this.getTable() + "\"" - + " SET " + s - + " WHERE (\"" + this.getTable() + "\".\"" + this.getPrimaryKey() + "\" = ?)", - p); + return this.getSqlConnection().executePreparedStatement(" UPDATE \"" + this.getTable() + "\"" + + " SET " + s + + " WHERE (\"" + this.getTable() + "\".\"" + this.getPrimaryKey() + "\" = ?)", + p); } public MSqlStatementResults setRecord(LinkedHashMap map, Object id) throws MSqlStatementException { @@ -117,10 +117,10 @@ public class MSqlTable extends MObject { // LinkedList p = new LinkedList(); p.add(id); - return this.getConnection().executePreparedStatement(" SELECT *" - + " FROM \"" + this.getTable() + "\"" - + " WHERE (\"" + this.getTable() + "\".\"" + this.getPrimaryKey() + "\" = ?)", - p); + return this.getSqlConnection().executePreparedStatement(" SELECT *" + + " FROM \"" + this.getTable() + "\"" + + " WHERE (\"" + this.getTable() + "\".\"" + this.getPrimaryKey() + "\" = ?)", + p); } public MSqlStatementResults deleteRecord(Object id) throws MSqlStatementException { @@ -130,9 +130,9 @@ public class MSqlTable extends MObject { // LinkedList p = new LinkedList(); p.add(id); - return this.getConnection().executePreparedStatement(" DELETE FROM \"" + this.getTable() + "\"" - + " WHERE (\"" + this.getTable() + "\".\"" + this.getPrimaryKey() + "\" = ?)", - p); + return this.getSqlConnection().executePreparedStatement(" DELETE FROM \"" + this.getTable() + "\"" + + " WHERE (\"" + this.getTable() + "\".\"" + this.getPrimaryKey() + "\" = ?)", + p); } public MSqlStatementResults deleteRecords(LinkedHashSet idSet) throws MSqlStatementException { @@ -146,9 +146,9 @@ public class MSqlTable extends MObject { whereClause.append(" OR (\"" + this.getTable() + "\".\"" + this.getPrimaryKey() + "\" = ?)"); p.add(id); } - return this.getConnection().executePreparedStatement(" DELETE FROM \"" + this.getTable() + "\"" - + " WHERE (" + whereClause + ")", - p); + return this.getSqlConnection().executePreparedStatement(" DELETE FROM \"" + this.getTable() + "\"" + + " WHERE (" + whereClause + ")", + p); } } -- 2.30.2