use of org.jpox.samples.models.company.Person in project tests by datanucleus.
the class PersistenceTest method testPersistDuplicates.
/**
* Test of persistence of more than 1 app id objects with the same "id".
*/
public void testPersistDuplicates() {
// Persist an object with same PK as the setUp object
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Person p2 = new Person(2, "Mickey", "Mouse", "micket.mouse@warnerbros.com");
p2.setGlobalNum("1");
pm.makePersistent(p2);
tx.commit();
fail("Was allowed to persist two application-identity objects with the same identity");
} catch (Exception e) {
// Expected
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
}
use of org.jpox.samples.models.company.Person in project tests by datanucleus.
the class PersistenceTest method testUpdateFieldNoLongerNull.
/**
* Test that adds a new attribute to spreadsheet
*/
public void testUpdateFieldNoLongerNull() {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Person p = (Person) pm.getObjectById(id1);
p.setEmailAddress("ppp");
tx.commit();
pm.close();
pm = pmf.getPersistenceManager();
tx = pm.currentTransaction();
tx.begin();
Person p1 = (Person) pm.getObjectById(id1);
assertEquals("ppp", p1.getEmailAddress());
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
}
use of org.jpox.samples.models.company.Person in project tests by datanucleus.
the class ApplicationIdPersistenceTest method testInsert.
public void testInsert() throws Exception {
try {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Person p = new Person();
p.setPersonNum(1);
p.setGlobalNum("1");
p.setFirstName("Bugs");
p.setLastName("Bunny");
Person p2 = new Person();
p2.setPersonNum(2);
p2.setGlobalNum("2");
p2.setFirstName("My");
p2.setLastName("Friend");
p.setBestFriend(p2);
pm.makePersistent(p);
tx.commit();
} catch (Exception e) {
e.printStackTrace();
fail("Exception thrown when running test " + e.getMessage());
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
} finally {
clean(Person.class);
}
}
use of org.jpox.samples.models.company.Person in project tests by datanucleus.
the class JDOQLBasicTest method setUp.
protected void setUp() throws Exception {
super.setUp();
// Delete the file so each test starts from nothing
File file = new File("test.xml");
if (file.exists()) {
file.delete();
}
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Person p = new Person();
p.setPersonNum(4);
p.setGlobalNum("4");
p.setFirstName("Bugs");
p.setLastName("Bunny");
pm.makePersistent(p);
Person bugs = p;
// id[0] = pm.getObjectId(p);
p = new Person();
p.setPersonNum(5);
p.setGlobalNum("5");
p.setFirstName("Ana");
p.setLastName("Hick");
pm.makePersistent(p);
// id[1] = pm.getObjectId(p);
p = new Person();
p.setPersonNum(3);
p.setGlobalNum("3");
p.setFirstName("Lami");
p.setLastName("Puxa");
p.setBestFriend(bugs);
pm.makePersistent(p);
// id[2] = pm.getObjectId(p);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
}
use of org.jpox.samples.models.company.Person in project tests by datanucleus.
the class JDOQLBasicTest method testQueryWithOneToOneParameterInputAsNull.
/**
* test query with use of parameter for a 1-1 relation, input as null.
* This tests the SQL generation of the query since, while there is a parameter, we don't want it
* to appear in the SQL as "COL == ?", since the value of the paramerter is null, hence the SQL should
* be "COL IS NULL".
*/
public void testQueryWithOneToOneParameterInputAsNull() {
try {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Person p1 = new Person(1, "Bugs", "Bunny", "bugs.bunny@warnerbros.com");
Person p2 = new Person(2, "Road", "Runner", "road.runner@warnerbros.com");
Person p3 = new Person(3, "Bart", "Simpson", "bart.simpson@simpsons.com");
p1.setBestFriend(p2);
p2.setBestFriend(p3);
pm.makePersistent(p1);
pm.makePersistent(p2);
pm.makePersistent(p3);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
pm = pmf.getPersistenceManager();
tx = pm.currentTransaction();
try {
tx.begin();
Query q = pm.newQuery("SELECT FROM " + Person.class.getName() + " WHERE bestFriend == :param");
Collection c = (Collection) q.execute(null);
assertEquals(1, c.size());
Person p = (Person) c.iterator().next();
assertEquals("FirstName is incorrect", "Bart", p.getFirstName());
assertEquals("LastName is incorrect", "Simpson", p.getLastName());
tx.commit();
} finally {
if (tx.isActive()) {
pm.currentTransaction().rollback();
}
pm.close();
}
} finally {
CompanyHelper.clearCompanyData(pmf);
}
}
Aggregations