Search in sources :

Example 41 with ObjectIdQuery

use of org.apache.cayenne.query.ObjectIdQuery in project cayenne by apache.

the class PersistentObjectInContextIT method testResolveToManyReverseResolved.

@Test
public void testResolveToManyReverseResolved() throws Exception {
    createTwoMtTable1sAnd2sDataSet();
    ObjectId gid = new ObjectId("MtTable1", MtTable1.TABLE1_ID_PK_COLUMN, new Integer(1));
    ClientMtTable1 t1 = (ClientMtTable1) Cayenne.objectForQuery(context, new ObjectIdQuery(gid));
    assertNotNull(t1);
    List<ClientMtTable2> t2s = t1.getTable2Array();
    assertEquals(2, t2s.size());
    for (ClientMtTable2 t2 : t2s) {
        PersistentObjectHolder holder = (PersistentObjectHolder) t2.getTable1Direct();
        assertFalse(holder.isFault());
        assertSame(t1, holder.getValue());
    }
}
Also used : PersistentObjectHolder(org.apache.cayenne.util.PersistentObjectHolder) ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) ObjectIdQuery(org.apache.cayenne.query.ObjectIdQuery) Test(org.junit.Test)

Example 42 with ObjectIdQuery

use of org.apache.cayenne.query.ObjectIdQuery in project cayenne by apache.

the class ShallowMergeOperation_ClientIT method testMerge_NoOverride.

@Test
public void testMerge_NoOverride() throws Exception {
    ObjectContext childContext = runtime.newContext(context);
    final ShallowMergeOperation op = new ShallowMergeOperation(childContext);
    final ClientMtTable1 modified = context.newObject(ClientMtTable1.class);
    context.commitChanges();
    final ClientMtTable1 peerModified = (ClientMtTable1) Cayenne.objectForQuery(childContext, new ObjectIdQuery(modified.getObjectId()));
    modified.setGlobalAttribute1("M1");
    peerModified.setGlobalAttribute1("M2");
    assertEquals(PersistenceState.MODIFIED, modified.getPersistenceState());
    assertEquals(PersistenceState.MODIFIED, peerModified.getPersistenceState());
    queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            Persistent peerModified2 = op.merge(modified);
            assertSame(peerModified, peerModified2);
            assertEquals(PersistenceState.MODIFIED, peerModified2.getPersistenceState());
            assertEquals("M2", peerModified.getGlobalAttribute1());
            assertEquals("M1", modified.getGlobalAttribute1());
        }
    });
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) Persistent(org.apache.cayenne.Persistent) ObjectContext(org.apache.cayenne.ObjectContext) ObjectIdQuery(org.apache.cayenne.query.ObjectIdQuery) Test(org.junit.Test)

Aggregations

ObjectIdQuery (org.apache.cayenne.query.ObjectIdQuery)42 Test (org.junit.Test)34 ObjectId (org.apache.cayenne.ObjectId)15 ClientMtTable1 (org.apache.cayenne.testdo.mt.ClientMtTable1)11 ClientMtTable2 (org.apache.cayenne.testdo.mt.ClientMtTable2)6 ToOneFK2 (org.apache.cayenne.testdo.relationships_to_one_fk.ToOneFK2)6 UnitTestClosure (org.apache.cayenne.unit.di.UnitTestClosure)6 DataRow (org.apache.cayenne.DataRow)5 Artist (org.apache.cayenne.testdo.testmap.Artist)5 ToOneFK1 (org.apache.cayenne.testdo.relationships_to_one_fk.ToOneFK1)4 List (java.util.List)3 ObjectContext (org.apache.cayenne.ObjectContext)3 Persistent (org.apache.cayenne.Persistent)3 QueryResponse (org.apache.cayenne.QueryResponse)3 SQLTemplate (org.apache.cayenne.query.SQLTemplate)3 AbstractPerson (org.apache.cayenne.testdo.inheritance_people.AbstractPerson)3 Date (java.util.Date)2 SelectQuery (org.apache.cayenne.query.SelectQuery)2 AttributeProperty (org.apache.cayenne.reflect.AttributeProperty)2 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)2