本文整理汇总了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());
}
示例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());
}
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
};
}
示例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);
}
示例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);
}
}
示例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);
}
示例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();
}
}