use of org.jpox.samples.models.company.Manager in project tests by datanucleus.
the class JDOQLBasicTest method testQueryWithNonNullFieldCondition.
/**
* test query with "field != null"
*/
public void testQueryWithNonNullFieldCondition() {
try {
Manager homer = new Manager(1, "Homer", "Simpson", "homer@simpson.com", 1, "serial 1");
Manager bart = new Manager(2, "Bart", "Simpson", "bart@simpson.com", 2, "serial 2");
Manager boss = new Manager(3, "Boss", "WakesUp", "boss@wakes.up", 4, "serial 3");
bart.setManager(homer);
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
pm.makePersistent(homer);
pm.makePersistent(bart);
pm.makePersistent(boss);
Object id = pm.getObjectId(bart);
tx.commit();
tx.begin();
Query q = pm.newQuery(Manager.class);
q.setFilter("this.manager != null");
Collection c = (Collection) q.execute();
assertEquals(1, c.size());
assertEquals(id, pm.getObjectId(c.iterator().next()));
// check again with null
q = pm.newQuery(Manager.class);
q.setFilter("this.manager == null");
c = (Collection) q.execute();
assertEquals(2, c.size());
tx.commit();
} finally {
if (tx.isActive()) {
pm.currentTransaction().rollback();
}
pm.close();
}
} finally {
CompanyHelper.clearCompanyData(pmf);
}
}
use of org.jpox.samples.models.company.Manager in project tests by datanucleus.
the class JDOQLBasicTest method testQueryUnboundVariablesInheritance1.
public void testQueryUnboundVariablesInheritance1() {
try {
Manager homer = new Manager(1, "Homer", "Simpson", "homer@simpson.com", 1, "serial 1");
Manager bart = new Manager(2, "Bart", "Simpson", "bart@simpson.com", 2, "serial 2");
Manager boss = new Manager(3, "Boss", "WakesUp", "boss@wakes.up", 4, "serial 3");
Manager boss2 = new Manager(4, "Boss", "WakesUp2", "boss2@wakes.up", 5, "serial 4");
Manager boss4 = new Manager(6, "Boss", "WakesUp4", "boss4@wakes.up", 7, "serial 6");
bart.addSubordinate(boss);
bart.addSubordinate(boss2);
homer.addSubordinate(boss4);
Department deptA = new Department("DeptA");
Department deptB = new Department("DeptB");
bart.addDepartment(deptB);
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
pm.makePersistent(bart);
pm.makePersistent(deptA);
pm.makePersistent(deptB);
tx.commit();
tx.begin();
Query q = pm.newQuery(Manager.class);
Collection c = q.filter("emp.lastName == \"WakesUp2\" && this.subordinates.contains(emp)").variables("Employee emp").imports("import org.jpox.samples.models.company.Employee").executeList();
assertEquals(1, c.size());
assertEquals(((Manager) c.iterator().next()).getFirstName(), "Bart");
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
} finally {
// Clean out our data
CompanyHelper.clearCompanyData(pmf);
}
}
use of org.jpox.samples.models.company.Manager in project tests by datanucleus.
the class JDOQLBasicTest method testKeepResultsQueryAfterQueryClose.
/**
* Test for the close of a Query and the availability of results.
*/
public void testKeepResultsQueryAfterQueryClose() {
try {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Manager homer = new Manager(1, "Homer", "Simpson", "homer@simpson.com", 1, "serial 1");
pm.makePersistent(homer);
pm.flush();
Query q = pm.newQuery(Manager.class);
List results = (List) q.execute();
assertFalse(results.isEmpty());
results.iterator().next();
q.closeAll();
assertFalse(results.iterator().hasNext());
try {
results.iterator().next();
fail("expected NoSuchElementException");
} catch (NoSuchElementException ex) {
// expected
}
tx.rollback();
} catch (Exception e) {
LOG.error("Exception during test", e);
fail("Exception thrown when trying to access QueryResult after closing the Query : " + e.getMessage());
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
} finally {
clean(Manager.class);
}
}
use of org.jpox.samples.models.company.Manager in project tests by datanucleus.
the class MultithreadPMTest method testEvictAllAndWrites.
/**
* Test changing the state
*/
public void testEvictAllAndWrites() {
Properties multiProps = new Properties();
multiProps.setProperty(PropertyNames.PROPERTY_MULTITHREADED, "true");
PersistenceManagerFactory myPMF = getPMF(1, multiProps);
try {
int THREAD_SIZE = 1000;
Thread[] threads = new Thread[THREAD_SIZE];
Thread[] threads2 = new Thread[THREAD_SIZE];
final PersistenceManager pm = myPMF.getPersistenceManager();
pm.currentTransaction().begin();
final Employee woody = new Employee(1, "Woody", "Woodpecker", "woody@woodpecker.com", 13, "serial 1", new Integer(10));
Manager bart = new Manager(2, "Bart", "Simpson", "bart@simpson.com", 2, "serial 2");
final Manager boss = new Manager(3, "Boss", "WakesUp", "boss@wakes.up", 4, "serial 3");
woody.setManager(bart);
pm.makePersistent(woody);
final Object id = pm.getObjectId(woody);
pm.currentTransaction().commit();
pm.currentTransaction().begin();
try {
for (int i = 0; i < THREAD_SIZE; i++) {
threads[i] = new Thread(new Runnable() {
public void run() {
pm.getObjectById(id, true);
woody.setLastName("name");
woody.setManager(boss);
}
});
}
for (int i = 0; i < THREAD_SIZE; i++) {
threads2[i] = new Thread(new Runnable() {
public void run() {
pm.evictAll();
}
});
}
for (int i = 0; i < THREAD_SIZE; i++) {
threads[i].start();
threads2[i].start();
}
for (int i = 0; i < THREAD_SIZE; i++) {
try {
threads[i].join();
threads2[i].join();
} catch (InterruptedException e) {
fail(e.getMessage());
}
}
} finally {
if (pm.currentTransaction().isActive()) {
pm.currentTransaction().rollback();
}
pm.close();
}
} finally {
CompanyHelper.clearCompanyData(myPMF);
myPMF.close();
}
}
use of org.jpox.samples.models.company.Manager in project tests by datanucleus.
the class MultithreadPMTest method testMultipleTransitionRead.
/**
* Test changing the state
*/
public void testMultipleTransitionRead() {
Properties multiProps = new Properties();
multiProps.setProperty(PropertyNames.PROPERTY_MULTITHREADED, "true");
PersistenceManagerFactory myPMF = getPMF(1, multiProps);
try {
int THREAD_SIZE = 1000;
Thread[] threads = new Thread[THREAD_SIZE];
PersistenceManager pm = myPMF.getPersistenceManager();
pm.currentTransaction().begin();
final Employee woody = new Employee(1, "Woody", "Woodpecker", "woody@woodpecker.com", 13, "serial 1", new Integer(10));
Manager bart = new Manager(2, "Bart", "Simpson", "bart@simpson.com", 2, "serial 2");
woody.setManager(bart);
pm.makePersistent(woody);
pm.currentTransaction().commit();
pm.currentTransaction().begin();
try {
for (int i = 0; i < THREAD_SIZE; i++) {
threads[i] = new Thread(new Runnable() {
public void run() {
woody.getLastName();
woody.getManager().getLastName();
}
});
}
for (int i = 0; i < THREAD_SIZE; i++) {
threads[i].start();
}
for (int i = 0; i < THREAD_SIZE; i++) {
try {
threads[i].join();
} catch (InterruptedException e) {
fail(e.getMessage());
}
}
} finally {
if (pm.currentTransaction().isActive()) {
pm.currentTransaction().rollback();
}
pm.close();
}
} finally {
CompanyHelper.clearCompanyData(myPMF);
myPMF.close();
}
}
Aggregations