use of org.apache.cayenne.testdo.mt.MtTable1 in project cayenne by apache.
the class CayenneContextRelationshipsIT method testLostUncommittedToOneModifications_Server.
@Test
public void testLostUncommittedToOneModifications_Server() throws Exception {
tMtTable1.insert(1, "G1", "S1");
tMtTable1.insert(2, "G2", "S2");
tMtTable2.insert(33, 1, "GX");
MtTable2 o = Cayenne.objectForPK(serverContext, MtTable2.class, 33);
MtTable1 r2 = Cayenne.objectForPK(serverContext, MtTable1.class, 2);
MtTable1 r1 = o.getTable1();
o.setTable1(r2);
assertSame(r2, o.getTable1());
assertFalse(r1.getTable2Array().contains(o));
assertSame(r2, o.getTable1());
}
use of org.apache.cayenne.testdo.mt.MtTable1 in project cayenne by apache.
the class CayenneContextWithDataContextIT method testPostAddOnObjectCallback.
@Test
public void testPostAddOnObjectCallback() throws Exception {
final DataContext serverContext = (DataContext) clientServerChannel.getParentChannel();
LifecycleCallbackRegistry callbackRegistry = serverContext.getEntityResolver().getCallbackRegistry();
try {
callbackRegistry.addCallback(LifecycleEvent.POST_ADD, MtTable1.class, "prePersistMethod");
final Persistent clientObject = clientContext.newObject(ClientMtTable1.class);
clientContext.commitChanges();
new ParallelTestContainer() {
@Override
protected void assertResult() {
// find peer
MtTable1 peer = (MtTable1) serverContext.getGraphManager().getNode(clientObject.getObjectId());
assertNotNull(peer);
assertTrue(peer.isPrePersisted());
}
}.runTest(1000);
} finally {
callbackRegistry.clear();
}
}
use of org.apache.cayenne.testdo.mt.MtTable1 in project cayenne by apache.
the class ClientServerChannelQueryIT method testSelectQueryOrdering.
@Test
public void testSelectQueryOrdering() throws Exception {
createTwoMtTable1sAnd2sDataSet();
ObjectSelect q = ObjectSelect.query(MtTable1.class).orderBy(ClientMtTable1.GLOBAL_ATTRIBUTE1.asc());
List<?> results = context.performQuery(q);
assertEquals(2, results.size());
ClientMtTable1 o1 = (ClientMtTable1) results.get(0);
ClientMtTable1 o2 = (ClientMtTable1) results.get(1);
assertTrue(o1.getGlobalAttribute1().compareTo(o2.getGlobalAttribute1()) < 0);
// now run the same query with reverse ordering to check that the first ordering
// result wasn't coincidental.
q.getOrderings().clear();
q.orderBy(ClientMtTable1.GLOBAL_ATTRIBUTE1.desc());
List<?> results1 = context.performQuery(q);
assertEquals(2, results1.size());
ClientMtTable1 o3 = (ClientMtTable1) results1.get(0);
ClientMtTable1 o4 = (ClientMtTable1) results1.get(1);
assertTrue(o3.getGlobalAttribute1().compareTo(o4.getGlobalAttribute1()) > 0);
}
use of org.apache.cayenne.testdo.mt.MtTable1 in project cayenne by apache.
the class ObjectDetachOperationIT method testDetachCommitted.
@Test
public void testDetachCommitted() {
EntityResolver serverResover = serverContext.getEntityResolver();
EntityResolver clientResolver = serverResover.getClientEntityResolver();
ObjectDetachOperation op = new ObjectDetachOperation(clientResolver);
ObjectId oid = ObjectId.of("MtTable1", MtTable1.TABLE1_ID_PK_COLUMN, 456);
MtTable1 so = new MtTable1();
so.setObjectId(oid);
so.setGlobalAttribute1("gx");
so.setPersistenceState(PersistenceState.COMMITTED);
so.setObjectContext(serverContext);
serverContext.getGraphManager().registerNode(oid, so);
Object detached = op.detach(so, serverResover.getClassDescriptor("MtTable1"), null);
assertNotNull(detached);
assertNotSame(so, detached);
assertTrue(detached instanceof ClientMtTable1);
ClientMtTable1 co = (ClientMtTable1) detached;
assertEquals(oid, co.getObjectId());
assertEquals("gx", co.getGlobalAttribute1());
assertEquals(PersistenceState.TRANSIENT, co.getPersistenceState());
assertNull(co.getObjectContext());
}
use of org.apache.cayenne.testdo.mt.MtTable1 in project cayenne by apache.
the class SelectQueryAbstractEntityIT method test2AbstractEntitySelect.
@Test
public void test2AbstractEntitySelect() throws Exception {
createDataSet();
ObjectSelect<MtTable1> query = ObjectSelect.query(MtTable1.class);
final List<MtTable1> list = context.select(query);
assertNotNull(list);
for (MtTable1 sub : list) {
if (sub instanceof MtTable1Subclass2) {
assertNotNull(((MtTable1Subclass2) sub).getSubclass2Attribute1());
}
}
}
Aggregations