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

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

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Won't Do
    • Icon: Major Major
    • None
    • 14.0.0.Final
    • Transactions
    • None

      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");
              }
          }
      

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

                Created:
                Updated:
                Resolved: