當前位置: 首頁>>代碼示例>>Java>>正文


Java Transaction.getStatus方法代碼示例

本文整理匯總了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();
  }
}
 
開發者ID:gemxd,項目名稱:gemfirexd-oss,代碼行數:17,代碼來源:GlobalTransactionTest.java

示例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);
  }
}
 
開發者ID:JanWiemer,項目名稱:jacis,代碼行數:21,代碼來源:AbstractJacisTransactionAdapterJTA.java

示例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;
      }
   }
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:20,代碼來源:ActiveMQRAManagedConnection.java

示例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;
	}
}
 
開發者ID:Jenner4S,項目名稱:unitimes,代碼行數:9,代碼來源:ReplicatedServer.java

示例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 );
    }
}
 
開發者ID:agroal,項目名稱:agroal,代碼行數:9,代碼來源:NarayanaTransactionIntegration.java

示例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();
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:12,代碼來源:GlobalTransactionJUnitTest.java

示例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);
  }
}
 
開發者ID:JanWiemer,項目名稱:jacis,代碼行數:31,代碼來源:AbstractJacisTransactionAdapterJTA.java

示例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);
    }
}
 
開發者ID:lastaflute,項目名稱:lasta-di,代碼行數:8,代碼來源:LjtTransactionUtil.java

示例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();
    }
}
 
開發者ID:jboss-switchyard,項目名稱:switchyard,代碼行數:38,代碼來源:EndpointProxy.java

示例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();
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:72,代碼來源:SessionFactoryUtils.java

示例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);
		}
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:49,代碼來源:SessionFactoryUtils.java

示例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);
        }
    }
 
開發者ID:NovaOrdis,項目名稱:playground,代碼行數:17,代碼來源:Util.java

示例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();

    }
 
開發者ID:NovaOrdis,項目名稱:playground,代碼行數:15,代碼來源:CacheOperation.java

示例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();
    }
 
開發者ID:NovaOrdis,項目名稱:playground,代碼行數:14,代碼來源:CacheOperation.java


注:本文中的javax.transaction.Transaction.getStatus方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。