本文整理匯總了Java中javax.transaction.Transaction.getStatus方法的典型用法代碼示例。如果您正苦於以下問題:Java Transaction.getStatus方法的具體用法?Java Transaction.getStatus怎麽用?Java Transaction.getStatus使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.transaction.Transaction
的用法示例。
在下文中一共展示了Transaction.getStatus方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testSetRollbackOnly
import javax.transaction.Transaction; //導入方法依賴的package包/類
public void testSetRollbackOnly() {
try {
utx.begin();
utx.setRollbackOnly();
Transaction txn = tm.getTransaction();
if (txn.getStatus() != Status.STATUS_MARKED_ROLLBACK) {
utx.rollback();
fail("testSetRollbackonly failed");
}
utx.rollback();
}
catch (Exception e) {
fail("exception in testSetRollbackonly due to " + e);
e.printStackTrace();
}
}
示例2: isJtaTransactionActive
import javax.transaction.Transaction; //導入方法依賴的package包/類
protected boolean isJtaTransactionActive(Transaction tx) {
try {
if (tx == null) {
return false;
}
int status = tx.getStatus();
status = Status.STATUS_UNKNOWN == status ? tx.getStatus() : status; // if status unknown (transient state) -> call again
switch (status) {
case Status.STATUS_NO_TRANSACTION:
return false;
case Status.STATUS_COMMITTED:
return transactionMap.get(tx) != null; // if state is committed we consider the Jacis TX to be still active (if there is one) since the sync committing the Jacis changes may still stand out
case Status.STATUS_ROLLEDBACK:
return transactionMap.get(tx) != null;
}
return true;
} catch (SystemException e) {
throw new JacisTransactionException(e);
}
}
示例3: checkTransactionActive
import javax.transaction.Transaction; //導入方法依賴的package包/類
public void checkTransactionActive() throws JMSException {
// don't bother looking at the transaction if there's an active XID
if (!inManagedTx && tm != null) {
try {
Transaction tx = tm.getTransaction();
if (tx != null) {
int status = tx.getStatus();
// Only allow states that will actually succeed
if (status != Status.STATUS_ACTIVE && status != Status.STATUS_PREPARING && status != Status.STATUS_PREPARED && status != Status.STATUS_COMMITTING) {
throw new javax.jms.IllegalStateException("Transaction " + tx + " not active");
}
}
} catch (SystemException e) {
JMSException jmsE = new javax.jms.IllegalStateException("Unexpected exception on the Transaction ManagerTransaction");
jmsE.initCause(e);
throw jmsE;
}
}
}
示例4: inTransaction
import javax.transaction.Transaction; //導入方法依賴的package包/類
private boolean inTransaction() {
try {
Transaction tx = getTransactionManager().getTransaction();
return tx != null && tx.getStatus() == Status.STATUS_ACTIVE;
} catch (SystemException e) {
return false;
}
}
示例5: transactionRunning
import javax.transaction.Transaction; //導入方法依賴的package包/類
private boolean transactionRunning() throws SQLException {
try {
Transaction transaction = transactionManager.getTransaction();
return transaction != null && ( transaction.getStatus() == STATUS_ACTIVE || transaction.getStatus() == STATUS_MARKED_ROLLBACK );
} catch ( Exception e ) {
throw new SQLException( "Exception in retrieving existing transaction", e );
}
}
示例6: testSetRollbackOnly
import javax.transaction.Transaction; //導入方法依賴的package包/類
@Test
public void testSetRollbackOnly() throws Exception {
utx.begin();
utx.setRollbackOnly();
Transaction txn = tm.getTransaction();
if (txn.getStatus() != Status.STATUS_MARKED_ROLLBACK) {
utx.rollback();
fail("testSetRollbackonly failed");
}
utx.rollback();
}
示例7: joinCurrentTransaction
import javax.transaction.Transaction; //導入方法依賴的package包/類
@Override
public JacisTransactionHandle joinCurrentTransaction(JacisContainer container) {
try {
Transaction tx = getJtaTransaction();
if (tx == null) {
throw new JacisNoTransactionException("No transaction!");
} else if (!isJtaTransactionActive(tx)) {
throw new JacisNoTransactionException("No active transaction! Current Transaction: " + tx + " (state=" + tx.getStatus() + ")");
}
JacisTransactionHandle currentTxHandle = transactionMap.get(tx);
if (currentTxHandle != null) {
if (log.isTraceEnabled()) {
log.trace("{} found existing handle [{}] for JTA-Tx=[{}]. Thread: {}", this, currentTxHandle, tx, Thread.currentThread().getName());
}
return currentTxHandle;
}
long txNr = txSeq.incrementAndGet();
String txId = computeJacisTxId(tx, txNr);
String txDescription = computeJacisTxDescription(tx, txId);
JacisTransactionHandle txHandle = new JacisTransactionHandle(txId, txDescription, tx);
tx.registerSynchronization(new JacisSync(container, txHandle));
transactionMap.put(tx, txHandle);
if (log.isTraceEnabled()) {
log.trace("{} created new handle [{}] for JTA-Tx=[{}]. Thread: {}", this, txHandle, tx, Thread.currentThread().getName());
}
return txHandle;
} catch (SystemException | RollbackException e) {
throw new JacisTransactionException(e);
}
}
示例8: getStatus
import javax.transaction.Transaction; //導入方法依賴的package包/類
public static int getStatus(final Transaction tx) {
try {
return tx.getStatus();
} catch (final SystemException e) {
throw new LjtSystemRuntimeException(e);
}
}
示例9: markTransactionAsRollbackOnly
import javax.transaction.Transaction; //導入方法依賴的package包/類
private void markTransactionAsRollbackOnly(Method method) throws Exception {
Transaction currentTx = _transactionManager.getTransaction();
if (_logger.isDebugEnabled()) {
_logger.debug(String.format("%s is marking the transaction as rollback only: currentTx=%s, startedTx=%s, suspendedTx=%s",
Thread.currentThread().getName(), currentTx, _startedTx, _suspendedTx));
}
if (_startedTx != null) {
if (currentTx != null && currentTx.equals(_startedTx)) {
currentTx.setRollbackOnly();
} else {
// Suspend any bad transaction - there is bug somewhere, but we will try to tidy things up
JCALogger.ROOT_LOGGER.currentTransactionIsNotSameAsThe(currentTx, _startedTx.toString());
Transaction origTx = _transactionManager.suspend();
try {
_transactionManager.resume(_startedTx);
_startedTx.setRollbackOnly();
} finally {
// Resume any suspended transaction
if (origTx != null) {
try {
_transactionManager.suspend();
_transactionManager.resume(origTx);
} catch (Throwable t) {
JCALogger.ROOT_LOGGER.messageEndpointFailedToResumeOldTransaction(_delegate.toString(), origTx.toString());
}
}
}
}
} else if (_messageEndpointFactory.isDeliveryTransacted(method)
&& currentTx != null && currentTx.getStatus() == Status.STATUS_ACTIVE) {
// Set rollback only flag on a source managed Tx
currentTx.setRollbackOnly();
}
}
示例10: getJtaSynchronizedSession
import javax.transaction.Transaction; //導入方法依賴的package包/類
/**
* Retrieve a Session from the given SessionHolder, potentially from a
* JTA transaction synchronization.
* @param sessionHolder the SessionHolder to check
* @param sessionFactory the SessionFactory to get the JTA TransactionManager from
* @param jdbcExceptionTranslator SQLExcepionTranslator to use for flushing the
* Session on transaction synchronization (may be {@code null})
* @return the associated Session, if any
* @throws DataAccessResourceFailureException if the Session couldn't be created
*/
private static Session getJtaSynchronizedSession(
SessionHolder sessionHolder, SessionFactory sessionFactory,
SQLExceptionTranslator jdbcExceptionTranslator) throws DataAccessResourceFailureException {
// JTA synchronization is only possible with a javax.transaction.TransactionManager.
// We'll check the Hibernate SessionFactory: If a TransactionManagerLookup is specified
// in Hibernate configuration, it will contain a TransactionManager reference.
TransactionManager jtaTm = getJtaTransactionManager(sessionFactory, sessionHolder.getAnySession());
if (jtaTm != null) {
// Check whether JTA transaction management is active ->
// fetch pre-bound Session for the current JTA transaction, if any.
// (just necessary for JTA transaction suspension, with an individual
// Hibernate Session per currently active/suspended transaction)
try {
// Look for transaction-specific Session.
Transaction jtaTx = jtaTm.getTransaction();
if (jtaTx != null) {
int jtaStatus = jtaTx.getStatus();
if (jtaStatus == Status.STATUS_ACTIVE || jtaStatus == Status.STATUS_MARKED_ROLLBACK) {
Session session = sessionHolder.getValidatedSession(jtaTx);
if (session == null && !sessionHolder.isSynchronizedWithTransaction()) {
// No transaction-specific Session found: If not already marked as
// synchronized with transaction, register the default thread-bound
// Session as JTA-transactional. If there is no default Session,
// we're a new inner JTA transaction with an outer one being suspended:
// In that case, we'll return null to trigger opening of a new Session.
session = sessionHolder.getValidatedSession();
if (session != null) {
logger.debug("Registering JTA transaction synchronization for existing Hibernate Session");
sessionHolder.addSession(jtaTx, session);
jtaTx.registerSynchronization(
new SpringJtaSynchronizationAdapter(
new SpringSessionSynchronization(sessionHolder, sessionFactory, jdbcExceptionTranslator, false),
jtaTm));
sessionHolder.setSynchronizedWithTransaction(true);
// Switch to FlushMode.AUTO, as we have to assume a thread-bound Session
// with FlushMode.NEVER, which needs to allow flushing within the transaction.
FlushMode flushMode = session.getFlushMode();
if (flushMode.lessThan(FlushMode.COMMIT)) {
session.setFlushMode(FlushMode.AUTO);
sessionHolder.setPreviousFlushMode(flushMode);
}
}
}
return session;
}
}
// No transaction active -> simply return default thread-bound Session, if any
// (possibly from OpenSessionInViewFilter/Interceptor).
return sessionHolder.getValidatedSession();
}
catch (Throwable ex) {
throw new DataAccessResourceFailureException("Could not check JTA transaction", ex);
}
}
else {
// No JTA TransactionManager -> simply return default thread-bound Session, if any
// (possibly from OpenSessionInViewFilter/Interceptor).
return sessionHolder.getValidatedSession();
}
}
示例11: registerJtaSynchronization
import javax.transaction.Transaction; //導入方法依賴的package包/類
/**
* Register a JTA synchronization for the given Session, if any.
* @param sessionHolder the existing thread-bound SessionHolder, if any
* @param session the Session to register
* @param sessionFactory the SessionFactory that the Session was created with
* @param jdbcExceptionTranslator SQLExcepionTranslator to use for flushing the
* Session on transaction synchronization (may be {@code null})
*/
private static void registerJtaSynchronization(Session session, SessionFactory sessionFactory,
SQLExceptionTranslator jdbcExceptionTranslator, SessionHolder sessionHolder) {
// JTA synchronization is only possible with a javax.transaction.TransactionManager.
// We'll check the Hibernate SessionFactory: If a TransactionManagerLookup is specified
// in Hibernate configuration, it will contain a TransactionManager reference.
TransactionManager jtaTm = getJtaTransactionManager(sessionFactory, session);
if (jtaTm != null) {
try {
Transaction jtaTx = jtaTm.getTransaction();
if (jtaTx != null) {
int jtaStatus = jtaTx.getStatus();
if (jtaStatus == Status.STATUS_ACTIVE || jtaStatus == Status.STATUS_MARKED_ROLLBACK) {
logger.debug("Registering JTA transaction synchronization for new Hibernate Session");
SessionHolder holderToUse = sessionHolder;
// Register JTA Transaction with existing SessionHolder.
// Create a new SessionHolder if none existed before.
if (holderToUse == null) {
holderToUse = new SessionHolder(jtaTx, session);
}
else {
holderToUse.addSession(jtaTx, session);
}
jtaTx.registerSynchronization(
new SpringJtaSynchronizationAdapter(
new SpringSessionSynchronization(holderToUse, sessionFactory, jdbcExceptionTranslator, true),
jtaTm));
holderToUse.setSynchronizedWithTransaction(true);
if (holderToUse != sessionHolder) {
TransactionSynchronizationManager.bindResource(sessionFactory, holderToUse);
}
}
}
}
catch (Throwable ex) {
throw new DataAccessResourceFailureException(
"Could not register synchronization with JTA TransactionManager", ex);
}
}
}
示例12: inTransaction
import javax.transaction.Transaction; //導入方法依賴的package包/類
public static boolean inTransaction() throws ServletException {
TransactionManager tm = getTransactionManager();
try {
Transaction t = tm.getTransaction();
return t != null && t.getStatus() == Status.STATUS_ACTIVE;
}
catch(Exception e) {
throw new ServletException(e);
}
}
示例13: commitTransactionIfPresent
import javax.transaction.Transaction; //導入方法依賴的package包/類
protected void commitTransactionIfPresent() throws Exception {
Transaction t = Util.getTransactionManager().getTransaction();
if (t == null || t.getStatus() != Status.STATUS_ACTIVE) {
return;
}
log.info("committing the JTA transaction");
t.commit();
}
示例14: rollbackTransactionIfPresent
import javax.transaction.Transaction; //導入方法依賴的package包/類
protected void rollbackTransactionIfPresent() throws Exception {
Transaction t = Util.getTransactionManager().getTransaction();
if (t == null || t.getStatus() != Status.STATUS_ACTIVE) {
return;
}
log.info("rolling back the JTA transaction");
t.rollback();
}