use of javax.jdo.Transaction in project tests by datanucleus.
the class OneOneTest method testPersistChildOnly.
/**
* Persist an object with an hierarchical mapped relation. When persisting the child object the parent object must
* be persisted *before*.
*/
public void testPersistChildOnly() {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Account dduck = new AccountWithPassword("dduck", "secret", null);
Person daffyDuck = new Person("Daffy", "Duck", "Daffy Duck", dduck, null, getDepartment(pm));
dduck.setPerson(daffyDuck);
pm.makePersistent(dduck);
helper.ids.add(pm.getObjectId(dduck));
helper.ids.add(pm.getObjectId(daffyDuck));
tx.commit();
pm.close();
// test
pm = pmf.getPersistenceManager();
tx = pm.currentTransaction();
tx.begin();
daffyDuck = pm.getObjectById(Person.class, "Daffy Duck");
assertNotNull(daffyDuck.getAccount());
assertEquals("dduck", daffyDuck.getAccount().getUid());
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
}
use of javax.jdo.Transaction in project tests by datanucleus.
the class TestHelper method tearDown.
public void tearDown(PersistenceManagerFactory pmf) throws Exception {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
for (Object id : ids) {
try {
pm.deletePersistent(pm.getObjectById(id));
} catch (Exception e) {
}
}
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
}
use of javax.jdo.Transaction in project tests by datanucleus.
the class TestHelper method setUp.
public void setUp(PersistenceManagerFactory pmf) throws Exception {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Company jdo = new Company("JDO Inc.");
pm.makePersistent(jdo);
Department engineering = new Department("Engineering", jdo);
Department sales = new Department("Sales", jdo);
pm.makePersistent(engineering);
pm.makePersistent(sales);
Account bbunny = new AccountWithPassword("bbunny", "secret", null);
Account ahicks = new Account("ahicks", null);
Account lpuxa = new AccountWithPassword("lpuxa", "secret", null);
Address bbAddress = new Address("B-City", "B-Street", null);
Address ahAddress = new Address("A-City", "A-Street", null);
Address lpAddress = new Address("L-City", "L-Street", null);
Person bugsBunny = new Person("Bugs", "Bunny", "Bugs Bunny", bbunny, bbAddress, engineering);
bbunny.setPerson(bugsBunny);
bbAddress.setPerson(bugsBunny);
engineering.getPersons().add(bugsBunny);
Person anaHicks = new Person("Ana", "Hicks", "Ana Hicks", ahicks, ahAddress, engineering);
ahicks.setPerson(anaHicks);
ahAddress.setPerson(anaHicks);
engineering.getPersons().add(anaHicks);
Person lamiPuxa = new Person("Lami", "Puxa", "Lami Puxa", lpuxa, lpAddress, sales);
lpuxa.setPerson(lamiPuxa);
lpAddress.setPerson(lamiPuxa);
sales.getPersons().add(lamiPuxa);
pm.makePersistent(bugsBunny);
pm.makePersistent(anaHicks);
pm.makePersistent(lamiPuxa);
ids.add(pm.getObjectId(bugsBunny));
ids.add(pm.getObjectId(anaHicks));
ids.add(pm.getObjectId(lamiPuxa));
ids.add(pm.getObjectId(engineering));
ids.add(pm.getObjectId(sales));
ids.add(pm.getObjectId(jdo));
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
}
use of javax.jdo.Transaction in project tests by datanucleus.
the class JDQLBasicTest method testBasicQuery.
public void testBasicQuery() {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Collection c = (Collection) pm.newQuery(Person.class).execute();
assertEquals(3, c.size());
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
}
use of javax.jdo.Transaction in project tests by datanucleus.
the class ManyOneTest method testUpdateField.
public void testUpdateField() {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Person bugs = pm.getObjectById(Person.class, "Bugs Bunny");
bugs.setFirstName("BBB");
tx.commit();
pm.close();
pm = pmf.getPersistenceManager();
tx = pm.currentTransaction();
tx.begin();
bugs = pm.getObjectById(Person.class, "Bugs Bunny");
assertEquals("BBB", bugs.getFirstName());
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
}
Aggregations