Slightly changed some methods and variables ('connection' -> 'sqlConnection').
authorMarco Zanon <info@marcozanon.com>
Thu, 29 Oct 2015 14:06:42 +0000 (14:06 +0000)
committerMarco Zanon <info@marcozanon.com>
Thu, 29 Oct 2015 14:06:42 +0000 (14:06 +0000)
4.x/src/java/com/marcozanon/macaco/logging/MLogDatabaseTable.java
4.x/src/java/com/marcozanon/macaco/sql/MSqlConnectionGenerator.java
4.x/src/java/com/marcozanon/macaco/sql/MSqlConnectionPool.java
4.x/src/java/com/marcozanon/macaco/sql/MSqlTable.java

index 6930b873af273d12efe0fc498034fb850fcd7c90..7e032307857c31301d2e5bcf0186eaf60e30be6b 100644 (file)
@@ -95,13 +95,13 @@ public class MLogDatabaseTable extends MLogTarget {
                 separator.append(" ");
             }
             //
-            MSqlConnection sqlConnection = this.getSqlConnectionPool().popConnection();
+            MSqlConnection sqlConnection = this.getSqlConnectionPool().popSqlConnection();
             //
             LinkedHashMap<String, Object> p = new LinkedHashMap<String, Object>();
             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);
index 0bf62273cc748d27f223057edc7cff9088c48982..1a98ddf950554f00b6e904582529896f18499af8 100644 (file)
@@ -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;
         }
         //
index 36c5be348c50ba08392afe5880d99b412334f47d..4523bfd2a1812019f5764ecb6517b0e2f6e87306 100644 (file)
@@ -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<MSqlConnection> connectionPool = new LinkedList<MSqlConnection>();
+    protected LinkedList<MSqlConnection> sqlConnectionPool = new LinkedList<MSqlConnection>();
 
     /* */
 
@@ -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<MSqlConnection> getConnectionPool() {
-        return this.connectionPool;
+    protected LinkedList<MSqlConnection> 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<MSqlConnection> connectionPool = this.getConnectionPool();
-        MSqlConnection connection = connectionPool.removeLast();
-        if (this.getMinimumSize() > connectionPool.size()) {
-            connectionPool.add(this.getConnectionGenerator().getNewConnection());
+    public synchronized MSqlConnection popSqlConnection() throws MSqlConnectionFailureException {
+        LinkedList<MSqlConnection> 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<MSqlConnection> connectionPool = this.getConnectionPool();
-        if (this.getMaximumSize() >= connectionPool.size()) {
-            connectionPool.add(connection);
+        LinkedList<MSqlConnection> sqlConnectionPool = this.getSqlConnectionPool();
+        if (this.getMaximumSize() >= sqlConnectionPool.size()) {
+            sqlConnectionPool.add(sqlConnection);
         }
     }
 
index 1c7cca47bafd3afbdf35b9dc259b20e082f023f0..932e776540a31f2709f1f599673152f788ad7085 100644 (file)
@@ -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<String, Object> 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<String, Object> map, Object id) throws MSqlStatementException {
@@ -117,10 +117,10 @@ public class MSqlTable extends MObject {
         //
         LinkedList<Object> p = new LinkedList<Object>();
         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<Object> p = new LinkedList<Object>();
         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);
     }
 
 }