T - the type of the results produced by a JDBC operationprotected abstract class Log4jOverridableConfigurer.JdbcOperation<T> extends Object
https://apache.googlesource.com/commons-configuration/+/trunk/src/main/java/org/apache/commons/configuration2/DatabaseConfiguration.javaUsing a simple low level JDBC class such as this as opposed to a higher level abstraction such as JPA/Hibernate is preferred since we want logging initialized before as many other technologies as possible. That way, we will be able to capture higher level technology logging in our Log4J logs and not lose it.
| Modifier | Constructor and Description |
|---|---|
protected |
JdbcOperation(DataSource dataSource)
Creates a new instance of
JdbcOperation. |
| Modifier and Type | Method and Description |
|---|---|
protected void |
close(Connection connection,
Statement statement,
ResultSet resultSet)
Close the specified database objects.
|
T |
execute()
Executes this operation.
|
protected Connection |
getConnection()
Returns the current connection.
|
protected PreparedStatement |
initStatement(String sql,
Object... parameters)
Creates an initializes a
PreparedStatement object for executing an SQL statement. |
protected ResultSet |
openResultSet(String sql,
Object... params)
Creates a
PreparedStatement for a query, initializes it and executes it. |
protected abstract T |
performOperation()
Performs the JDBC operation.
|
protected JdbcOperation(DataSource dataSource)
JdbcOperation.dataSource - the data source to the database.protected abstract T performOperation() throws SQLException
execute() after this object has been fully initialized. Here the actual JDBC logic has
to be placed.SQLException - if an SQL error occurspublic T execute() throws SQLException
performOperation(). Afterwards it performs the
necessary clean up.SQLException - if there was a problem executing the operation.protected ResultSet openResultSet(String sql, Object... params) throws SQLException
PreparedStatement for a query, initializes it and executes it. The resulting ResultSet is returned.sql - the statement to be executed.params - the parameters for the statement.ResultSet produced by the query.SQLException - if an SQL error occurs.protected PreparedStatement initStatement(String sql, Object... parameters) throws SQLException
PreparedStatement object for executing an SQL statement.sql - the statement to be executedparameters - the parameters for the statementSQLException - if an SQL error occursprotected Connection getConnection()
execute() is running. It returns null otherwise.protected void close(Connection connection, Statement statement, ResultSet resultSet)
connection - The database connection to closestatement - The statement to closeresultSet - the result set to closeCopyright © 2021. All rights reserved.