Example #1
0
 /**
  * Returns total number of transactions of the specified status associated with current thread.
  */
 public int totalThreadTransactionsWithStatus(JtxStatus status) {
   ArrayList<JtxTransaction> txlist = txStack.get();
   if (txlist == null) {
     return 0;
   }
   int count = 0;
   for (JtxTransaction tx : txlist) {
     if (tx.getStatus() == status) {
       count++;
     }
   }
   return count;
 }
Example #2
0
 /**
  * Returns <code>true</code> if scope is specified and it is different then of existing
  * transaction.
  */
 protected boolean isNewTxScope(JtxTransaction currentTx, Object destScope) {
   if (ignoreScope == true) {
     return true;
   }
   if (currentTx == null) {
     return true;
   }
   if (destScope == null) {
     return true;
   }
   if (currentTx.getScope() == null) {
     return true;
   }
   return !destScope.equals(currentTx.getScope());
 }
Example #3
0
 /**
  * Propagation: MANDATORY
  *
  * <pre>{@code
  * None -> Error
  * T1   -> T1 (cont.)
  * }</pre>
  */
 @SuppressWarnings({"UnusedDeclaration"})
 protected JtxTransaction propMandatory(
     JtxTransaction currentTx, JtxTransactionMode mode, Object scope) {
   if ((currentTx == null) || (currentTx.isNoTransaction() == true)) {
     throw new JtxException("No existing TX found for TX marked with propagation 'mandatory'");
   }
   continueTx(currentTx, mode);
   return currentTx;
 }
Example #4
0
 /**
  * Propagation: REQUIRED
  *
  * <pre>{@code
  * None -> T2
  * T1   -> T1 (cont.)
  * }</pre>
  */
 protected JtxTransaction propRequired(
     JtxTransaction currentTx, JtxTransactionMode mode, Object scope) {
   if ((currentTx == null) || (currentTx.isNoTransaction() == true)) {
     currentTx = createNewTransaction(mode, scope, true);
   } else {
     continueTx(currentTx, mode);
   }
   return currentTx;
 }
Example #5
0
 /**
  * Propagation: NEVER
  *
  * <pre>{@code
  * None -> None
  * T1   -> Error
  * }</pre>
  */
 protected JtxTransaction propNever(
     JtxTransaction currentTx, JtxTransactionMode mode, Object scope) {
   if ((currentTx != null) && (currentTx.isNoTransaction() == false)) {
     throw new JtxException("Existing TX found for TX marked with propagation 'never'");
   }
   if (currentTx == null) {
     currentTx = createNewTransaction(mode, scope, false);
   }
   return currentTx;
 }
Example #6
0
 /**
  * Propagation: NOT_SUPPORTED
  *
  * <pre>{@code
  * None -> None
  * T1   -> None
  * }</pre>
  */
 protected JtxTransaction propNotSupported(
     JtxTransaction currentTx, JtxTransactionMode mode, Object scope) {
   if (currentTx == null) {
     return createNewTransaction(mode, scope, false);
   }
   if (currentTx.isNoTransaction() == true) {
     return currentTx;
   }
   return createNewTransaction(mode, scope, false);
 }
Example #7
0
 /**
  * Propagation: SUPPORTS
  *
  * <pre>{@code
  * None -> None
  * T1   -> T1 (cont.)
  * }</pre>
  */
 protected JtxTransaction propSupports(
     JtxTransaction currentTx, JtxTransactionMode mode, Object scope) {
   if ((currentTx != null) && (currentTx.isNoTransaction() != true)) {
     continueTx(currentTx, mode);
   }
   if (currentTx == null) {
     currentTx = createNewTransaction(mode, scope, false);
   }
   return currentTx;
 }
Example #8
0
 /**
  * Check if propagation of a transaction is possible, due to source and destination transaction
  * modes.
  *
  * @see #setValidateExistingTransaction(boolean)
  */
 protected void continueTx(JtxTransaction sourceTx, JtxTransactionMode destMode) {
   if (validateExistingTransaction == false) {
     return;
   }
   JtxTransactionMode sourceMode = sourceTx.getTransactionMode();
   JtxIsolationLevel destIsolationLevel = destMode.getIsolationLevel();
   if (destIsolationLevel != ISOLATION_DEFAULT) {
     JtxIsolationLevel currentIsolationLevel = sourceMode.getIsolationLevel();
     if (currentIsolationLevel != destIsolationLevel) {
       throw new JtxException(
           "Participating TX specifies isolation level: "
               + destIsolationLevel
               + " which is incompatible with existing TX: "
               + currentIsolationLevel);
     }
   }
   if ((destMode.isReadOnly() == false) && (sourceMode.isReadOnly())) {
     throw new JtxException("Participating TX is not marked as read-only, but existing TX is");
   }
 }