public Transaction suspend() throws SystemException { Transaction tx = getTransaction(); if (tx != null) { unassociate(); } return tx; }
public void resume(Transaction tx) throws IllegalStateException, InvalidTransactionException, SystemException { if (getTransaction() != null && tx != getTransaction()) { throw new IllegalStateException("Thread already associated with another transaction"); } if (tx != null && tx != getTransaction()) { if (!(tx instanceof TransactionImpl)) { throw new InvalidTransactionException("Cannot resume foreign transaction: " + tx); } associate((TransactionImpl) tx); } }
public void begin() throws NotSupportedException, SystemException { begin(getTransactionTimeoutMilliseconds(0L)); }
public Transaction begin(long transactionTimeoutMilliseconds) throws NotSupportedException, SystemException { if (getStatus() != Status.STATUS_NO_TRANSACTION) { throw new NotSupportedException("Nested Transactions are not supported"); } TransactionImpl tx = new TransactionImpl(xidFactory, transactionLog, getTransactionTimeoutMilliseconds(transactionTimeoutMilliseconds)); // timeoutTimer.schedule(tx, getTransactionTimeoutMilliseconds(transactionTimeoutMilliseconds)); try { associate(tx); } catch (InvalidTransactionException e) { // should not be possible since we just created that transaction and no one has a reference yet throw (SystemException)new SystemException("Internal error: associate threw an InvalidTransactionException for a newly created transaction").initCause(e); } // Todo: Verify if this is correct thing to do. Use default timeout for next transaction. this.transactionTimeoutMilliseconds.set(null); return tx; }
private void unassociate() { Transaction tx = getTransaction(); if (tx != null) { associatedTransactions.remove(tx); threadTx.set(null); fireThreadUnassociated(tx); activeCount.getAndDecrement(); } }
public int getStatus() throws SystemException { Transaction tx = getTransaction(); return (tx != null) ? tx.getStatus() : Status.STATUS_NO_TRANSACTION; }
/** * jta 1.1 method so the jpa implementations can be told to flush their caches. * @param synchronization */ public void registerInterposedSynchronization(Synchronization synchronization) { TransactionImpl tx = getActiveTransactionImpl(); tx.registerInterposedSynchronization(synchronization); }
private EntityManager getEntityManager(boolean activeRequired) { TransactionImpl transaction = (TransactionImpl) transactionManager.getTransaction(); if (activeRequired && (transaction == null || transaction.getStatus() != Status.STATUS_ACTIVE)) { throw new TransactionRequiredException("No active transaction"); } if (transaction == null) { return null; } EntityManagerWrapper entityManagerWrapper = (EntityManagerWrapper) transactionManager.getResource(persistenceUnit); if (entityManagerWrapper == null) { EntityManager entityManager = createEntityManager(); entityManagerWrapper = new EntityManagerWrapperTxScoped(entityManager); transactionManager.putResource(persistenceUnit, entityManagerWrapper); try { transaction.registerSynchronization(entityManagerWrapper); } catch (javax.transaction.RollbackException e) { throw (TransactionRequiredException) new TransactionRequiredException("No active transaction").initCause(e); } catch (SystemException e) { throw (TransactionRequiredException) new TransactionRequiredException("No active transaction").initCause(e); } } return entityManagerWrapper.getEntityManager(); }
public Transaction importXid(Xid xid, long transactionTimeoutMilliseconds) throws XAException, SystemException { if (transactionTimeoutMilliseconds < 0) { throw new SystemException("transaction timeout must be positive or 0 to reset to default"); } return new TransactionImpl(xid, this, getTransactionTimeoutMilliseconds(transactionTimeoutMilliseconds)); }
private void associate(TransactionImpl tx) throws InvalidTransactionException { if (tx == null) throw new NullPointerException("tx is null"); Object existingAssociation = associatedTransactions.putIfAbsent(tx, Thread.currentThread()); if (existingAssociation != null) { throw new InvalidTransactionException("Specified transaction is already associated with another thread"); } threadTx.set(tx); fireThreadAssociated(tx); activeCount.getAndIncrement(); }
public void recoverResourceManager(NamedXAResource xaResource) { try { recovery.recoverResourceManager(xaResource); } catch (XAException e) { recoveryError(e); } }
public Transaction begin(long transactionTimeoutMilliseconds) throws NotSupportedException, SystemException { if (getStatus() != Status.STATUS_NO_TRANSACTION) { throw new NotSupportedException("Nested Transactions are not supported"); } TransactionImpl tx = new TransactionImpl(this, getTransactionTimeoutMilliseconds(transactionTimeoutMilliseconds)); // timeoutTimer.schedule(tx, getTransactionTimeoutMilliseconds(transactionTimeoutMilliseconds)); try { associate(tx); } catch (InvalidTransactionException e) { // should not be possible since we just created that transaction and no one has a reference yet throw (SystemException)new SystemException("Internal error: associate threw an InvalidTransactionException for a newly created transaction").initCause(e); } // Todo: Verify if this is correct thing to do. Use default timeout for next transaction. this.transactionTimeoutMilliseconds.set(null); return tx; }
private void unassociate() { Transaction tx = getTransaction(); if (tx != null) { associatedTransactions.remove(tx); threadTx.set(null); fireThreadUnassociated(tx); activeCount.getAndDecrement(); } }
public int getTransactionStatus() { TransactionImpl tx = (TransactionImpl) getTransaction(); return tx == null? Status.STATUS_NO_TRANSACTION: tx.getTransactionStatus(); }
public boolean getRollbackOnly() { TransactionImpl tx = getActiveTransactionImpl(); return tx.getRollbackOnly(); }
public Transaction importXid(Xid xid, long transactionTimeoutMilliseconds) throws XAException, SystemException { if (transactionTimeoutMilliseconds < 0) { throw new SystemException("transaction timeout must be positive or 0 to reset to default"); } TransactionImpl tx = new TransactionImpl(xid, xidFactory, transactionLog, getTransactionTimeoutMilliseconds(transactionTimeoutMilliseconds)); return tx; }
private void associate(TransactionImpl tx) throws InvalidTransactionException { if (tx.getStatus() == Status.STATUS_NO_TRANSACTION) { throw new InvalidTransactionException("Cannot resume invalid transaction: " + tx); } else { Object existingAssociation = associatedTransactions.putIfAbsent(tx, Thread.currentThread()); if (existingAssociation != null) { throw new InvalidTransactionException("Specified transaction is already associated with another thread"); } threadTx.set(tx); fireThreadAssociated(tx); activeCount.getAndIncrement(); } }
public void recoverResourceManager(NamedXAResource xaResource) { try { recovery.recoverResourceManager(xaResource); } catch (XAException e) { recoveryError(e); } }
public Transaction suspend() throws SystemException { Transaction tx = getTransaction(); if (tx != null) { unassociate(); } return tx; }
public Transaction begin(long transactionTimeoutMilliseconds) throws NotSupportedException, SystemException { if (getStatus() != Status.STATUS_NO_TRANSACTION) { throw new NotSupportedException("Nested Transactions are not supported"); } TransactionImpl tx = new TransactionImpl(xidFactory, transactionLog, getTransactionTimeoutMilliseconds(transactionTimeoutMilliseconds)); // timeoutTimer.schedule(tx, getTransactionTimeoutMilliseconds(transactionTimeoutMilliseconds)); try { associate(tx); } catch (InvalidTransactionException e) { // should not be possible since we just created that transaction and no one has a reference yet throw (SystemException)new SystemException("Internal error: associate threw an InvalidTransactionException for a newly created transaction").initCause(e); } // Todo: Verify if this is correct thing to do. Use default timeout for next transaction. this.transactionTimeoutMilliseconds.set(null); return tx; }