org.fluentjdbc.DbTransaction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fluent-jdbc Show documentation
Show all versions of fluent-jdbc Show documentation
A Java library used to execute JDBC statements and build SQL
package org.fluentjdbc;
/**
* Controls whether the current thread will commit or rollback operations to database. If
* {@link #setComplete()} is called, the transaction will be committed, unless {@link #setRollback()}
* is called afterwards. Default behavior is to rollback if nothing else is specified.
*
* Transactions can be nested. For example, if one operation rolls back, the whole context
* is rolled back:
*
* try (DbTransaction tx = dbContext.ensureTransaction()) {
* // ... some operations
* try (DbTransaction innerTx = dbContext.ensureTransaction()) {
* // ... some operations
* innerTx.setRollback();
* }
* tx.setComplete();
* }
* // Operations will be rolled back as the inner transaction was rolled back
*
*
*/
public interface DbTransaction extends AutoCloseable {
@Override
void close();
/**
* Specify that this transaction should be committed when {@link #close()} is called.
* Subsequent calls to {@link #setRollback()} will reset this behavior. If an inner
* transaction votes {@link #setRollback()}, the transaction will be rolled back
*/
void setComplete();
/**
* Specify that this transaction and outer transactions will be rolled back. This
* is the default behavior
*/
void setRollback();
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy