use of org.apache.cayenne.testdo.mt.ClientMtTable1 in project cayenne by apache.
the class CayenneContextWithDataContextIT method testPreRemoveCallback.
@Test
public void testPreRemoveCallback() throws Exception {
// an exception was triggered within POST_LOAD callback
LifecycleCallbackRegistry callbackRegistry = clientServerChannel.getEntityResolver().getCallbackRegistry();
final boolean[] flag = new boolean[1];
try {
callbackRegistry.addListener(MtTable1.class, new LifecycleListener() {
public void postLoad(Object entity) {
}
public void postPersist(Object entity) {
}
public void postRemove(Object entity) {
}
public void postUpdate(Object entity) {
}
public void postAdd(Object entity) {
}
public void preRemove(Object entity) {
flag[0] = true;
}
public void preUpdate(Object entity) {
}
public void prePersist(Object entity) {
}
});
ClientMtTable1 object = clientContext.newObject(ClientMtTable1.class);
assertFalse(flag[0]);
clientContext.commitChanges();
assertFalse(flag[0]);
clientContext.deleteObjects(object);
clientContext.commitChanges();
assertTrue(flag[0]);
} finally {
callbackRegistry.clear();
}
}
use of org.apache.cayenne.testdo.mt.ClientMtTable1 in project cayenne by apache.
the class CayenneContextWithDataContextIT method testPrefetchingToOne.
@Test
public void testPrefetchingToOne() throws Exception {
createTwoMtTable1sAnd2sDataSet();
final ObjectId prefetchedId = new ObjectId("MtTable1", MtTable1.TABLE1_ID_PK_COLUMN, 1);
SelectQuery q = new SelectQuery(ClientMtTable2.class);
q.addOrdering(ClientMtTable2.GLOBAL_ATTRIBUTE_PROPERTY, SortOrder.ASCENDING);
q.addPrefetch(ClientMtTable2.TABLE1_PROPERTY);
final List<ClientMtTable2> results = clientContext.performQuery(q);
clientServerInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertEquals(2, results.size());
for (ClientMtTable2 o : results) {
assertEquals(PersistenceState.COMMITTED, o.getPersistenceState());
assertSame(clientContext, o.getObjectContext());
ClientMtTable1 o1 = o.getTable1();
assertNotNull(o1);
assertEquals(PersistenceState.COMMITTED, o1.getPersistenceState());
assertSame(clientContext, o1.getObjectContext());
assertEquals(prefetchedId, o1.getObjectId());
}
}
});
}
use of org.apache.cayenne.testdo.mt.ClientMtTable1 in project cayenne by apache.
the class CayenneContextWithDataContextIT method testCreateBadFault.
@Test
public void testCreateBadFault() throws Exception {
tMtTable1.insert(1, "g1", "s1");
ObjectId id = new ObjectId("MtTable1", MtTable1.TABLE1_ID_PK_COLUMN, 2);
Object fault = clientContext.createFault(id);
assertTrue(fault instanceof ClientMtTable1);
ClientMtTable1 o = (ClientMtTable1) fault;
// try tripping fault
try {
o.getGlobalAttribute1();
fail("resolving bad fault should've thrown");
} catch (FaultFailureException e) {
// expected
}
}
use of org.apache.cayenne.testdo.mt.ClientMtTable1 in project cayenne by apache.
the class NestedCayenneContextIT method testDeleteNew.
@Test
public void testDeleteNew() throws Exception {
ObjectContext child = runtime.newContext(clientContext);
ClientMtTable1 a = clientContext.newObject(ClientMtTable1.class);
clientContext.commitChanges();
ClientMtTable2 p = child.newObject(ClientMtTable2.class);
ClientMtTable1 aChild = (ClientMtTable1) Cayenne.objectForPK(child, a.getObjectId());
p.setGlobalAttribute("X");
aChild.addToTable2Array(p);
child.commitChangesToParent();
child.deleteObjects(p);
aChild.removeFromTable2Array(p);
child.commitChangesToParent();
}
use of org.apache.cayenne.testdo.mt.ClientMtTable1 in project cayenne by apache.
the class NestedCayenneContextIT method testPrefetchingToOne.
@Test
public void testPrefetchingToOne() throws Exception {
final ClientMtTable1 mt11 = clientContext.newObject(ClientMtTable1.class);
clientContext.newObject(ClientMtTable1.class);
ClientMtTable2 mt21 = clientContext.newObject(ClientMtTable2.class);
ClientMtTable2 mt22 = clientContext.newObject(ClientMtTable2.class);
mt21.setTable1(mt11);
mt22.setTable1(mt11);
clientContext.commitChanges();
final ObjectContext child = runtime.newContext(clientContext);
SelectQuery<ClientMtTable2> q = new SelectQuery<ClientMtTable2>(ClientMtTable2.class);
q.addPrefetch(ClientMtTable2.TABLE1_PROPERTY);
final List<ClientMtTable2> results = child.select(q);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertEquals(2, results.size());
Iterator<?> it = results.iterator();
while (it.hasNext()) {
ClientMtTable2 o = (ClientMtTable2) it.next();
assertEquals(PersistenceState.COMMITTED, o.getPersistenceState());
assertSame(child, o.getObjectContext());
ClientMtTable1 o1 = o.getTable1();
assertNotNull(o1);
assertEquals(PersistenceState.COMMITTED, o1.getPersistenceState());
assertSame(child, o1.getObjectContext());
assertEquals(mt11.getObjectId(), o1.getObjectId());
}
}
});
}
Aggregations