Uploaded image for project: 'Cayenne'
  1. Cayenne
  2. CAY-1778

TransactionManager to simplify user-managed transactions

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 3.2.M1
    • None
    • None

    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.

      Attachments

        Activity

          People

            andrus Andrus Adamchik
            andrus Andrus Adamchik
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: