[
https://issues.apache.org/jira/browse/CAY-1778?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Andrus Adamchik updated CAY-1778:
---------------------------------
Description:
Getting the semantics of manual transactions right is really hard:
http://cayenne.apache.org/docs/3.0/understanding-transactions.html We need
something more straightforward and DI based. Proposing the following:
public interface TransactionManager {
/**
* Starts a new transaction (or joins an existing one) calling
* {@link TransactionalOperation#perform(CayenneRuntime)}, and then
* committing or rolling back the transaction. Frees the user
*/
<T> T performInTransaction(TransactionalOperation<T> op);
}
public interface TransactionalOperation<T> {
/**
* A callback method that {@link TransactionManager} invokes,
* {@link TransactionManager} will wrap this method call in a single
* thread-bound transaction.
*/
T perform(CayenneRuntime runtime);
}
So a custom block of code to run in TX may look like this:
runtime.getTransactionManager().performInTransaction(new
TransactionalOperation<SomeType>() {
SomeType perform(CayenneRuntime runtime) {
// do something
}
});
or maybe even:
runtime.performInTransaction(new TransactionalOperation<SomeType>() {
SomeType perform(CayenneRuntime runtime) {
// do something
}
});
Later we may even use TransactionManager API for internal tx's to achieve
uniformity. I can also see the evolution of the current Transaction API
(including static bind methods) to gradually move under TransactionManager
methods.
was:
Getting the semantics of manual transactions right is really hard:
http://cayenne.apache.org/docs/3.0/understanding-transactions.html We need
something more straightforward and DI based. Proposing the following:
public interface TransactionManager {
/**
* Starts a new transaction (or joins an existing one) calling
* {@link TransactionalOperation#perform(CayenneRuntime)}, and then
* committing or rolling back the transaction. Frees the user
*/
<T> T performInTransaction(TransactionalOperation<T> op);
}
public interface TransactionalOperation<T> {
/**
* A callback method that {@link TransactionManager} invokes,
* {@link TransactionManager} will wrap this method call in a single
* thread-bound transaction.
*/
T perform(CayenneRuntime runtime);
}
So a custom block of code to run in TX may look like this:
runtime.getTransactionManager().performInTransaction(new
TransactionalOperation<SomeType>() {
SomeType perform(CayenneRuntime runtime) {
// do something
}
});
or maybe even:
runtime.performInTransaction(new TransactionalOperation<SomeType>() {
SomeType perform(CayenneRuntime runtime) {
// do something
}
});
Later we may even use TransactionManager API for internal tx's to achieve
uniformity.
> TransactionManager to simplify user-managed transactions
> --------------------------------------------------------
>
> Key: CAY-1778
> URL: https://issues.apache.org/jira/browse/CAY-1778
> Project: Cayenne
> Issue Type: Bug
> Reporter: Andrus Adamchik
> Assignee: Andrus Adamchik
> Fix For: 3.2M1
>
>
> Getting the semantics of manual transactions right is really hard:
> http://cayenne.apache.org/docs/3.0/understanding-transactions.html We need
> something more straightforward and DI based. Proposing the following:
> public interface TransactionManager {
> /**
> * Starts a new transaction (or joins an existing one) calling
> * {@link TransactionalOperation#perform(CayenneRuntime)}, and then
> * committing or rolling back the transaction. Frees the user
> */
> <T> T performInTransaction(TransactionalOperation<T> op);
> }
> public interface TransactionalOperation<T> {
> /**
> * A callback method that {@link TransactionManager} invokes,
> * {@link TransactionManager} will wrap this method call in a single
> * thread-bound transaction.
> */
> T perform(CayenneRuntime runtime);
> }
> So a custom block of code to run in TX may look like this:
> runtime.getTransactionManager().performInTransaction(new
> TransactionalOperation<SomeType>() {
> SomeType perform(CayenneRuntime runtime) {
> // do something
> }
> });
> or maybe even:
> runtime.performInTransaction(new TransactionalOperation<SomeType>() {
> SomeType perform(CayenneRuntime runtime) {
> // do something
> }
> });
> Later we may even use TransactionManager API for internal tx's to achieve
> uniformity. I can also see the evolution of the current Transaction API
> (including static bind methods) to gradually move under TransactionManager
> methods.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira