Search in sources :

Example 1 with MtTable1

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());
}
Also used : MtTable2(org.apache.cayenne.testdo.mt.MtTable2) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) MtTable1(org.apache.cayenne.testdo.mt.MtTable1) ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) Test(org.junit.Test)

Example 2 with MtTable1

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();
    }
}
Also used : DataContext(org.apache.cayenne.access.DataContext) MtTable1(org.apache.cayenne.testdo.mt.MtTable1) ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ParallelTestContainer(org.apache.cayenne.test.parallel.ParallelTestContainer) LifecycleCallbackRegistry(org.apache.cayenne.reflect.LifecycleCallbackRegistry) Test(org.junit.Test)

Example 3 with MtTable1

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);
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) MtTable1(org.apache.cayenne.testdo.mt.MtTable1) ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ObjectSelect(org.apache.cayenne.query.ObjectSelect) Test(org.junit.Test)

Example 4 with MtTable1

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());
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) MtTable1(org.apache.cayenne.testdo.mt.MtTable1) ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ObjectId(org.apache.cayenne.ObjectId) EntityResolver(org.apache.cayenne.map.EntityResolver) Test(org.junit.Test)

Example 5 with MtTable1

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());
        }
    }
}
Also used : MtTable1(org.apache.cayenne.testdo.mt.MtTable1) MtTable1Subclass2(org.apache.cayenne.testdo.mt.MtTable1Subclass2) Test(org.junit.Test)

Aggregations

MtTable1 (org.apache.cayenne.testdo.mt.MtTable1)8 Test (org.junit.Test)8 ClientMtTable1 (org.apache.cayenne.testdo.mt.ClientMtTable1)6 ObjectId (org.apache.cayenne.ObjectId)2 EntityResolver (org.apache.cayenne.map.EntityResolver)2 DataContext (org.apache.cayenne.access.DataContext)1 GraphDiff (org.apache.cayenne.graph.GraphDiff)1 NodeCreateOperation (org.apache.cayenne.graph.NodeCreateOperation)1 ObjectSelect (org.apache.cayenne.query.ObjectSelect)1 LifecycleCallbackRegistry (org.apache.cayenne.reflect.LifecycleCallbackRegistry)1 ParallelTestContainer (org.apache.cayenne.test.parallel.ParallelTestContainer)1 ClientMtTable2 (org.apache.cayenne.testdo.mt.ClientMtTable2)1 MtTable1Subclass1 (org.apache.cayenne.testdo.mt.MtTable1Subclass1)1 MtTable1Subclass2 (org.apache.cayenne.testdo.mt.MtTable1Subclass2)1 MtTable2 (org.apache.cayenne.testdo.mt.MtTable2)1