Methods Summary |
---|
public void | addExtendedEntityManagerMapping(javax.persistence.EntityManagerFactory emf, javax.persistence.EntityManager em)
getExtendedEntityManagerMap().put(emf, em);
|
synchronized void | addResourceName(java.lang.String resourceName)
if (resourceNames == null)
resourceNames = new ArrayList<String>();
resourceNames.add(resourceName);
|
public void | addTxEntityManagerMapping(javax.persistence.EntityManagerFactory emf, javax.persistence.EntityManager em)
getTxEntityManagerMap().put(emf, em);
|
int | cancelTimerTask()
cancel();
return timeout;
|
public void | commit()
// START local transaction timeout
// If this transaction is set for timeout, cancel it as it is in the commit state
if (isTimerTask)
cancel();
// END local transaction timeout
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE,"--In J2EETransaction.commit, jtsTx="+jtsTx
+" nonXAResource="+ nonXAResource);
}
commitStarted = true;
if ( jtsTx != null ) {
try {
jtsTx.commit();
} finally {
j2eeTM.clearThreadTx();
onTxCompletion(true);
}
}
else { // local tx
try {
if ( isTimedOut ) {
// rollback nonXA resource
if ( nonXAResource != null )
nonXAResource.getXAResource().rollback(xid);
localTxStatus = Status.STATUS_ROLLEDBACK;
throw new RollbackException(sm.getString("enterprise_distributedtx.rollback_timeout"));
}
if ( isRollbackOnly() ) {
// rollback nonXA resource
if ( nonXAResource != null )
nonXAResource.getXAResource().rollback(xid);
localTxStatus = Status.STATUS_ROLLEDBACK;
throw new RollbackException(sm.getString("enterprise_distributedtx.mark_rollback"));
}
// call beforeCompletion
for ( int i=0; i<syncs.size(); i++ ) {
try {
Synchronization sync = (Synchronization)syncs.elementAt(i);
sync.beforeCompletion();
} catch ( RuntimeException ex ) {
setRollbackOnly();
} catch (Exception ex) { }
}
for ( int i=0; i<interposedSyncs.size(); i++ ) {
try {
Synchronization sync = (Synchronization)interposedSyncs.elementAt(i);
sync.beforeCompletion();
} catch ( RuntimeException ex ) {
setRollbackOnly();
} catch (Exception ex) { }
}
// check rollbackonly again, in case any of the beforeCompletion
// calls marked it for rollback.
if ( isRollbackOnly()) {
//Check if it is a Local Transaction
if(jtsTx == null) {
if ( nonXAResource != null )
nonXAResource.getXAResource().rollback(xid);
localTxStatus = Status.STATUS_ROLLEDBACK;
throw new RollbackException(sm.getString("enterprise_distributedtx.mark_rollback"));
// else it is a global transaction
} else {
jtsTx.rollback();
localTxStatus = Status.STATUS_ROLLEDBACK;
throw new RollbackException(sm.getString("enterprise_distributedtx.mark_rollback"));
}
}
// check if there is a jtsTx active, in case any of the
// beforeCompletions registered the first XA resource.
if ( jtsTx != null ) {
jtsTx.commit();
//IASRI START 4731186
localTxStatus = Status.STATUS_COMMITTED;
//IASRI END 4731186
// Note: JTS will not call afterCompletions in this case,
// because no syncs have been registered with JTS.
// So afterCompletions are called in finally block below.
}
else {
// do single-phase commit on nonXA resource
if ( nonXAResource != null )
nonXAResource.getXAResource().commit(xid, true);
// XXX should this be STATUS_NO_TRANSACTION ?
localTxStatus = Status.STATUS_COMMITTED;
}
} catch ( RollbackException ex ) {
localTxStatus = Status.STATUS_ROLLEDBACK; // XXX is this correct ?
throw ex;
} catch ( SystemException ex ) {
// localTxStatus = Status.STATUS_ROLLEDBACK; // XXX is this correct ?
localTxStatus = Status.STATUS_COMMITTING;
throw ex;
} catch ( Exception ex ) {
localTxStatus = Status.STATUS_ROLLEDBACK; // XXX is this correct ?
SystemException exc = new SystemException();
exc.initCause(ex);
throw exc;
} finally {
j2eeTM.clearThreadTx();
for ( int i=0; i<interposedSyncs.size(); i++ ) {
try {
Synchronization sync = (Synchronization)interposedSyncs.elementAt(i);
sync.afterCompletion(localTxStatus);
} catch ( Exception ex ) {}
}
// call afterCompletions
for ( int i=0; i<syncs.size(); i++ ) {
try {
Synchronization sync = (Synchronization)syncs.elementAt(i);
sync.afterCompletion(localTxStatus);
} catch ( Exception ex ) {}
}
onTxCompletion(true);
}
}
|
public boolean | delistResource(javax.transaction.xa.XAResource xaRes, int flag)
// START OF IASRI 4660742
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE,"--In J2EETransaction.delistResource, jtsTx="
+jtsTx +" nonXAResource="+nonXAResource);
}
// END OF IASRI 4660742
if ( jtsTx != null )
return jtsTx.delistResource(xaRes, flag);
else
throw new IllegalStateException(sm.getString("enterprise_distributedtx.deleteresource_for_localtx"));
|
public boolean | enlistResource(javax.transaction.xa.XAResource xaRes)
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE,"--In J2EETransaction.enlistResource, jtsTx="
+jtsTx+" nonXAResource="+nonXAResource);
}
if ( jtsTx != null )
return jtsTx.enlistResource(xaRes);
else if ( nonXAResource != null )
throw new IllegalStateException(sm.getString("enterprise_distributedtx.already_has_nonxa"));
// IASRI END 4723068
/***
else // XXX what to do ? Start a new JTS tx ?
throw new IllegalStateException("J2EETransaction.enlistResource called for local tx");
***/
else { // Start a new JTS tx
j2eeTM.startJTSTx(this);
return jtsTx.enlistResource(xaRes);
}
// IASRI END 4723068
|
public boolean | equals(java.lang.Object other)
if ( other == this )
return true;
if ( other instanceof J2EETransaction ) {
J2EETransaction othertx = (J2EETransaction)other;
return ( txId == othertx.txId );
}
return false;
|
public java.lang.Object | getActiveTxCache()
return this.activeTxCache;
|
public java.util.Set | getAllParticipatingPools()Return all pools registered in the resourceTable. This
will cut down the scope of pools on which transactionComplted
is called by the PoolManagerImpl. This method will return
only those pools that have ever participated in a tx
return (Set) resourceTable.keySet();
|
java.lang.String | getComponentName()
return componentName;
|
public java.lang.Object | getContainerData()
return containerData;
|
public javax.persistence.EntityManager | getExtendedEntityManager(javax.persistence.EntityManagerFactory emf)
return getExtendedEntityManagerMap().get(emf);
|
private java.util.Map | getExtendedEntityManagerMap()
if( extendedEntityManagerMap == null ) {
extendedEntityManagerMap =
new HashMap<EntityManagerFactory, EntityManager>();
}
return extendedEntityManagerMap;
|
javax.transaction.Transaction | getJTSTx()
return jtsTx;
|
ResourceHandle | getLAOResource()
return laoResource;
|
javax.transaction.xa.Xid | getLocalXid()
return xid;
|
private static synchronized long | getNewTxId()
long newTxId = txIdCounter++;
return newTxId;
|
public ResourceHandle | getNonXAResource()
return nonXAResource;
|
public int | getRemainingTimeout()Return duration in seconds before transaction would timeout.
Returns zero if this transaction has no timeout set.
Returns negative value if already timed out.
if (timeout == 0) {
return timeout;
} else if (isTimedOut) {
return -1;
} else {
// compute how much time left before transaction times out
return timeout - (int)((System.currentTimeMillis() - startTime) / 1000L);
}
|
synchronized java.util.ArrayList | getResourceNames()
return resourceNames;
|
public java.util.Set | getResources(java.lang.String poolName)
return (Set) resourceTable.get(poolName);
|
public long | getStartTime()
return startTime;
|
public int | getStatus()
if ( jtsTx != null )
return jtsTx.getStatus();
else
return localTxStatus;
|
public java.lang.String | getTransactionId()
return xid.toString();
|
public javax.persistence.EntityManager | getTxEntityManager(javax.persistence.EntityManagerFactory emf)
return getTxEntityManagerMap().get(emf);
|
private java.util.Map | getTxEntityManagerMap()
if( txEntityManagerMap == null ) {
txEntityManagerMap =
new HashMap<EntityManagerFactory, EntityManager>();
}
return txEntityManagerMap;
|
synchronized java.lang.Object | getUserResource(java.lang.Object key)
if (userResourceMap == null)
return null;
return userResourceMap.get(key);
|
public int | hashCode()
return (int)txId;
|
private static synchronized void | initializeTimer()
if (isTimerInitialized)
return;
timer = new Timer(true); // daemon
isTimerInitialized = true;
|
boolean | isAssociatedTimeout()
return isTimerTask;
|
boolean | isImportedTransaction()
return imported;
|
boolean | isLocalTx()
return (jtsTx==null);
|
private boolean | isRollbackOnly()
int status;
if ( jtsTx != null )
status = jtsTx.getStatus();
else
status = localTxStatus;
return (status == Status.STATUS_MARKED_ROLLBACK);
|
boolean | isTimedout()
return isTimedOut;
|
private void | onTxCompletion(boolean status)
for (Map.Entry<EntityManagerFactory, EntityManager> entry :
getTxEntityManagerMap().entrySet()) {
EntityManager em = entry.getValue();
if (em.isOpen()) {
try {
em.close();
} catch (Throwable th) {
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "Exception while closing em.", th);
}
}
}
}
|
synchronized void | putUserResource(java.lang.Object key, java.lang.Object value)
if (userResourceMap == null)
userResourceMap = new HashMap<Object, Object>();
userResourceMap.put(key, value);
|
void | registerInterposedSynchronization(javax.transaction.Synchronization sync)
interposedSyncs.add(sync);
|
public void | registerSynchronization(javax.transaction.Synchronization sync)
// START OF IASRI 4660742
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE,"--In J2EETransaction.registerSynchronization, jtsTx=" +jtsTx+" nonXAResource="+nonXAResource);
}
// END OF IASRI 4660742
if ( jtsTx != null )
jtsTx.registerSynchronization(sync);
else
syncs.add(sync);
|
public void | removeExtendedEntityManagerMapping(javax.persistence.EntityManagerFactory emf)
getExtendedEntityManagerMap().remove(emf);
|
public void | rollback()
// START local transaction timeout
// If this transaction is set for timeout, cancel it as it is in the rollback state
if (isTimerTask)
cancel();
// END local transaction timeout
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE,"--In J2EETransaction.rollback, jtsTx="+jtsTx
+" nonXAResource="+nonXAResource);
}
try {
if ( jtsTx != null )
jtsTx.rollback();
else { // rollback nonXA resource
if ( nonXAResource != null )
nonXAResource.getXAResource().rollback(xid);
// XXX should this be STATUS_NO_TRANSACTION ?
localTxStatus = Status.STATUS_ROLLEDBACK;
}
} catch ( Exception ex ) {
localTxStatus = Status.STATUS_ROLLEDBACK; // XXX is this correct ?
} finally {
j2eeTM.clearThreadTx();
if ( jtsTx == null ) {
// call afterCompletions
for ( int i=0; i<syncs.size(); i++ ) {
try {
Synchronization sync = (Synchronization)syncs.elementAt(i);
sync.afterCompletion(Status.STATUS_ROLLEDBACK);
} catch ( Exception ex ) {}
}
}
onTxCompletion(false);
}
|
public void | run()
isTimedOut = true;
try {
setRollbackOnly();
} catch (Exception e) {
e.printStackTrace();
}
|
public void | setActiveTxCache(java.lang.Object cache)
this.activeTxCache = cache;
|
void | setComponentName(java.lang.String componentName)
this.componentName = componentName;
|
public void | setContainerData(java.lang.Object data)
containerData = data;
|
void | setImportedTransaction()
imported = true;
|
void | setJTSTx(javax.transaction.Transaction jtsTx)
this.jtsTx = jtsTx;
if ( !commitStarted ) {
// register syncs
for ( int i=0; i<syncs.size(); i++ )
jtsTx.registerSynchronization((Synchronization)syncs.elementAt(i));
for ( int i=0; i<interposedSyncs.size(); i++ )
((TransactionImpl)jtsTx).registerInterposedSynchronization((Synchronization)interposedSyncs.elementAt(i));
}
|
void | setLAOResource(ResourceHandle h)
laoResource = h;
|
void | setNonXAResource(ResourceHandle h)
nonXAResource = h;
|
public void | setResources(java.util.Set resources, java.lang.String poolName)
resourceTable.put(poolName, resources);
|
public void | setRollbackOnly()
if ( jtsTx != null )
jtsTx.setRollbackOnly();
else
localTxStatus = Status.STATUS_MARKED_ROLLBACK;
|
public java.lang.String | toString()
return "J2EETransaction: txId="+txId+" nonXAResource="+nonXAResource
+" jtsTx="+jtsTx+" localTxStatus="+localTxStatus
+" syncs="+syncs;
|