本文整理汇总了Java中bitronix.tm.BitronixTransaction类的典型用法代码示例。如果您正苦于以下问题:Java BitronixTransaction类的具体用法?Java BitronixTransaction怎么用?Java BitronixTransaction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BitronixTransaction类属于bitronix.tm包,在下文中一共展示了BitronixTransaction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSession
import bitronix.tm.BitronixTransaction; //导入依赖的package包/类
public Session getSession(boolean forceXa) throws JMSException {
if (getState() == State.CLOSED)
throw new IllegalStateException("session handle is closed");
if (forceXa) {
if (log.isDebugEnabled()) { log.debug("choosing XA session (forced)"); }
return createXASession();
}
else {
BitronixTransaction currentTransaction = TransactionContextHelper.currentTransaction();
if (currentTransaction != null) {
if (log.isDebugEnabled()) { log.debug("choosing XA session"); }
return createXASession();
}
if (log.isDebugEnabled()) { log.debug("choosing non-XA session"); }
return createNonXASession();
}
}
示例2: getNotAccessible
import bitronix.tm.BitronixTransaction; //导入依赖的package包/类
/**
* Get a XAStatefulHolder (connection) from the NOT_ACCESSIBLE pool. This method obtains
* the stateTransitionLock.readLock() which prevents any modification during iteration, but
* allows multiple threads to iterate simultaneously.
*
* @return a connection, or null if there are no connections in the inaccessible pool for the current transaction
*/
private T getNotAccessible() {
if (log.isDebugEnabled()) { log.debug("trying to recycle a NOT_ACCESSIBLE connection of " + this); }
BitronixTransaction transaction = TransactionContextHelper.currentTransaction();
if (transaction == null) {
if (log.isDebugEnabled()) { log.debug("no current transaction, no connection can be in state NOT_ACCESSIBLE when there is no global transaction context"); }
return null;
}
Uid currentTxGtrid = transaction.getResourceManager().getGtrid();
if (log.isDebugEnabled()) { log.debug("current transaction GTRID is [" + currentTxGtrid + "]"); }
stateTransitionLock.readLock().lock();
try {
for (T xaStatefulHolder : inaccessiblePool) {
if (log.isDebugEnabled()) { log.debug("found a connection in NOT_ACCESSIBLE state: " + xaStatefulHolder); }
if (containsXAResourceHolderMatchingGtrid(xaStatefulHolder, currentTxGtrid))
return xaStatefulHolder;
}
if (log.isDebugEnabled()) { log.debug("no NOT_ACCESSIBLE connection enlisted in this transaction"); }
return null;
}
finally {
stateTransitionLock.readLock().unlock();
}
}
示例3: getSharedXAStatefulHolder
import bitronix.tm.BitronixTransaction; //导入依赖的package包/类
/**
* Try to get a shared XAStatefulHolder. This method will either return a shared
* XAStatefulHolder or <code>null</code>. If there is no current transaction,
* XAStatefulHolder's are not shared. If there is a transaction <i>and</i> there is
* a XAStatefulHolder associated with this thread already, we return that XAStatefulHolder
* (provided it is ACCESSIBLE or NOT_ACCESSIBLE).
*
* @return a shared XAStatefulHolder or <code>null</code>
*/
private T getSharedXAStatefulHolder() {
BitronixTransaction transaction = TransactionContextHelper.currentTransaction();
if (transaction == null) {
if (log.isDebugEnabled()) { log.debug("no current transaction, shared connection map will not be used"); }
return null;
}
Uid currentTxGtrid = transaction.getResourceManager().getGtrid();
StatefulHolderThreadLocal<T> threadLocal = statefulHolderTransactionMap.get(currentTxGtrid);
if (threadLocal != null) {
T xaStatefulHolder = threadLocal.get();
// Additional sanity checks...
if (xaStatefulHolder != null &&
xaStatefulHolder.getState() != State.IN_POOL &&
xaStatefulHolder.getState() != State.CLOSED) {
if (log.isDebugEnabled()) { log.debug("sharing connection " + xaStatefulHolder + " in transaction " + currentTxGtrid); }
return xaStatefulHolder;
}
}
return null;
}
示例4: getLatestAlreadyEnlistedXAResourceHolderState
import bitronix.tm.BitronixTransaction; //导入依赖的package包/类
private static XAResourceHolderState getLatestAlreadyEnlistedXAResourceHolderState(XAResourceHolder xaResourceHolder, final BitronixTransaction currentTransaction) {
if (currentTransaction == null)
return null;
class LocalVisitor implements XAResourceHolderStateVisitor {
private XAResourceHolderState latestEnlistedHolder;
@Override
public boolean visit(XAResourceHolderState xaResourceHolderState) {
if (xaResourceHolderState != null && xaResourceHolderState.getXid() != null) {
BitronixXid bitronixXid = xaResourceHolderState.getXid();
Uid resourceGtrid = bitronixXid.getGlobalTransactionIdUid();
Uid currentTransactionGtrid = currentTransaction.getResourceManager().getGtrid();
if (currentTransactionGtrid.equals(resourceGtrid)) {
latestEnlistedHolder = xaResourceHolderState;
}
}
return true; // continue visitation
}
}
LocalVisitor xaResourceHolderStateVisitor = new LocalVisitor();
xaResourceHolder.acceptVisitorForXAResourceHolderStates(currentTransaction.getResourceManager().getGtrid(), xaResourceHolderStateVisitor);
return xaResourceHolderStateVisitor.latestEnlistedHolder;
}
示例5: isParticipatingInActiveGlobalTransaction
import bitronix.tm.BitronixTransaction; //导入依赖的package包/类
/**
* If this method returns false, then local transaction calls like Connection.commit() can be made.
* @return true if start() has been successfully called but not end() yet <i>and</i> the transaction is not suspended.
*/
public boolean isParticipatingInActiveGlobalTransaction() {
rwLock.readLock().lock();
try {
BitronixTransaction currentTransaction = TransactionContextHelper.currentTransaction();
Uid gtrid = currentTransaction == null ? null : currentTransaction.getResourceManager().getGtrid();
if (gtrid == null)
return false;
Map<Uid, XAResourceHolderState> statesForGtrid = xaResourceHolderStates.get(gtrid);
if (statesForGtrid == null)
return false;
for (XAResourceHolderState xaResourceHolderState : statesForGtrid.values()) {
if (xaResourceHolderState != null &&
xaResourceHolderState.isStarted() &&
!xaResourceHolderState.isSuspended() &&
!xaResourceHolderState.isEnded())
return true;
}
return false;
}
finally {
rwLock.readLock().unlock();
}
}
示例6: invoke
import bitronix.tm.BitronixTransaction; //导入依赖的package包/类
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
Object result = null;
String methodName = method.getName();
logger.trace(methodName);
if( "commit".equals(methodName) && args == null) {
BitronixTransaction bt = ((BitronixTransactionManager) ut).getCurrentTransaction();
// Ensure that all actions have occurred so that we get what is _really_ commited to the db
// (This code is straight from bitronix)
Iterator<?> iter = bt.getSynchronizationScheduler().reverseIterator();
while (iter.hasNext()) {
Synchronization synchronization = (Synchronization) iter.next();
try {
synchronization.beforeCompletion();
} catch (RuntimeException ex) {
bt.setStatus(Status.STATUS_MARKED_ROLLBACK);
throw ex;
}
}
String testMethodName = MarshallingTestUtil.getTestMethodName();
if( testMethodName != null ) {
EntityManager em = emf.createEntityManager();
Set<MarshalledData> newMarshalledData = objectSpecificMarshallingActions.updateManagedObjects(testMethodName);
for( MarshalledData marshalledData : newMarshalledData ) {
em.persist(marshalledData);
}
em.close();
}
ut.commit();
return result;
}
else {
result = invoke(method, ut, args);
}
return result;
}
示例7: putSharedXAStatefulHolder
import bitronix.tm.BitronixTransaction; //导入依赖的package包/类
/**
* Try to share a XAStatefulHolder with other callers on this thread. If
* there is no current transaction, the XAStatefulHolder is not put into the
* ThreadLocal. If there is a transaction, and it is the first time we're
* attempting to share a XAStatefulHolder on this thread, then we register
* a Synchronization so we can pull the ThreadLocals out of the shared map
* when the transaction completes (either commit() or rollback()). Without
* the Synchronization we would "leak".
*
* @param xaStatefulHolder a XAStatefulHolder to share with other callers
* on this thread.
*/
private void putSharedXAStatefulHolder(final T xaStatefulHolder) {
BitronixTransaction transaction = TransactionContextHelper.currentTransaction();
if (transaction == null) {
if (log.isDebugEnabled()) { log.debug("no current transaction, not adding " + xaStatefulHolder + " to shared connection map"); }
return;
}
final Uid currentTxGtrid = transaction.getResourceManager().getGtrid();
StatefulHolderThreadLocal<T> threadLocal = statefulHolderTransactionMap.get(currentTxGtrid);
if (threadLocal == null) {
// This is the first time this TxGtrid/ThreadLocal is going into the map,
// register interest in synchronization so we can remove it at commit/rollback
try {
transaction.registerSynchronization(new SharedStatefulHolderCleanupSynchronization(currentTxGtrid));
} catch (Exception e) {
// OK, forget it. The transaction is either rollback only or already finished.
return;
}
threadLocal = new StatefulHolderThreadLocal<T>();
statefulHolderTransactionMap.put(currentTxGtrid, threadLocal);
if (log.isDebugEnabled()) { log.debug("added shared connection mapping for " + currentTxGtrid + " holder " + xaStatefulHolder); }
}
// Set the XAStatefulHolder on the ThreadLocal. Even if we've already set it before,
// it's safe -- checking would be more expensive than just setting it again.
threadLocal.set(xaStatefulHolder);
}
示例8: enlistInCurrentTransaction
import bitronix.tm.BitronixTransaction; //导入依赖的package包/类
/**
* Enlist the {@link XAResourceHolder} in the current transaction or do nothing if there is no global transaction
* context for this thread.
* @param xaResourceHolder the {@link XAResourceHolder} to enlist.
* @throws SystemException if an internal error happens.
* @throws RollbackException if the current transaction has been marked as rollback only.
*/
public static void enlistInCurrentTransaction(XAResourceHolder<? extends XAResourceHolder> xaResourceHolder) throws SystemException, RollbackException {
BitronixTransaction currentTransaction = currentTransaction();
ResourceBean bean = xaResourceHolder.getResourceBean();
if (log.isDebugEnabled()) { log.debug("enlisting " + xaResourceHolder + " into " + currentTransaction); }
if (currentTransaction != null) {
if (currentTransaction.timedOut())
throw new BitronixSystemException("transaction timed out");
// in case multiple unjoined branches of the current transaction have run on the resource,
// only the last one counts as all the first ones are ended already
XAResourceHolderState alreadyEnlistedXAResourceHolderState = TransactionContextHelper.getLatestAlreadyEnlistedXAResourceHolderState(xaResourceHolder, currentTransaction);
if (alreadyEnlistedXAResourceHolderState == null || alreadyEnlistedXAResourceHolderState.isEnded()) {
currentTransaction.enlistResource(xaResourceHolder.getXAResource());
}
else if (log.isDebugEnabled()) { log.debug("avoiding re-enlistment of already enlisted but not ended resource " + alreadyEnlistedXAResourceHolderState); }
}
else {
if (bean.getAllowLocalTransactions()) {
if (log.isDebugEnabled()) { log.debug("in local transaction context, skipping enlistment"); }
}
else
throw new BitronixSystemException("resource '" + bean.getUniqueName() + "' cannot be used outside XA " +
"transaction scope. Set allowLocalTransactions to true if you want to allow this and you know " +
"your resource supports this.");
}
}
示例9: delistFromCurrentTransaction
import bitronix.tm.BitronixTransaction; //导入依赖的package包/类
/**
* Delist the {@link XAResourceHolder} from the current transaction or do nothing if there is no global transaction
* context for this thread.
* @param xaResourceHolder the {@link XAResourceHolder} to delist.
* @throws SystemException if an internal error happens.
*/
public static void delistFromCurrentTransaction(XAResourceHolder<? extends XAResourceHolder> xaResourceHolder) throws SystemException {
final BitronixTransaction currentTransaction = currentTransaction();
ResourceBean bean = xaResourceHolder.getResourceBean();
if (log.isDebugEnabled()) { log.debug("delisting " + xaResourceHolder + " from " + currentTransaction); }
// End resource as eagerly as possible. This allows to release connections to the pool much earlier
// with resources fully supporting transaction interleaving.
if (isInEnlistingGlobalTransactionContext(xaResourceHolder, currentTransaction) && !bean.getDeferConnectionRelease()) {
class LocalVisitor implements XAResourceHolderStateVisitor {
private SystemException systemException = null;
@Override
public boolean visit(XAResourceHolderState xaResourceHolderState) {
if (!xaResourceHolderState.isEnded()) {
if (log.isDebugEnabled()) { log.debug("delisting resource " + xaResourceHolderState + " from " + currentTransaction); }
// Watch out: the delistResource() call might throw a BitronixRollbackSystemException to indicate a unilateral rollback.
try {
currentTransaction.delistResource(xaResourceHolderState.getXAResource(), XAResource.TMSUCCESS);
} catch (SystemException e) {
systemException = e;
return false; // stop visitation
}
}
else if (log.isDebugEnabled()) { log.debug("avoiding delistment of not enlisted resource " + xaResourceHolderState); }
return true; // continue visitation
}
}
LocalVisitor xaResourceHolderStateVisitor = new LocalVisitor();
xaResourceHolder.acceptVisitorForXAResourceHolderStates(currentTransaction.getResourceManager().getGtrid(), xaResourceHolderStateVisitor);
if (xaResourceHolderStateVisitor.systemException != null) {
throw xaResourceHolderStateVisitor.systemException;
}
} // isInEnlistingGlobalTransactionContext
}
示例10: requeue
import bitronix.tm.BitronixTransaction; //导入依赖的package包/类
/**
* Switch the {@link XAStatefulHolder}'s state appropriately after the acquired resource handle has been closed.
* The pooled resource will either be marked as closed or not accessible, depending on the value of the bean's
* <code>deferConnectionRelease</code> property and will be marked for release after 2PC execution in the latter case.
* @param xaStatefulHolder the {@link XAStatefulHolder} to requeue.
* @param bean the {@link ResourceBean} of the {@link XAResourceHolder}.
* @throws BitronixSystemException if an internal error happens.
*/
public static void requeue(XAStatefulHolder<? extends XAStatefulHolder> xaStatefulHolder, ResourceBean bean) throws BitronixSystemException {
BitronixTransaction currentTransaction = currentTransaction();
if (log.isDebugEnabled()) { log.debug("requeuing " + xaStatefulHolder + " from " + currentTransaction); }
if (!TransactionContextHelper.isInEnlistingGlobalTransactionContext(xaStatefulHolder, currentTransaction)) {
if (!TransactionContextHelper.isEnlistedInSomeTransaction(xaStatefulHolder)) {
// local mode, always requeue connection immediately
if (log.isDebugEnabled()) { log.debug("resource not in enlisting global transaction context, immediately releasing to pool " + xaStatefulHolder); }
xaStatefulHolder.setState(State.IN_POOL);
} else {
throw new BitronixSystemException("cannot close a resource when its XAResource is taking part in an unfinished global transaction");
}
}
else if (bean.getDeferConnectionRelease()) {
// global mode, defer connection requeuing
if (log.isDebugEnabled()) { log.debug("deferring release to pool of " + xaStatefulHolder); }
if (!TransactionContextHelper.isAlreadyRegisteredForDeferredRelease(xaStatefulHolder, currentTransaction)) {
if (log.isDebugEnabled()) { log.debug("registering DeferredReleaseSynchronization for " + xaStatefulHolder); }
DeferredReleaseSynchronization synchronization = new DeferredReleaseSynchronization(xaStatefulHolder);
currentTransaction.getSynchronizationScheduler().add(synchronization, Scheduler.ALWAYS_LAST_POSITION);
}
else if (log.isDebugEnabled()) { log.debug("already registered DeferredReleaseSynchronization for " + xaStatefulHolder); }
xaStatefulHolder.setState(State.NOT_ACCESSIBLE);
}
else {
// global mode, immediate connection requeuing
if (log.isDebugEnabled()) { log.debug("immediately releasing to pool " + xaStatefulHolder); }
xaStatefulHolder.setState(State.IN_POOL);
}
}
示例11: recycle
import bitronix.tm.BitronixTransaction; //导入依赖的package包/类
/**
* Ensure the {@link XAStatefulHolder}'s release won't be deferred anymore (when appropriate) as it has been recycled.
* @param xaStatefulHolder the recycled {@link XAStatefulHolder}.
*/
public static void recycle(XAStatefulHolder<? extends XAStatefulHolder> xaStatefulHolder) {
BitronixTransaction currentTransaction = currentTransaction();
if (log.isDebugEnabled()) { log.debug("marking " + xaStatefulHolder + " as recycled in " + currentTransaction); }
Scheduler<Synchronization> synchronizationScheduler = currentTransaction.getSynchronizationScheduler();
DeferredReleaseSynchronization deferredReleaseSynchronization = findDeferredRelease(xaStatefulHolder, currentTransaction);
if (deferredReleaseSynchronization != null) {
if (log.isDebugEnabled()) { log.debug(xaStatefulHolder + " has been recycled, unregistering deferred release from " + currentTransaction); }
synchronizationScheduler.remove(deferredReleaseSynchronization);
}
}
示例12: findDeferredRelease
import bitronix.tm.BitronixTransaction; //导入依赖的package包/类
private static DeferredReleaseSynchronization findDeferredRelease(XAStatefulHolder<? extends XAStatefulHolder> xaStatefulHolder, BitronixTransaction currentTransaction) {
Scheduler<Synchronization> synchronizationScheduler = currentTransaction.getSynchronizationScheduler();
for (Synchronization synchronization : synchronizationScheduler) {
if (synchronization instanceof DeferredReleaseSynchronization) {
DeferredReleaseSynchronization deferredReleaseSynchronization = (DeferredReleaseSynchronization) synchronization;
if (deferredReleaseSynchronization.getXAStatefulHolder() == xaStatefulHolder) {
return deferredReleaseSynchronization;
}
} // if synchronization instanceof DeferredReleaseSynchronization
} // for
return null;
}
示例13: isInEnlistingGlobalTransactionContext
import bitronix.tm.BitronixTransaction; //导入依赖的package包/类
private static boolean isInEnlistingGlobalTransactionContext(XAResourceHolder<? extends XAResourceHolder> xaResourceHolder, BitronixTransaction currentTransaction) {
boolean globalTransactionMode = false;
if (currentTransaction != null && xaResourceHolder.isExistXAResourceHolderStatesForGtrid(currentTransaction.getResourceManager().getGtrid())) {
globalTransactionMode = true;
}
if (log.isDebugEnabled()) { log.debug("resource is " + (globalTransactionMode ? "" : "not ") + "in enlisting global transaction context: " + xaResourceHolder); }
return globalTransactionMode;
}
示例14: setTransaction
import bitronix.tm.BitronixTransaction; //导入依赖的package包/类
/**
* Link a transaction with this ThreadContext.
*
* @param transaction the transaction to link.
*/
public void setTransaction(BitronixTransaction transaction) {
if (transaction == null)
throw new IllegalArgumentException("transaction parameter cannot be null");
if (log.isDebugEnabled()) { log.debug("assigning <" + transaction + "> to <" + this + ">"); }
this.transaction = transaction;
}
示例15: scheduleTransactionTimeout
import bitronix.tm.BitronixTransaction; //导入依赖的package包/类
/**
* Schedule a task that will mark the transaction as timed out at the specified date. If this method is called
* with the same transaction multiple times, the previous timeout date is dropped and replaced by the new one.
* @param transaction the transaction to mark as timeout.
* @param executionTime the date at which the transaction must be marked.
*/
public void scheduleTransactionTimeout(BitronixTransaction transaction, Date executionTime) {
if (log.isDebugEnabled()) { log.debug("scheduling transaction timeout task on " + transaction + " for " + executionTime); }
if (transaction == null)
throw new IllegalArgumentException("expected a non-null transaction");
if (executionTime == null)
throw new IllegalArgumentException("expected a non-null execution date");
TransactionTimeoutTask task = new TransactionTimeoutTask(transaction, executionTime, this);
addTask(task);
if (log.isDebugEnabled()) { log.debug("scheduled " + task + ", total task(s) queued: " + countTasksQueued()); }
}