List of usage examples for javax.transaction Transaction getStatus
public int getStatus() throws SystemException;
From source file:org.apache.servicemix.transaction.GeronimoPlatformTransactionManager.java
protected void registerTransactionAssociationListener() { addTransactionAssociationListener(new TransactionManagerMonitor() { public void threadAssociated(Transaction transaction) { try { if (transaction.getStatus() == Status.STATUS_ACTIVE) { SuspendedResourcesHolder holder = suspendedResources.remove(transaction); if (holder != null && holder.getSuspendedSynchronizations() != null) { TransactionSynchronizationManager.setActualTransactionActive(true); TransactionSynchronizationManager.setCurrentTransactionReadOnly(holder.isReadOnly()); TransactionSynchronizationManager.setCurrentTransactionName(holder.getName()); TransactionSynchronizationManager.initSynchronization(); for (Iterator<?> it = holder.getSuspendedSynchronizations().iterator(); it.hasNext();) { TransactionSynchronization synchronization = (TransactionSynchronization) it.next(); synchronization.resume(); TransactionSynchronizationManager.registerSynchronization(synchronization); }/*from w w w. j a va2 s. co m*/ } } } catch (SystemException e) { return; } } public void threadUnassociated(Transaction transaction) { try { if (transaction.getStatus() == Status.STATUS_ACTIVE) { if (TransactionSynchronizationManager.isSynchronizationActive()) { List<?> suspendedSynchronizations = TransactionSynchronizationManager .getSynchronizations(); for (Iterator<?> it = suspendedSynchronizations.iterator(); it.hasNext();) { ((TransactionSynchronization) it.next()).suspend(); } TransactionSynchronizationManager.clearSynchronization(); String name = TransactionSynchronizationManager.getCurrentTransactionName(); TransactionSynchronizationManager.setCurrentTransactionName(null); boolean readOnly = TransactionSynchronizationManager.isCurrentTransactionReadOnly(); TransactionSynchronizationManager.setCurrentTransactionReadOnly(false); TransactionSynchronizationManager.setActualTransactionActive(false); SuspendedResourcesHolder holder = new SuspendedResourcesHolder(null, suspendedSynchronizations, name, readOnly); suspendedResources.put(transaction, holder); } } } catch (SystemException e) { return; } } }); }
From source file:com.impetus.kundera.persistence.jta.KunderaJTAUserTransaction.java
@Override public void begin() throws NotSupportedException, SystemException { log.info("beginning JTA transaction"); isTransactionInProgress = true;/* ww w . j a v a 2s . c o m*/ Transaction tx = threadLocal.get(); if (tx != null) { if ((tx.getStatus() == Status.STATUS_MARKED_ROLLBACK)) { throw new NotSupportedException("Nested Transaction not supported!"); } } Integer timer = timerThead.get(); threadLocal.set(new KunderaTransaction(timer != null ? timer : DEFAULT_TIME_OUT)); }
From source file:com.impetus.kundera.persistence.jta.KunderaJTAUserTransaction.java
@Override public int getStatus() throws SystemException { Transaction tx = threadLocal.get(); if (tx == null) { return Status.STATUS_NO_TRANSACTION; }/*from w ww . j av a 2s . com*/ return tx.getStatus(); }
From source file:org.grails.orm.hibernate.GrailsSessionContext.java
protected void registerJtaSynchronization(Session session, 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(session); if (jtaTm == null) { return;/*from ww w. j av a 2s . c o m*/ } try { Transaction jtaTx = jtaTm.getTransaction(); if (jtaTx == null) { return; } int jtaStatus = jtaTx.getStatus(); if (jtaStatus != Status.STATUS_ACTIVE && jtaStatus != Status.STATUS_MARKED_ROLLBACK) { return; } LOG.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(session); } else { // it's up to the caller to manage concurrent sessions // holderToUse.addSession(session); } jtaTx.registerSynchronization( new SpringJtaSynchronizationAdapter(createSpringSessionSynchronization(holderToUse), 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); } }
From source file:org.apache.ode.scheduler.simple.SimpleScheduler.java
public boolean isTransacted() { TransactionManager txm = _txm;/*w w w . j a v a2 s. c om*/ if (txm == null) { throw new ContextException("Cannot locate the transaction manager; the server might be shutting down."); } try { Transaction tx = txm.getTransaction(); return (tx != null && tx.getStatus() != Status.STATUS_NO_TRANSACTION); } catch (SystemException e) { throw new ContextException("Internal Error: Could not obtain transaction status."); } }
From source file:org.apache.ojb.broker.core.PersistenceBrokerFactorySyncImpl.java
private Transaction searchForValidTx() throws SystemException { Transaction tx = txMan.getTransaction(); if (tx != null) { int status = tx.getStatus(); if (status != Status.STATUS_ACTIVE && status != Status.STATUS_NO_TRANSACTION) { throw new PBFactoryException("Transaction synchronization failed - wrong" + " status of external JTA tx. Expected was an 'active' or 'no transaction'" + ", found status is '" + getStatusFlagAsString(status) + "'"); }//from w ww .j av a 2 s . c o m } return tx; }
From source file:org.apache.ojb.odmg.JTATxManager.java
/** * Do synchronization of the given J2EE ODMG Transaction *//*from ww w . j a v a 2 s .com*/ private void registerSynchronization(TransactionImpl odmgTrans, Transaction transaction) { // todo only need for development if (odmgTrans == null || transaction == null) { log.error("One of the given parameters was null --> cannot do synchronization!" + " omdg transaction was null: " + (odmgTrans == null) + ", external transaction was null: " + (transaction == null)); return; } int status = -1; // default status. try { status = transaction.getStatus(); if (status != Status.STATUS_ACTIVE) { throw new OJBRuntimeException( "Transaction synchronization failed - wrong status of external container tx: " + getStatusString(status)); } } catch (SystemException e) { throw new OJBRuntimeException("Can't read status of external tx", e); } try { //Sequence of the following method calls is significant // 1. register the synchronization with the ODMG notion of a transaction. transaction.registerSynchronization((J2EETransactionImpl) odmgTrans); // 2. mark the ODMG transaction as being in a JTA Transaction // Associate external transaction with the odmg transaction. txRepository.set(new TxBuffer(odmgTrans, transaction)); } catch (Exception e) { log.error("Cannot associate PersistenceBroker with running Transaction", e); throw new OJBRuntimeException( "Transaction synchronization failed - wrong status of external container tx", e); } }
From source file:org.apache.ojb.odmg.JTATxManager.java
/** * Abort an active extern transaction associated with the given PB. *//*from w ww . j ava 2 s . co m*/ public void abortExternalTx(TransactionImpl odmgTrans) { if (log.isDebugEnabled()) log.debug("abortExternTransaction was called"); if (odmgTrans == null) return; TxBuffer buf = (TxBuffer) txRepository.get(); Transaction extTx = buf != null ? buf.getExternTx() : null; try { if (extTx != null && extTx.getStatus() == Status.STATUS_ACTIVE) { if (log.isDebugEnabled()) { log.debug("Set extern transaction to rollback"); } extTx.setRollbackOnly(); } } catch (Exception ignore) { } txRepository.set(null); }
From source file:org.apache.openjpa.kernel.AbstractBrokerFactory.java
/** * Find a managed runtime broker associated with the * current transaction, or returns null if none. *//*w w w. j a v a2s .com*/ protected Broker findTransactionalBroker(String user, String pass) { Transaction trans; ManagedRuntime mr = _conf.getManagedRuntimeInstance(); Object txKey; try { trans = mr.getTransactionManager().getTransaction(); txKey = mr.getTransactionKey(); if (trans == null || trans.getStatus() == Status.STATUS_NO_TRANSACTION || trans.getStatus() == Status.STATUS_UNKNOWN) return null; } catch (OpenJPAException ke) { throw ke; } catch (Exception e) { throw new GeneralException(e); } Collection<Broker> brokers = _transactional.get(txKey); if (brokers != null) { // we don't need to synchronize on brokers since one JTA transaction // can never be active on multiple concurrent threads. for (Broker broker : brokers) { if (StringUtils.equals(broker.getConnectionUserName(), user) && StringUtils.equals(broker.getConnectionPassword(), pass)) return broker; } } return null; }