當前位置: 首頁>>代碼示例>>Java>>正文


Java InvalidTransactionException類代碼示例

本文整理匯總了Java中javax.transaction.InvalidTransactionException的典型用法代碼示例。如果您正苦於以下問題:Java InvalidTransactionException類的具體用法?Java InvalidTransactionException怎麽用?Java InvalidTransactionException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


InvalidTransactionException類屬於javax.transaction包,在下文中一共展示了InvalidTransactionException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: returnImmediatelyWhenReceivedRejectResponse

import javax.transaction.InvalidTransactionException; //導入依賴的package包/類
@Test
public void returnImmediatelyWhenReceivedRejectResponse() throws Throwable {
  MessageSender sender = mock(MessageSender.class);
  when(sender.send(any())).thenReturn(new AlphaResponse(true));

  TransactionAspect aspect = new TransactionAspect(sender, omegaContext);
  try {
    aspect.advise(joinPoint, compensable);
    expectFailing(InvalidTransactionException.class);
  } catch (InvalidTransactionException e) {
    System.out.println(e.getMessage());
    assertThat(e.getMessage().contains("Abort sub transaction"), is(true));
  }

  verify(sender, times(1)).send(any());
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-saga,代碼行數:17,代碼來源:TransactionAspectTest.java

示例2: canContinueWithTransaction

import javax.transaction.InvalidTransactionException; //導入依賴的package包/類
private static boolean canContinueWithTransaction(Transactional config, EntityTransaction transaction, Method m) {
    switch (config.value()) {
        case REQUIRED:
            return true;
        case MANDATORY:
            if (!transaction.isActive()) {
                throwTransactionalException(config.value(), m,
                        new TransactionRequiredException("called outside a transaction context"));
            }
            return false;
        case NEVER:
            if (transaction.isActive()) {
                throwTransactionalException(config.value(), m,
                        new InvalidTransactionException("called inside a transaction context"));
            }
            return false;
        case SUPPORTS:
            return false;
        case REQUIRES_NEW: // not fully supported
            return true;
        case NOT_SUPPORTED: // not fully supported
            return false;
        default:
            throw new UnsupportedOperationException("Unknown enum " + config.value());
    }
}
 
開發者ID:Tibor17,項目名稱:javaee-samples,代碼行數:27,代碼來源:BeanManager.java

示例3: resume

import javax.transaction.InvalidTransactionException; //導入依賴的package包/類
public void resume(final Transaction tx) throws InvalidTransactionException {
    if (tx == null) {
        throw new InvalidTransactionException("Transaction is null");
    }
    if (!(tx instanceof MyTransaction)) {
        throw new InvalidTransactionException("Unknown transaction type " + tx.getClass().getName());
    }
    final MyTransaction myTransaction = (MyTransaction) tx;

    if (threadTransaction.get() != null) {
        throw new IllegalStateException("A transaction is already active");
    }

    final int status = myTransaction.getStatus();
    if (status != Status.STATUS_ACTIVE && status != Status.STATUS_MARKED_ROLLBACK) {
        throw new InvalidTransactionException("Expected transaction to be STATUS_ACTIVE or STATUS_MARKED_ROLLBACK, but was " + status);
    }

    threadTransaction.set(myTransaction);
}
 
開發者ID:apache,項目名稱:tomee,代碼行數:21,代碼來源:PseudoTransactionService.java

示例4: resume

import javax.transaction.InvalidTransactionException; //導入依賴的package包/類
@Override
public void resume(Transaction transaction) throws InvalidTransactionException, IllegalStateException, SystemException {
    if (log.isDebugEnabled()) { log.debug("resuming " + transaction); }
    if (transaction == null)
        throw new InvalidTransactionException("resumed transaction cannot be null");
    if (!(transaction instanceof BitronixTransaction))
        throw new InvalidTransactionException("resumed transaction must be an instance of BitronixTransaction");

    BitronixTransaction tx = (BitronixTransaction) transaction;
    if (getCurrentTransaction() != null)
        throw new IllegalStateException("a transaction is already running on this thread");

    try {
        XAResourceManager resourceManager = tx.getResourceManager();
        resourceManager.resume();
        ThreadContext threadContext = ThreadContext.getThreadContext();
        threadContext.setTransaction(tx);
        inFlightTransactions.get(tx).setThreadContext(threadContext);
        MDC.put(MDC_GTRID_KEY, tx.getGtrid());
    } catch (XAException ex) {
        String extraErrorDetails = TransactionManagerServices.getExceptionAnalyzer().extractExtraXAExceptionDetails(ex);
        throw new BitronixSystemException("cannot resume " + tx + ", error=" + Decoder.decodeXAExceptionErrorCode(ex) +
                (extraErrorDetails == null ? "" : ", extra error=" + extraErrorDetails), ex);
    }
}
 
開發者ID:bitronix,項目名稱:btm,代碼行數:26,代碼來源:BitronixTransactionManager.java

示例5: advise

import javax.transaction.InvalidTransactionException; //導入依賴的package包/類
@Around("execution(@org.apache.servicecomb.saga.omega.transaction.annotations.Compensable * *(..)) && @annotation(compensable)")
Object advise(ProceedingJoinPoint joinPoint, Compensable compensable) throws Throwable {
  Method method = ((MethodSignature) joinPoint.getSignature()).getMethod();
  LOG.debug("Intercepting compensable method {} with context {}", method.toString(), context);

  String signature = compensationMethodSignature(joinPoint, compensable, method);

  String localTxId = context.localTxId();
  context.newLocalTxId();

  TimeAwareInterceptor interceptor = new TimeAwareInterceptor(this.interceptor);
  AlphaResponse response = interceptor.preIntercept(localTxId, signature, joinPoint.getArgs());
  if (response.aborted()) {
    String abortedLocalTxId = context.localTxId();
    context.setLocalTxId(localTxId);
    throw new InvalidTransactionException("Abort sub transaction " + abortedLocalTxId +
        " because global transaction " + context.globalTxId() + " has already aborted.");
  }
  LOG.debug("Updated context {} for compensable method {} ", context, method.toString());

  scheduleTimeoutTask(interceptor, localTxId, signature, method, compensable.timeout());

  try {
    Object result = joinPoint.proceed();
    interceptor.postIntercept(localTxId, signature);

    return result;
  } catch (Throwable throwable) {
    interceptor.onError(localTxId, signature, throwable);
    throw throwable;
  } finally {
    context.setLocalTxId(localTxId);
    LOG.debug("Restored context back to {}", context);
  }
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-saga,代碼行數:36,代碼來源:TransactionAspect.java

示例6: resume

import javax.transaction.InvalidTransactionException; //導入依賴的package包/類
public void resume(Transaction tx) throws InvalidTransactionException, IllegalStateException, SystemException
{
    if (!(tx instanceof SimpleTransaction))
    {
        throw new IllegalStateException("Transaction must be a SimpleTransaction to resume");
    }
    SimpleTransaction.resume((SimpleTransaction) tx);
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:9,代碼來源:SimpleTransactionManager.java

示例7: doJtaResume

import javax.transaction.InvalidTransactionException; //導入依賴的package包/類
/**
 * Perform a JTA resume on the JTA TransactionManager.
 * <p>Can be overridden in subclasses, for specific JTA implementations.
 * @param txObject the JtaTransactionObject containing the UserTransaction
 * @param suspendedTransaction the suspended JTA Transaction object
 * @throws InvalidTransactionException if thrown by JTA methods
 * @throws SystemException if thrown by JTA methods
 * @see #getTransactionManager()
 * @see javax.transaction.TransactionManager#resume(javax.transaction.Transaction)
 */
protected void doJtaResume(JtaTransactionObject txObject, Object suspendedTransaction)
	throws InvalidTransactionException, SystemException {

	if (getTransactionManager() == null) {
		throw new TransactionSuspensionNotSupportedException(
				"JtaTransactionManager needs a JTA TransactionManager for suspending a transaction: " +
				"specify the 'transactionManager' or 'transactionManagerName' property");
	}
	getTransactionManager().resume((Transaction) suspendedTransaction);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:21,代碼來源:JtaTransactionManager.java

示例8: test1

import javax.transaction.InvalidTransactionException; //導入依賴的package包/類
/**
 * Create InvalidTransactionException with no-arg constructor
 */
@Test
public void test1() {
    InvalidTransactionException ex = new InvalidTransactionException();
    assertTrue(ex.getMessage() == null
            && ex.getCause() == null);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:10,代碼來源:InvalidTransactionExceptionTests.java

示例9: test2

import javax.transaction.InvalidTransactionException; //導入依賴的package包/類
/**
 * Create InvalidTransactionException with message
 */
@Test
public void test2() {
    InvalidTransactionException ex = new InvalidTransactionException(reason);
    assertTrue(ex.getMessage().equals(reason)
            && ex.getCause() == null);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:10,代碼來源:InvalidTransactionExceptionTests.java

示例10: test3

import javax.transaction.InvalidTransactionException; //導入依賴的package包/類
/**
 * De-Serialize a InvalidTransactionException from JDBC 4.0 and make sure
 * you can read it back properly
 */
@Test
public void test3() throws Exception {

    ObjectInputStream ois = new ObjectInputStream(
            new ByteArrayInputStream(SerializedTransactionExceptions.ITE_DATA));
    InvalidTransactionException ex = (InvalidTransactionException) ois.readObject();
    assertTrue(reason.equals(ex.getMessage())
            && ex.getCause() == null);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:14,代碼來源:InvalidTransactionExceptionTests.java

示例11: getTransactionManager

import javax.transaction.InvalidTransactionException; //導入依賴的package包/類
public TransactionManager getTransactionManager() {
    return new TransactionManager() {
        public void begin() throws NotSupportedException, SystemException {
        }

        public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException {
        }

        public int getStatus() throws SystemException {
            return TransactionUtil.STATUS_NO_TRANSACTION;
        }

        public Transaction getTransaction() throws SystemException {
            return null;
        }

        public void resume(Transaction transaction) throws InvalidTransactionException, IllegalStateException, SystemException {
        }

        public void rollback() throws IllegalStateException, SecurityException, SystemException {
        }

        public void setRollbackOnly() throws IllegalStateException, SystemException {
        }

        public void setTransactionTimeout(int i) throws SystemException {
        }

        public Transaction suspend() throws SystemException {
            return null;
        }
    };
}
 
開發者ID:ilscipio,項目名稱:scipio-erp,代碼行數:34,代碼來源:DumbTransactionFactory.java

示例12: resume

import javax.transaction.InvalidTransactionException; //導入依賴的package包/類
public void resume(final Transaction resumeTx) throws InvalidTransactionException, IllegalStateException, SystemException {
    final ExtendedTransaction tx = getCurrent();
    if (tx != null) {
        throw new LjtIllegalStateException("Already assigned the other transaction for resume().");
    }
    ((ExtendedTransaction) resumeTx).resume();
    setCurrent((ExtendedTransaction) resumeTx);
}
 
開發者ID:lastaflute,項目名稱:lasta-di,代碼行數:9,代碼來源:AbstractTransactionManager.java

示例13: suspendTransactionAndExecute

import javax.transaction.InvalidTransactionException; //導入依賴的package包/類
private <T> T suspendTransactionAndExecute(Supplier<T> supplier) {
    Transaction old;
    try {
        old = txm.suspend();
        try {
            return supplier.get();
        } finally {
            txm.resume(old);
        }
    } catch (InvalidTransactionException | IllegalStateException | SystemException e) {
        throw new TransactionException("Error while suspending and resuming transaction", e);
    }
}
 
開發者ID:ruediste,項目名稱:rise,代碼行數:14,代碼來源:TransactionControl.java

示例14: resume

import javax.transaction.InvalidTransactionException; //導入依賴的package包/類
@Override
public void resume(Transaction tx) throws InvalidTransactionException, IllegalStateException {
    if (getTransaction() != null) {
        throw new IllegalStateException("Transaction is already associated");
    }
    if (!(tx instanceof TransactionImpl)) {
        throw new InvalidTransactionException("Foreign transaction: " + tx);
    }
    TRANSACTIONS.set((TransactionImpl) tx);
}
 
開發者ID:odnoklassniki,項目名稱:one-datasource,代碼行數:11,代碼來源:TransactionManagerImpl.java

示例15: resume

import javax.transaction.InvalidTransactionException; //導入依賴的package包/類
public void resume(Transaction tx) throws IllegalStateException, InvalidTransactionException, SystemException {
	if (TransactionImpl.class.isInstance(tx)) {
		TransactionImpl transaction = (TransactionImpl) tx;
		transaction.resumeAllResource();
		AssociatedContext bctx = new AssociatedContext();
		bctx.setThread(Thread.currentThread());
		this.threadToTxnMap.put(Thread.currentThread(), bctx);
	} else {
		throw new InvalidTransactionException();
	}
}
 
開發者ID:yangting,項目名稱:openjtcc,代碼行數:12,代碼來源:TransactionManagerImpl.java


注:本文中的javax.transaction.InvalidTransactionException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。