Search in sources :

Example 66 with ClientMtTable1

use of org.apache.cayenne.testdo.mt.ClientMtTable1 in project cayenne by apache.

the class CayenneContextServerDiffsIT method testReturnDiffInPreUpdate.

@Test
public void testReturnDiffInPreUpdate() {
    LifecycleCallbackRegistry callbackRegistry = clientServerChannel.getEntityResolver().getCallbackRegistry();
    try {
        callbackRegistry.addListener(LifecycleEvent.PRE_UPDATE, MtTable1.class, new ClientChannelServerDiffsListener1(), "preUpdate");
        ClientMtTable1 o = context.newObject(ClientMtTable1.class);
        o.setServerAttribute1("YY");
        context.commitChanges();
        assertNull(o.getGlobalAttribute1());
        o.setServerAttribute1("XX");
        context.commitChanges();
        assertFalse(o.getObjectId().isTemporary());
        assertEquals(PersistenceState.COMMITTED, o.getPersistenceState());
        assertEquals("111", o.getGlobalAttribute1());
    } finally {
        callbackRegistry.clear();
    }
}
Also used : ClientChannelServerDiffsListener1(org.apache.cayenne.remote.ClientChannelServerDiffsListener1) ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) LifecycleCallbackRegistry(org.apache.cayenne.reflect.LifecycleCallbackRegistry) Test(org.junit.Test)

Example 67 with ClientMtTable1

use of org.apache.cayenne.testdo.mt.ClientMtTable1 in project cayenne by apache.

the class CayenneContextServerDiffsIT method testReturnDiffClientArcChanges.

@Test
public void testReturnDiffClientArcChanges() {
    LifecycleCallbackRegistry callbackRegistry = clientServerChannel.getEntityResolver().getCallbackRegistry();
    try {
        callbackRegistry.addListener(LifecycleEvent.POST_ADD, MtTable1.class, new ClientChannelServerDiffsListener1(), "prePersist");
        ClientMtTable1 o = context.newObject(ClientMtTable1.class);
        ClientMtTable2 o1 = context.newObject(ClientMtTable2.class);
        o.addToTable2Array(o1);
        context.commitChanges();
        assertFalse(o.getObjectId().isTemporary());
        assertEquals(PersistenceState.COMMITTED, o.getPersistenceState());
        assertEquals("XXX", o.getGlobalAttribute1());
    } finally {
        callbackRegistry.clear();
    }
}
Also used : ClientChannelServerDiffsListener1(org.apache.cayenne.remote.ClientChannelServerDiffsListener1) ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) LifecycleCallbackRegistry(org.apache.cayenne.reflect.LifecycleCallbackRegistry) Test(org.junit.Test)

Example 68 with ClientMtTable1

use of org.apache.cayenne.testdo.mt.ClientMtTable1 in project cayenne by apache.

the class CayenneContextWithDataContextIT method testCreateFault.

@Test
public void testCreateFault() throws Exception {
    tMtTable1.insert(1, "g1", "s1");
    ObjectId id = new ObjectId("MtTable1", MtTable1.TABLE1_ID_PK_COLUMN, 1);
    Object fault = clientContext.createFault(id);
    assertTrue(fault instanceof ClientMtTable1);
    ClientMtTable1 o = (ClientMtTable1) fault;
    assertEquals(PersistenceState.HOLLOW, o.getPersistenceState());
    assertSame(clientContext, o.getObjectContext());
    assertNull(o.getGlobalAttribute1Direct());
    // make sure we haven't tripped the fault yet
    assertEquals(PersistenceState.HOLLOW, o.getPersistenceState());
    // try tripping fault
    assertEquals("g1", o.getGlobalAttribute1());
    assertEquals(PersistenceState.COMMITTED, o.getPersistenceState());
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) Test(org.junit.Test)

Example 69 with ClientMtTable1

use of org.apache.cayenne.testdo.mt.ClientMtTable1 in project cayenne by apache.

the class PersistentObjectHolderTest method testSetInitialValue.

@Test
public void testSetInitialValue() {
    ObjectContext context = mock(ObjectContext.class);
    ClientMtTable2 o = new ClientMtTable2();
    o.setPersistenceState(PersistenceState.COMMITTED);
    o.setObjectContext(context);
    PersistentObjectHolder holder = new PersistentObjectHolder(o, ClientMtTable2.TABLE1_PROPERTY);
    assertTrue(holder.isFault());
    ClientMtTable1 o1 = new ClientMtTable1();
    o1.setObjectContext(context);
    holder.setValueDirectly(o1);
    assertFalse(holder.isFault());
    assertSame(o1, holder.value);
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) ObjectContext(org.apache.cayenne.ObjectContext) Test(org.junit.Test)

Example 70 with ClientMtTable1

use of org.apache.cayenne.testdo.mt.ClientMtTable1 in project cayenne by apache.

the class CayenneContextWithDataContextIT method testPrefetchingToManyEmpty.

@Test
public void testPrefetchingToManyEmpty() throws Exception {
    createTwoMtTable1sAnd2sDataSet();
    SelectQuery q = new SelectQuery(ClientMtTable1.class);
    q.addOrdering(ClientMtTable1.GLOBAL_ATTRIBUTE1_PROPERTY, SortOrder.ASCENDING);
    q.addPrefetch(ClientMtTable1.TABLE2ARRAY_PROPERTY);
    final List<ClientMtTable1> results = clientContext.performQuery(q);
    clientServerInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            ClientMtTable1 o2 = results.get(1);
            assertEquals(PersistenceState.COMMITTED, o2.getPersistenceState());
            assertSame(clientContext, o2.getObjectContext());
            List<ClientMtTable2> children2 = o2.getTable2Array();
            assertFalse(((ValueHolder) children2).isFault());
            assertEquals(0, children2.size());
        }
    });
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) RemoteIncrementalFaultList(org.apache.cayenne.remote.RemoteIncrementalFaultList) List(java.util.List) Test(org.junit.Test)

Aggregations

ClientMtTable1 (org.apache.cayenne.testdo.mt.ClientMtTable1)112 Test (org.junit.Test)112 ClientMtTable2 (org.apache.cayenne.testdo.mt.ClientMtTable2)46 SelectQuery (org.apache.cayenne.query.SelectQuery)26 UnitTestClosure (org.apache.cayenne.unit.di.UnitTestClosure)19 ObjectContext (org.apache.cayenne.ObjectContext)12 Expression (org.apache.cayenne.exp.Expression)12 ObjectIdQuery (org.apache.cayenne.query.ObjectIdQuery)11 List (java.util.List)8 ObjectId (org.apache.cayenne.ObjectId)7 EntityResolver (org.apache.cayenne.map.EntityResolver)7 LifecycleCallbackRegistry (org.apache.cayenne.reflect.LifecycleCallbackRegistry)7 RemoteIncrementalFaultList (org.apache.cayenne.remote.RemoteIncrementalFaultList)6 GraphDiff (org.apache.cayenne.graph.GraphDiff)5 MockEventManager (org.apache.cayenne.event.MockEventManager)4 ClientChannelServerDiffsListener1 (org.apache.cayenne.remote.ClientChannelServerDiffsListener1)4 ArrayList (java.util.ArrayList)3 Iterator (java.util.Iterator)3 GraphChangeHandler (org.apache.cayenne.graph.GraphChangeHandler)3 MtTable1 (org.apache.cayenne.testdo.mt.MtTable1)3