Uploaded image for project: 'Infinispan'
  1. Infinispan
  2. ISPN-13667

Create a utility method to deal with cache operations during a transaction

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Unresolved
    • Major
    • None
    • 14.0.0.Final
    • Transactions
    • None

    Description

      Create a utility method to deal with cache operations during a transaction

      Pseudo code

          void doInTx(Runnable runnable, int maxAttempts) {
              TransactionManager tm = myCache.cache.getAdvancedCache().getTransactionManager();
              boolean success = false;
              int count = 0;
              while (!success && count < maxAttempts) {
                  boolean rollbackCalled = false;
                  try {
                      tm.begin();
                      runnable.run();
                  } catch (Exception e) {
                      rollbackCalled = true;
                      tm.rollback();
                  } finally {
                      count++;
                      if (!rollbackCalled) {
                          tm.commit();
                          success = true;
                      }
                  }
              }
              if (!success) {
                  throw new IllegalStateException("cannot do the operation");
              }
          }
      

      Attachments

        Activity

          People

            pruivo@redhat.com Pedro Ruivo
            dlovison@redhat.com Diego Lovison
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: