/** * 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; }
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(); } } }
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(); }
@Override public void beginTransaction() { if (!manager.currentTransaction().isActive()) { manager.currentTransaction().begin(); } // if } // beginTransaction()
private PersistenceManager openTransaction() { PersistenceManager pm = pmf.getPersistenceManager(); Transaction currentTransaction = pm.currentTransaction(); currentTransaction.begin(); return pm; }
@Before public void before() { TestTools.createDb(); TestTools.defineSchema(TestClass.class); pm = TestTools.openPM(); pm.currentTransaction().begin(); }
@Before public void before() { TestTools.createDb(); TestTools.defineSchema(TestClass.class); pm = TestTools.openPM(); pm.currentTransaction().begin(); }
@Before public void before() { TestTools.createDb(); TestTools.defineSchema(TestClass.class); pm = TestTools.openPM(); pm.currentTransaction().begin(); }
@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(); }
@Before public void before() { TestTools.createDb(); TestTools.closePM(); pm = TestTools.openPM(); pm.currentTransaction().begin(); ZooJdoHelper.schema(pm).addClass(TestClassTiny.class); ZooJdoHelper.schema(pm).addClass(TestClassTiny2.class); pm.currentTransaction().commit(); pm.currentTransaction().begin(); }
private void checkResults(String queryFilter, int nRes) { pm.currentTransaction().commit(); pm.currentTransaction().begin(); Query q = pm.newQuery(TestClass.class, queryFilter); Collection<?> c = (Collection<?>) q.execute(); int n = 0; for (Object o: c) { assertNotNull(o); n++; } assertEquals(nRes, n); }
@Test public void testSchemaCreationWithNullArray() { PersistenceManager pm = TestTools.openPM(props); pm.currentTransaction().begin(); TestClassWithArray t = new TestClassWithArray(); t.array = null; pm.makePersistent(t); pm.currentTransaction().commit(); TestTools.closePM(); }
@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 testThatPrintingDoesntThrowExceptions() { pm.currentTransaction().commit(); pm.currentTransaction().begin(); ZooClassDef def = getDef(TestClass.class); QueryParserV3 qp = new QueryParserV3( "(_int > 1 && _int < 52) || _int > 50", def, null, null, 0, Long.MAX_VALUE); QueryTreeNode qtn = qp.parseQuery(); assertNotNull(qtn.print()); }
@Test public void testThatPrintingDoesntThrowExceptions() { pm.currentTransaction().commit(); pm.currentTransaction().begin(); ZooClassDef def = getDef(TestClass.class); QueryParser qp = new QueryParser("(_int > 1 && _int < 52) || _int > 50", def, null, null); QueryTreeNode qtn = qp.parseQuery(); assertNotNull(qtn.print()); } }
@Test public void testSchemaCreationHierarchy() { PersistenceManager pm = TestTools.openPM(props); pm.currentTransaction().begin(); pm.makePersistent(new TestClassTiny()); pm.makePersistent(new TestClassTiny2()); pm.currentTransaction().commit(); 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); }