Package com.landawn.abacus.jdbc
Class SQLTransaction
java.lang.Object
com.landawn.abacus.jdbc.SQLTransaction
- All Implemented Interfaces:
Transaction
,Closeable
,AutoCloseable
DO NOT CLOSE the connection manually. It will be automatically closed after the transaction is committed or rolled back.
- Since:
- 0.8
- Author:
- Haiyang Li
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.landawn.abacus.jdbc.Transaction
Transaction.Action, Transaction.Status
-
Method Summary
Modifier and TypeMethodDescription<R,
E extends Throwable>
RcallNotInMe
(com.landawn.abacus.util.Throwables.Callable<R, E> cmd) Execute the specifiedCallable
not this transaction.void
close()
rollbackIfNotCommitted
is called.void
commit()
boolean
int
hashCode()
id()
Returns the identifier of this transaction if it's supported.boolean
isActive()
Checks if is active.void
rollback()
Deprecated.void
Rollback if not committed.<E extends Throwable>
voidrunNotInMe
(com.landawn.abacus.util.Throwables.Runnable<E> cmd) Execute the specifiedRunnable
not this transaction.status()
toString()
-
Method Details
-
id
Description copied from interface:Transaction
Returns the identifier of this transaction if it's supported.- Specified by:
id
in interfaceTransaction
- Returns:
-
connection
- Returns:
-
isolationLevel
- Specified by:
isolationLevel
in interfaceTransaction
- Returns:
-
status
- Specified by:
status
in interfaceTransaction
- Returns:
-
isActive
public boolean isActive()Checks if is active.- Specified by:
isActive
in interfaceTransaction
- Returns:
- true, if is active
-
commit
public void commit() throws com.landawn.abacus.exception.UncheckedSQLException- Specified by:
commit
in interfaceTransaction
- Throws:
com.landawn.abacus.exception.UncheckedSQLException
- the unchecked SQL exception
-
rollback
Deprecated.replaced by#rollbackIfNotCommitted()
Transaction can be started:final SQLTransaction tran = sqlExecutor.beginTransaction(IsolationLevel.READ_COMMITTED); try { // sqlExecutor.insert(...); // sqlExecutor.update(...); // sqlExecutor.query(...); tran.commit(); } finally { // The connection will be automatically closed after the transaction is committed or rolled back. tran.rollbackIfNotCommitted(); }
- Specified by:
rollback
in interfaceTransaction
- Throws:
com.landawn.abacus.exception.UncheckedSQLException
- the unchecked SQL exception- See Also:
-
SQLExecutor#beginTransaction(IsolationLevel)
-
rollbackIfNotCommitted
public void rollbackIfNotCommitted() throws com.landawn.abacus.exception.UncheckedSQLExceptionRollback if not committed.- Throws:
com.landawn.abacus.exception.UncheckedSQLException
- the unchecked SQL exception
-
runNotInMe
public <E extends Throwable> void runNotInMe(com.landawn.abacus.util.Throwables.Runnable<E> cmd) throws E Execute the specifiedRunnable
not this transaction.- Type Parameters:
E
-- Parameters:
cmd
-- Throws:
E
-
callNotInMe
public <R,E extends Throwable> R callNotInMe(com.landawn.abacus.util.Throwables.Callable<R, E> cmd) throws EExecute the specifiedCallable
not this transaction.- Type Parameters:
R
-E
-- Parameters:
cmd
-- Returns:
- Throws:
E
-
close
public void close()rollbackIfNotCommitted
is called.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- See Also:
-
hashCode
public int hashCode() -
equals
-
toString
-
#rollbackIfNotCommitted()