Ejemplo n.º 1
0
 /**
  * Simply check if there is an ongoing tx.
  *
  * <ul>
  *   <li>If there is one, this is a no-op and just passes the call up the chain.
  *   <li>If there isn't one and there is a batch in progress, resume the batch's tx, pass up, and
  *       finally suspend the batch's tx.
  *   <li>If there is no batch in progress, just pass the call up the chain.
  * </ul>
  */
 @Override
 protected Object handleDefault(InvocationContext ctx, VisitableCommand command) throws Throwable {
   Transaction tx;
   if (!ctx.isOriginLocal()) return invokeNextInterceptor(ctx, command);
   // if in a batch, attach tx
   if (transactionManager.getTransaction() == null
       && (tx = batchContainer.getBatchTransaction()) != null) {
     try {
       transactionManager.resume(tx);
       // If there's no ongoing tx then BatchingInterceptor creates one and then invokes next
       // interceptor,
       // so that all interceptors in the stack will be executed in a transactional context.
       // This is where a new context (TxInvocationContext) is created, as the existing context is
       // not transactional: NonTxInvocationContext.
       InvocationContext txContext = icc.createInvocationContext(true, -1);
       txContext.setFlags(ctx.getFlags());
       return invokeNextInterceptor(txContext, command);
     } finally {
       if (transactionManager.getTransaction() != null
           && batchContainer.isSuspendTxAfterInvocation()) transactionManager.suspend();
     }
   } else {
     return invokeNextInterceptor(ctx, command);
   }
 }
Ejemplo n.º 2
0
 public boolean startBatch() {
   if (!config.isInvocationBatchingEnabled()) {
     throw new ConfigurationException(
         "Invocation batching not enabled in current configuration!  Please use the <invocationBatching /> element.");
   }
   return batchContainer.startBatch();
 }
Ejemplo n.º 3
0
 public void endBatch(boolean successful) {
   if (!config.isInvocationBatchingEnabled()) {
     throw new ConfigurationException(
         "Invocation batching not enabled in current configuration!  Please use the <invocationBatching /> element.");
   }
   batchContainer.endBatch(successful);
 }
Ejemplo n.º 4
0
 private Transaction getOngoingTransaction() {
   try {
     Transaction transaction = null;
     if (transactionManager != null) {
       transaction = transactionManager.getTransaction();
       if (transaction == null && config.isInvocationBatchingEnabled()) {
         transaction = batchContainer.getBatchTransaction();
       }
     }
     return transaction;
   } catch (SystemException e) {
     throw new CacheException("Unable to get transaction", e);
   }
 }