当前位置: 首页>>代码示例>>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;未经允许,请勿转载。