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


Java TransactionManager.getTransaction方法代碼示例

本文整理匯總了Java中javax.transaction.TransactionManager.getTransaction方法的典型用法代碼示例。如果您正苦於以下問題:Java TransactionManager.getTransaction方法的具體用法?Java TransactionManager.getTransaction怎麽用?Java TransactionManager.getTransaction使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.transaction.TransactionManager的用法示例。


在下文中一共展示了TransactionManager.getTransaction方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: SpringSessionSynchronization

import javax.transaction.TransactionManager; //導入方法依賴的package包/類
public SpringSessionSynchronization(
		SessionHolder sessionHolder, SessionFactory sessionFactory,
		SQLExceptionTranslator jdbcExceptionTranslator, boolean newSession) {

	this.sessionHolder = sessionHolder;
	this.sessionFactory = sessionFactory;
	this.jdbcExceptionTranslator = jdbcExceptionTranslator;
	this.newSession = newSession;

	// Check whether the SessionFactory has a JTA TransactionManager.
	TransactionManager jtaTm =
			SessionFactoryUtils.getJtaTransactionManager(sessionFactory, sessionHolder.getAnySession());
	if (jtaTm != null) {
		this.hibernateTransactionCompletion = true;
		// Fetch current JTA Transaction object
		// (just necessary for JTA transaction suspension, with an individual
		// Hibernate Session per currently active/suspended transaction).
		try {
			this.jtaTransaction = jtaTm.getTransaction();
		}
		catch (SystemException ex) {
			throw new DataAccessResourceFailureException("Could not access JTA transaction", ex);
		}
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:26,代碼來源:SpringSessionSynchronization.java

示例2: connect

import javax.transaction.TransactionManager; //導入方法依賴的package包/類
private void connect() throws HibernateException {
	if (!isCurrentTransaction) {
		//if there is no current transaction callback registered
		//when we obtain the connection, try to register one now
		//note that this is not going to handle the case of
		//multiple-transactions-per-connection when the user is
		//manipulating transactions (need to use Hibernate txn)
		TransactionManager tm = factory.getTransactionManager();
		if (tm!=null) {
			try {
				javax.transaction.Transaction tx = tm.getTransaction();
				if ( isJTATransactionActive(tx) ) {
					tx.registerSynchronization( new CacheSynchronization(this) );
					isCurrentTransaction = true;
				}
			}
			catch (Exception e) {
				throw new TransactionException("could not register synchronization with JTA TransactionManager", e);
			}
		}
	}
	connection = batcher.openConnection();
	connect = false;
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:25,代碼來源:SessionImpl.java

示例3: getJtaSynchronizedSession

import javax.transaction.TransactionManager; //導入方法依賴的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

示例4: registerJtaSynchronization

import javax.transaction.TransactionManager; //導入方法依賴的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

示例5: begin

import javax.transaction.TransactionManager; //導入方法依賴的package包/類
public void begin() throws ResourceException {
  if (DEBUG) {
    try {
      throw new NullPointerException("Asif:JCALocalTransaction:begin");
    } catch (NullPointerException npe) {
      npe.printStackTrace();
    }
  }
  try {
    if (!initDone || this.cache.isClosed()) {
      this.init();
    }
    // System.out.println("JCALocalTransaction:Asif: cache is ="+cache +
    // " for tx ="+this);
    LogWriter logger = cache.getLogger();
    if (logger.fineEnabled()) {
      logger.fine("JCALocalTransaction::begin:");
    }
    TransactionManager tm = cache.getJTATransactionManager();
    if (this.tid != null) {
      throw new LocalTransactionException(" A transaction is already in progress");
    }
    if (tm != null && tm.getTransaction() != null) {
      if (logger.fineEnabled()) {
        logger.fine("JCAManagedConnection: JTA transaction is on");
      }
      // This is having a JTA transaction. Assuming ignore jta flag is true,
      // explicitly being a gemfire transaction.
      TXStateProxy tsp = this.gfTxMgr.getTXState();
      if (tsp == null) {
        this.gfTxMgr.begin();
        tsp = this.gfTxMgr.getTXState();
        tsp.setJCATransaction();
        this.tid = tsp.getTransactionId();
        if (logger.fineEnabled()) {
          logger.fine("JCALocalTransaction:begun GFE transaction");
        }
      } else {
        throw new LocalTransactionException("GemFire is already associated with a transaction");
      }
    } else {
      if (logger.fineEnabled()) {
        logger.fine("JCAManagedConnection: JTA Transaction does not exist.");
      }
    }
  } catch (SystemException e) {
    // this.onError();
    throw new ResourceException(e);
  }
  // Not to be invoked for local transactions managed by the container
  // Iterator<ConnectionEventListener> itr = this.listeners.iterator();
  // ConnectionEvent ce = new ConnectionEvent(this,
  // ConnectionEvent.LOCAL_TRANSACTION_STARTED);
  // while (itr.hasNext()) {
  // itr.next().localTransactionStarted(ce);
  // }

}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:59,代碼來源:JCALocalTransaction.java


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