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()); } }
/** * 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 boolean ensureDbInit() { Transaction tx = pm.currentTransaction(); boolean doCommit = false; if (!tx.isActive()) {
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(); } } }
public Object getCurrentTransaction() { Transaction t = pm.currentTransaction(); t.begin(); return t; }
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(); } }
public void close() { if (pm.currentTransaction().isActive()) { pm.currentTransaction().rollback(); } pm.close(); pm.getPersistenceManagerFactory().close(); }
public boolean hasTransaction() { return (this.persistenceManagerHolder != null && this.persistenceManagerHolder.getPersistenceManager() != null && this.persistenceManagerHolder.getPersistenceManager().currentTransaction().isActive()); }
private PersistenceManager openTransaction() { PersistenceManager pm = pmf.getPersistenceManager(); Transaction currentTransaction = pm.currentTransaction(); currentTransaction.begin(); return pm; }
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() { pm.currentTransaction().rollback(); TestTools.closePM(); pm = null; }
@After public void after() { if (pm != null && !pm.isClosed() && pm.currentTransaction().isActive()) { pm.currentTransaction().rollback(); } TestTools.closePM(); pm = null; TestTools.removeDb(); }
@Test public void testActivationOutsideTx2() { PersistenceManager pm = TestTools.openPM(); pm.currentTransaction().begin(); pm.currentTransaction().commit(); pm.close(); TestClass tc = new TestClass(); tc.setInt(5); tc.getInt(); }
@Test public void testSchemaName() { PersistenceManager pm = TestTools.openPM(); pm.currentTransaction().begin(); //create schema ZooClass s01 = ZooJdoHelper.schema(pm).addClass(TestClass.class); assertEquals(TestClass.class.getName(), s01.getName()); TestTools.closePM(); }
@Test public void testQuery() { PersistenceManager pm = TestTools.openPM(); pm.currentTransaction().begin(); Query q = pm.newQuery(); assertEquals(pm, q.getPersistenceManager()); assertFalse(q.isUnmodifiable()); q.setClass(TestClass.class); testDeclarative(q); testString(q); TestTools.closePM(pm); }
@Test public void testQueryOfExtent() { PersistenceManager pm = TestTools.openPM(); pm.currentTransaction().begin(); Extent<?> ext = pm.getExtent(TestClass.class); Query q = pm.newQuery(ext); assertEquals(pm, q.getPersistenceManager()); assertFalse(q.isUnmodifiable()); testDeclarative(q); testString(q); TestTools.closePM(pm); }