List of usage examples for javax.transaction Status STATUS_NO_TRANSACTION
int STATUS_NO_TRANSACTION
To view the source code for javax.transaction Status STATUS_NO_TRANSACTION.
Click Source Link
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 ww w . ja va2 s .co m } return tx; }
From source file:org.apache.ojb.odmg.JTATxManager.java
private static String getStatusString(int status) { switch (status) { case Status.STATUS_ACTIVE: return "STATUS_ACTIVE"; case Status.STATUS_COMMITTED: return "STATUS_COMMITTED"; case Status.STATUS_COMMITTING: return "STATUS_COMMITTING"; case Status.STATUS_MARKED_ROLLBACK: return "STATUS_MARKED_ROLLBACK"; case Status.STATUS_NO_TRANSACTION: return "STATUS_NO_TRANSACTION"; case Status.STATUS_PREPARED: return "STATUS_PREPARED"; case Status.STATUS_PREPARING: return "STATUS_PREPARING"; case Status.STATUS_ROLLEDBACK: return "STATUS_ROLLEDBACK"; case Status.STATUS_ROLLING_BACK: return "STATUS_ROLLING_BACK"; case Status.STATUS_UNKNOWN: return "STATUS_UNKNOWN"; default:/*from w w w.j a v a2s. co m*/ return "NO STATUS FOUND"; } }
From source file:org.apache.ojb.odmg.TransactionImpl.java
/** * cleanup tx and prepare for reuse// w w w .j a v a 2 s . c om */ protected void refresh() { if (log.isDebugEnabled()) log.debug("Refresh this transaction for reuse: " + this); try { // we reuse ObjectEnvelopeTable instance objectEnvelopeTable.refresh(); } catch (Exception e) { if (log.isDebugEnabled()) { log.debug("error closing object envelope table : " + e.getMessage()); e.printStackTrace(); } } cleanupBroker(); // clear the temporary used named roots map // we should do that, because same tx instance // could be used several times broker = null; clearRegistrationList(); unmaterializedLocks.clear(); txStatus = Status.STATUS_NO_TRANSACTION; }
From source file:org.apache.ojb.odmg.TransactionImpl.java
/** * Abort and close the transaction. Calling abort abandons all persistent * object modifications and releases the associated locks. Aborting a * transaction does not restore the state of modified transient objects *///from w w w . ja v a2 s . c o m public void abort() { /* do nothing if already rolledback */ if (txStatus == Status.STATUS_NO_TRANSACTION || txStatus == Status.STATUS_UNKNOWN || txStatus == Status.STATUS_ROLLEDBACK) { log.info("Nothing to abort, tx is not active - status is " + TxUtil.getStatusString(txStatus)); return; } // check status of tx if (txStatus != Status.STATUS_ACTIVE && txStatus != Status.STATUS_PREPARED && txStatus != Status.STATUS_MARKED_ROLLBACK) { throw new IllegalStateException( "Illegal state for abort call, state was '" + TxUtil.getStatusString(txStatus) + "'"); } if (log.isEnabledFor(Logger.INFO)) { log.info("Abort transaction was called on tx " + this); } try { try { doAbort(); } catch (Exception e) { log.error("Error while abort transaction, will be skipped", e); } // used in managed environments, ignored in non-managed this.implementation.getTxManager().abortExternalTx(this); try { if (hasBroker() && getBroker().isInTransaction()) { getBroker().abortTransaction(); } } catch (Exception e) { log.error("Error while do abort used broker instance, will be skipped", e); } } finally { txStatus = Status.STATUS_ROLLEDBACK; // cleanup things, e.g. release all locks doClose(); } }
From source file:org.apache.openjpa.kernel.AbstractBrokerFactory.java
/** * Find a managed runtime broker associated with the * current transaction, or returns null if none. *///from w w w.jav a2 s . c o m 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; }
From source file:org.apache.openjpa.kernel.AbstractBrokerFactory.java
/** * Synchronize the given broker with a managed transaction, * optionally starting one if none is in progress. * * @return true if synched with transaction, false otherwise *//*ww w . jav a 2 s.com*/ boolean syncWithManagedTransaction(BrokerImpl broker, boolean begin) { Transaction trans; try { ManagedRuntime mr = broker.getManagedRuntime(); TransactionManager tm = mr.getTransactionManager(); if (tm == null) { throw new InternalException(_loc.get("null-transactionmanager", mr)); } trans = tm.getTransaction(); if (trans != null && (trans.getStatus() == Status.STATUS_NO_TRANSACTION || trans.getStatus() == Status.STATUS_UNKNOWN)) trans = null; if (trans == null && begin) { tm.begin(); trans = tm.getTransaction(); } else if (trans == null) return false; // synch broker and trans trans.registerSynchronization(broker); // we don't need to synchronize on brokers or guard against multiple // threads using the same trans since one JTA transaction can never // be active on multiple concurrent threads. Object txKey = mr.getTransactionKey(); Collection<Broker> brokers = _transactional.get(txKey); if (brokers == null) { brokers = new ArrayList<Broker>(2); _transactional.put(txKey, brokers); trans.registerSynchronization(new RemoveTransactionSync(txKey)); } brokers.add(broker); return true; } catch (OpenJPAException ke) { throw ke; } catch (Exception e) { throw new GeneralException(e); } }
From source file:org.apache.openjpa.kernel.BrokerImpl.java
/** * Mark the current transaction as rollback-only. *//*from ww w .j ava 2s. c om*/ private void setRollbackOnlyInternal(Throwable cause) { try { javax.transaction.Transaction trans = _runtime.getTransactionManager().getTransaction(); if (trans == null) throw new InvalidStateException(_loc.get("null-trans")); // ensure tran is in a valid state to accept the setRollbackOnly int tranStatus = trans.getStatus(); if ((tranStatus != Status.STATUS_NO_TRANSACTION) && (tranStatus != Status.STATUS_ROLLEDBACK) && (tranStatus != Status.STATUS_COMMITTED)) _runtime.setRollbackOnly(cause); else if (_log.isTraceEnabled()) _log.trace(_loc.get("invalid-tran-status", Integer.valueOf(tranStatus), "setRollbackOnly")); } catch (OpenJPAException ke) { throw ke; } catch (Exception e) { throw new GeneralException(e); } }
From source file:org.commonjava.maven.galley.cache.infinispan.FastLocalCacheProvider.java
private void lockByISPN(final CacheInstance<String, String> cacheInstance, final ConcreteResource resource, final LockLevel level) throws SystemException, NotSupportedException, IOException, InterruptedException { //FIXME: This whole method is not thread-safe, especially for the lock state of the path, so the caller needs to take care // We need to think about the way of the ISPN lock and wait. If directly // use the nfsOwnerCache.lock but not consider if the lock has been acquired by another // thread, the ISPN lock will fail with a RuntimeException. So we need to let the // thread wait for the ISPN lock until it's released by the thread holds it. It's // like "tryLock" and "wait" of a thread lock. CacheInstance<String, String> cacheInst = cacheInstance; if (cacheInst == null) { cacheInst = nfsOwnerCache;/* w w w .ja va 2 s . c o m*/ } final String path = getKeyForResource(resource); fileManager.lock(new File(path), Long.MAX_VALUE, level); // Some consideration about the thread "re-entrant" for waiting here. If it is the same // thread, will not wait. waitForISPNLock(resource, cacheInst.isLocked(path), DEFAULT_WAIT_FOR_TRANSFER_LOCK_MILLIS); if (cacheInst.getTransactionStatus() == Status.STATUS_NO_TRANSACTION) { cacheInst.beginTransaction(); logger.trace("Transaction started for path {} with resource {}", path, resource); } if (!cacheInst.isLocked(path) && isTxActive(cacheInstance)) { cacheInst.lock(path); // Increment a file counter to notify that there is a file operation with ISPN lock now in this ISPN TX final int counter = getFileCounter().incrementAndGet(); logger.trace("ISPN locked once more, path: {}, resource {}, file counter: {}", path, resource, counter); } }
From source file:org.compass.core.transaction.AbstractJTATransaction.java
public void begin(InternalCompassSession session, TransactionManager transactionManager) throws CompassException { try {/*w w w . ja v a 2 s. com*/ this.session = session; controllingNewTransaction = true; newTransaction = ut.getStatus() == Status.STATUS_NO_TRANSACTION; if (newTransaction) { if (log.isDebugEnabled()) { log.debug("Beginning new JTA transaction, and a new compass transaction on thread [" + Thread.currentThread().getName() + "]"); } session.getSearchEngine().begin(); int timeout = session.getSettings() .getSettingAsInt(CompassEnvironment.Transaction.TRANSACTION_TIMEOUT, -1); if (timeout != -1) { ut.setTransactionTimeout(timeout); } ut.begin(); } else { // joining an exisiting transaction session.getSearchEngine().begin(); if (log.isDebugEnabled()) { log.debug("Joining an existing JTA transaction, starting a new compass transaction on thread [" + Thread.currentThread().getName() + "] with status [" + ut.getStatus() + "]"); } } javax.transaction.Transaction tx = transactionManager.getTransaction(); doBindToTransaction(tx, session, newTransaction); } catch (Exception e) { throw new TransactionException("Begin failed with exception", e); } setBegun(true); }
From source file:org.dhatim.db.JndiDataSourceTest.java
@Test public void test_jta_new_transaction() throws Exception { when(connection.getAutoCommit()).thenReturn(true); when(transaction.getStatus()).thenReturn(Status.STATUS_NO_TRANSACTION); executeSmooks("jta", "test_jta_new_transaction", REPORT); verify(dataSource, atLeastOnce()).getConnection(); verify(transaction).begin();//from www. ja v a 2 s . c o m verify(connection).setAutoCommit(false); verify(transaction).commit(); verify(connection).close(); verify(transaction, never()).rollback(); verify(connection, never()).commit(); verify(connection, never()).rollback(); }