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);
/* 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;
}
//
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>();
/* */
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;
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);
}
}
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.");
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. */
}
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 {
}
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 {
//
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 {
//
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 {
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);
}
}