public class SQLExecutor
extends java.lang.Object
SQLStatementLogger.| Modifier and Type | Class and Description |
|---|---|
static interface |
SQLExecutor.BiConsumerWithException<T,U>
Functional interface, similar to
BiConsumer, but with the capability to throw an Exception. |
static interface |
SQLExecutor.ConsumerWithException<T>
Functional interface, similar to
Consumer, but with the capability to throw an Exception. |
static interface |
SQLExecutor.DMLStatement
A more specific
ConsumerWithException, applied to PreparedStatement only. |
static interface |
SQLExecutor.FunctionWithException<T,R>
Functional interface, similar to
Function, but with the capability to throw an Exception. |
static interface |
SQLExecutor.LambdaLogger
Basic interface that groups the functional interfaces used for logging statements.
|
protected static class |
SQLExecutor.LambdaLoggerType
Enumeration used to distinguish between different
SQLExecutor.LambdaLoggers. |
static interface |
SQLExecutor.QueryStatement
A more specific
FunctionWithException, applied to PreparedStatement and
ResultSet only. |
static interface |
SQLExecutor.UpdateBatchStatement
A more specific
FunctionWithException, applied to PreparedStatement and
int[] only. |
static interface |
SQLExecutor.UpdateStatement
A more specific
FunctionWithException, applied to PreparedStatement and
Integer only. |
| Modifier and Type | Field and Description |
|---|---|
private int |
defaultBatchSize
Usually, SQLs are executed one by one.
|
private static SQLExecutor |
instance
The static singleton instance.
|
| Modifier | Constructor and Description |
|---|---|
private |
SQLExecutor()
The private default constructor.
|
| Modifier and Type | Method and Description |
|---|---|
<T,U> void |
execute(Database database,
SQLExecutor.BiConsumerWithException<T,U> r,
T receiver,
U otherReceiver)
Logs a statement for a database.
|
<T> void |
execute(Database database,
java.lang.String sql,
SQLExecutor.ConsumerWithException<T> r,
T receiver)
Logs a statement for a database.
|
<T> void |
execute(Database database,
java.lang.String sql,
SQLExecutor.ConsumerWithException<T> r,
T receiver,
int batchSize)
Logs a statement for a database.
|
<T,U> U |
execute(Database database,
java.lang.String sql,
SQLExecutor.FunctionWithException<T,U> r,
T receiver)
Logs a statement for a database.
|
private <T,U> U |
execute(Database database,
java.lang.String sql,
SQLExecutor.LambdaLogger r,
T receiver,
U otherReceiver,
int batchSize,
SQLExecutor.LambdaLoggerType type)
Logs a statement for a database.
|
private <T,U> U |
executeImpl(SQLExecutor.LambdaLogger r,
T receiver,
U otherReceiver,
SQLExecutor.LambdaLoggerType type) |
static SQLExecutor |
getInstance()
Static accessor to singleton.
|
private static final SQLExecutor instance
private final int defaultBatchSize
public static SQLExecutor getInstance()
SQLExecutor singleton instance.public <T> void execute(Database database, java.lang.String sql, SQLExecutor.ConsumerWithException<T> r, T receiver) throws java.sql.SQLException
Database are disabled the method will
return without printing anything.T - The statement type.database - The reference Database.sql - String representing the SQL used in the statement.r - A SQLExecutor.ConsumerWithException that handles the execution of a statement.receiver - Receiver denoting the statement that will be executed.java.sql.SQLExceptionpublic <T> void execute(Database database, java.lang.String sql, SQLExecutor.ConsumerWithException<T> r, T receiver, int batchSize) throws java.sql.SQLException
Database are disabled the method will
return without printing anything.T - The statement type.database - The reference Database.sql - String representing the SQL used in the statement.r - A SQLExecutor.ConsumerWithException that handles the execution of a statement.receiver - Receiver denoting the statement that will be executed.batchSize - How many SQLs are executed in this batch.java.sql.SQLExceptionpublic <T,U> void execute(Database database, SQLExecutor.BiConsumerWithException<T,U> r, T receiver, U otherReceiver) throws java.sql.SQLException
Database are disabled the method will
return without printing anything. It will use the toString() method of the Statement.T - The statement type.U - The argument type.database - The reference Database.r - A SQLExecutor.BiConsumerWithException that handles the execution of a statement with a parameter.receiver - Receiver denoting the statement that will be executed.otherReceiver - The parameter that will be given to the execution.java.sql.SQLExceptionpublic <T,U> U execute(Database database, java.lang.String sql, SQLExecutor.FunctionWithException<T,U> r, T receiver) throws java.sql.SQLException
Database are disabled the method will
return without printing anything. It will use the toString() method of the Statement.T - The statement type.U - The result type.database - The reference Database.sql - The SQL used in the statement.r - SQLExecutor.FunctionWithException that handles the execution of a statement and returns a result.receiver - Receiver denoting the statement that will be executed.java.sql.SQLExceptionprivate <T,U> U execute(Database database, java.lang.String sql, SQLExecutor.LambdaLogger r, T receiver, U otherReceiver, int batchSize, SQLExecutor.LambdaLoggerType type) throws java.sql.SQLException
Database are disabled the method will
return without printing anything.T - The statement type.U - The argument type or the result type, depending on LambaLoggerType.database - The reference Database.sql - The SQL used in the statement.r - A SQLExecutor.LambdaLoggerType that handles the execution of a statement.receiver - Receiver denoting the statement that will be executed.otherReceiver - The parameter that will be given to the execution.batchSize - How many SQLs are executed in this batch.type - The type of the receiver.java.sql.SQLExceptionprivate <T,U> U executeImpl(SQLExecutor.LambdaLogger r, T receiver, U otherReceiver, SQLExecutor.LambdaLoggerType type) throws java.sql.SQLException
T - The statement type.U - The argument type or the result type, depending on LambaLoggerType.r - A SQLExecutor.LambdaLoggerType that handles the execution of a statement.receiver - Receiver denoting the statement that will be executed.otherReceiver - The parameter that will be given to the execution.type - The type of the receiver.java.sql.SQLException