|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.j256.ormlite.misc.TransactionManager
public class TransactionManager
Provides basic transaction support for a ConnectionSource.
NOTE: For transactions to work, the database being used must support the functionality.
NOTE: If you are using the Spring type wiring in Java, initialize() should be called after all of the
set methods. In Spring XML, init-method="initialize" should be used.
You can call this as an instance with a new TransactionManager(dataSource); or you can call it as a static like the below example:
TransactionManager.callInTransaction(dataSource, new Callable<Void>() {
public Void call() throws Exception {
// delete both objects but make sure that if either one fails, the transaction is rolled back
// and both objects are "restored" to the database
fooDao.delete(foo);
barDao.delete(bar);
return null;
}
});
For Spring wiring of a Transaction Manager bean, we would do something like the following:
<bean id="transactionManager" class="com.j256.ormlite.misc.TransactionManager" init-method="initialize">
<property name="dataSource" ref="dataSource" />
</bean>
| Constructor Summary | |
|---|---|
TransactionManager()
Constructor for Spring type wiring if you are using the set methods. |
|
TransactionManager(ConnectionSource connectionSource)
Constructor for direct java code wiring. |
|
| Method Summary | ||
|---|---|---|
|
callInTransaction(Callable<T> callable)
Execute the Callable class inside of a transaction. |
|
static
|
callInTransaction(ConnectionSource connectionSource,
Callable<T> callable)
Same as callInTransaction(Callable) except as a static method with a connection source. |
|
static
|
callInTransaction(DatabaseConnection connection,
boolean saved,
DatabaseType databaseType,
Callable<T> callable)
Same as callInTransaction(Callable) except as a static method on a connection. |
|
static
|
callInTransaction(DatabaseConnection connection,
DatabaseType databaseType,
Callable<T> callable)
Same as callInTransaction(Callable) except as a static method on a connection. |
|
void |
initialize()
If you are using the Spring type wiring, this should be called after all of the set methods. |
|
void |
setConnectionSource(ConnectionSource connectionSource)
|
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public TransactionManager()
public TransactionManager(ConnectionSource connectionSource)
| Method Detail |
|---|
public void initialize()
public <T> T callInTransaction(Callable<T> callable)
throws SQLException
Callable class inside of a transaction. If the callable returns then the transaction is
committed. If the callable throws an exception then the transaction is rolled back and a SQLException is
thrown by this method.
NOTE: If your callable block really doesn't have a return object then use the Void class and return null from the call method.
callable - Callable to execute inside of the transaction.
SQLException - If the callable threw an exception then the transaction is rolled back and a SQLException wraps the
callable exception and is thrown by this method.
public static <T> T callInTransaction(ConnectionSource connectionSource,
Callable<T> callable)
throws SQLException
callInTransaction(Callable) except as a static method with a connection source.
SQLException
public static <T> T callInTransaction(DatabaseConnection connection,
DatabaseType databaseType,
Callable<T> callable)
throws SQLException
callInTransaction(Callable) except as a static method on a connection.
SQLException
public static <T> T callInTransaction(DatabaseConnection connection,
boolean saved,
DatabaseType databaseType,
Callable<T> callable)
throws SQLException
callInTransaction(Callable) except as a static method on a connection.
SQLExceptionpublic void setConnectionSource(ConnectionSource connectionSource)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||