- All Implemented Interfaces:
AutoCloseable
,DbOperations
close()
if not explicitly committed using
commit()
or rolled back using rollback()
before.
Start a new transaction using SimpleConnection.startTransaction()
.
Operations are not allowed on a closed, committed or rolled back transaction.
Closing an already closed transaction is a no-op.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Rollback transaction if not already committed or rolled back and restore original auto commit setting if necessary.void
commit()
Commit the transaction.void
executeScript
(String sqlScript) Execute all commands in a SQL script, separated with;
.int
executeUpdate
(String sql) Execute a single SQL statement.int
executeUpdate
(String sql, PreparedStatementSetter preparedStatementSetter) Execute a single SQL statement as a prepared statement with placeholders.Get the original wrapped connection.Create a prepared statement batch builder for inserting or updating rows by directly setting values of aPreparedStatement
.preparedStatementBatch
(Class<T> rowType) Execute a SQL query and return aresult set
with genericRow
s.<T> SimpleResultSet<T>
query
(String sql, PreparedStatementSetter preparedStatementSetter, RowMapper<T> rowMapper) Execute a SQL query, set parameters and return aresult set
with rows converted to a custom typeDbOperations
.void
rollback()
Rollback the transaction.Create a batch statement builder for executing multiple statements in a batch.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.itsallcode.jdbc.DbOperations
executeUpdate, query, query
-
Method Details
-
commit
Commit the transaction.No further operations are allowed on this transaction afterwards.
- See Also:
-
rollback
Rollback the transaction.No further operations are allowed on this transaction afterwards.
- See Also:
-
executeUpdate
Description copied from interface:DbOperations
Execute a single SQL statement.- Specified by:
executeUpdate
in interfaceDbOperations
- Parameters:
sql
- SQL statement- Returns:
- either the row count for SQL Data Manipulation Language (DML) statements or 0 for SQL statements that return nothing
-
executeUpdate
Description copied from interface:DbOperations
Execute a single SQL statement as a prepared statement with placeholders.- Specified by:
executeUpdate
in interfaceDbOperations
- Parameters:
sql
- SQL statementpreparedStatementSetter
- prepared statement setter- Returns:
- either the row count for SQL Data Manipulation Language (DML) statements or 0 for SQL statements that return nothing
-
query
Description copied from interface:DbOperations
Execute a SQL query and return aresult set
with genericRow
s.- Specified by:
query
in interfaceDbOperations
- Parameters:
sql
- SQL query- Returns:
- result set
-
executeScript
Description copied from interface:DbOperations
Execute all commands in a SQL script, separated with;
.- Specified by:
executeScript
in interfaceDbOperations
- Parameters:
sqlScript
- script to execute.
-
query
public <T> SimpleResultSet<T> query(String sql, PreparedStatementSetter preparedStatementSetter, RowMapper<T> rowMapper) Description copied from interface:DbOperations
Execute a SQL query, set parameters and return aresult set
with rows converted to a custom typeDbOperations
.- Specified by:
query
in interfaceDbOperations
- Type Parameters:
T
- generic row type- Parameters:
sql
- SQL querypreparedStatementSetter
- the prepared statement setterrowMapper
- row mapper- Returns:
- the result set
-
statementBatch
Description copied from interface:DbOperations
Create a batch statement builder for executing multiple statements in a batch.- Specified by:
statementBatch
in interfaceDbOperations
- Returns:
- batch statement builder
-
preparedStatementBatch
Description copied from interface:DbOperations
Create a prepared statement batch builder for inserting or updating rows by directly setting values of aPreparedStatement
.If you want to insert rows from an
Iterator
or aStream
, useDbOperations.preparedStatementBatch(Class)
.- Specified by:
preparedStatementBatch
in interfaceDbOperations
- Returns:
- batch insert builder
-
preparedStatementBatch
Description copied from interface:DbOperations
Create a row-based prepared statement batch builder for inserting or updating rows from anIterator
or aStream
.If you want to insert rows by directly setting values of a
PreparedStatement
, useDbOperations.preparedStatementBatch()
.- Specified by:
preparedStatementBatch
in interfaceDbOperations
- Type Parameters:
T
- row type- Parameters:
rowType
- row type- Returns:
- row-based batch insert builder
-
getOriginalConnection
Description copied from interface:DbOperations
Get the original wrapped connection.Use this in case of missing features in
DbOperations
.- Specified by:
getOriginalConnection
in interfaceDbOperations
- Returns:
- original wrapped connection
-
close
Rollback transaction if not already committed or rolled back and restore original auto commit setting if necessary.Explicitly run
commit()
before to commit your transaction.No further operations are allowed on this transaction afterwards.
This does not close the connection, so you can continue using it.
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceDbOperations
-