/** * @return true if there is an active transaction. If the current transaction * is either committed or rolled back it returns false */ @Override public boolean isActiveTransaction() { if (currentTransaction == null) { return false; } return currentTransaction.isActive(); }
throw e; if (!currentTransaction.isActive()) { RuntimeException e = new RuntimeException("commitTransaction was called but openTransactionCalls = " + openTrasactionCalls + ". This probably indicates that there are unbalanced " + debugLog("Commit transaction: count = " + openTrasactionCalls + ", isactive "+ currentTransaction.isActive()); if ((openTrasactionCalls == 0) && currentTransaction.isActive()) { transactionStatus = TXN_STATUS.COMMITED; currentTransaction.commit();
/** * Opens a new one or the one already created Every call of this function must * have corresponding commit or rollback function call * * @return an active transaction */ @Override public boolean openTransaction() { openTrasactionCalls++; if (openTrasactionCalls == 1) { currentTransaction = pm.currentTransaction(); currentTransaction.begin(); transactionStatus = TXN_STATUS.OPEN; } else { // openTransactionCalls > 1 means this is an interior transaction // We should already have a transaction created that is active. if ((currentTransaction == null) || (!currentTransaction.isActive())){ throw new RuntimeException("openTransaction called in an interior" + " transaction scope, but currentTransaction is not active."); } } boolean result = currentTransaction.isActive(); debugLog("Open transaction: count = " + openTrasactionCalls + ", isActive = " + result); return result; }
private void prepareQuotes() throws SQLException { if (dbType == DatabaseProduct.MYSQL) { assert pm.currentTransaction().isActive(); JDOConnection jdoConn = pm.getDataStoreConnection(); Statement statement = null; try { statement = ((Connection)jdoConn.getNativeConnection()).createStatement(); statement.execute("SET @@session.sql_mode=ANSI_QUOTES"); } finally { if(statement != null){ statement.close(); } jdoConn.close(); } } }
/** * This run the necessary logic to prepare for queries. It should be called once, after the * txn on DataNucleus connection is opened, and before any queries are issued. What it does * currently is run db-specific logic, e.g. setting ansi quotes mode for MySQL. The reason it * must be used inside of the txn is connection pooling; there's no way to guarantee that the * effect will apply to the connection that is executing the queries otherwise. */ public void prepareTxn() throws MetaException { if (dbType != DatabaseProduct.MYSQL) return; try { assert pm.currentTransaction().isActive(); // must be inside tx together with queries executeNoResult("SET @@session.sql_mode=ANSI_QUOTES"); } catch (SQLException sqlEx) { throw new MetaException("Error setting ansi quotes: " + sqlEx.getMessage()); } }
if (currentTransaction != null && currentTransaction.isActive()) { throw rollbackEx; // Throw if the tx wasn't rolled back.
private boolean ensureDbInit() { Transaction tx = pm.currentTransaction(); boolean doCommit = false; if (!tx.isActive()) { tx.begin(); doCommit = true;
private boolean runTestQuery() { Transaction tx = pm.currentTransaction(); boolean doCommit = false; if (!tx.isActive()) { tx.begin(); doCommit = true; } Query query = null; // Run a self-test query. If it doesn't work, we will self-disable. What a PITA... String selfTestQuery = "select \"DB_ID\" from " + DBS + ""; try { prepareTxn(); query = pm.newQuery("javax.jdo.query.SQL", selfTestQuery); query.execute(); return true; } catch (Throwable t) { doCommit = false; LOG.warn("Self-test query [" + selfTestQuery + "] failed; direct SQL is disabled", t); tx.rollback(); return false; } finally { if (doCommit) { tx.commit(); } if (query != null) { query.closeAll(); } } }
/** * @return true if there is an active transaction. If the current transaction * is either committed or rolled back it returns false */ public boolean isActiveTransaction() { if (currentTransaction == null) { return false; } return currentTransaction.isActive(); }
/** * @return true if there is an active transaction. If the current transaction * is either committed or rolled back it returns false */ @Override public boolean isActiveTransaction() { if (currentTransaction == null) { return false; } return currentTransaction.isActive(); }
/** * @return true if there is an active transaction. If the current transaction * is either committed or rolled back it returns false */ public boolean isActiveTransaction() { if (currentTransaction == null) { return false; } return currentTransaction.isActive(); }
/** * @return true if there is an active transaction. If the current transaction * is either committed or rolled back it returns false */ public boolean isActiveTransaction() { if (currentTransaction == null) { return false; } return currentTransaction.isActive(); }
public void startTransaction() { final javax.jdo.Transaction transaction = persistenceManager.currentTransaction(); if (transaction.isActive()) { throw new IllegalStateException("Transaction already active"); } transaction.begin(); }
public void endTransaction() { final javax.jdo.Transaction transaction = persistenceManager.currentTransaction(); if (transaction.isActive()) { transaction.commit(); } }
public void abortTransaction() { final javax.jdo.Transaction transaction = persistenceManager.currentTransaction(); if (transaction.isActive()) { transaction.rollback(); } }
/** * Method to transition to write-field state. * @param sm StateManager. * @return new LifeCycle state. */ public LifeCycleState transitionWriteField(StateManager sm) { Transaction tx = sm.getPersistenceManager().currentTransaction(); return changeState(sm, tx.isActive() ? P_DIRTY : P_NONTRANS); }
public boolean hasTransaction() { return (this.persistenceManagerHolder != null && this.persistenceManagerHolder.getPersistenceManager() != null && this.persistenceManagerHolder.getPersistenceManager().currentTransaction().isActive()); }
private static void safeClose(PersistenceManagerFactory pmf, PersistenceManager pm) { if (pm != null) { if (pm.currentTransaction().isActive()) { pm.currentTransaction().rollback(); } pm.close(); } if (pmf != null) { pmf.close(); } }
private static void closePM(PersistenceManager pm) { if (!pm.isClosed()) { if (pm.currentTransaction().isActive()) { pm.currentTransaction().rollback(); } pm.close(); } }
@After public void after() { if (pm != null && !pm.isClosed() && pm.currentTransaction().isActive()) { pm.currentTransaction().rollback(); } TestTools.closePM(); pm = null; TestTools.removeDb(); }