Search in sources :

Example 1 with BaseDataObject

use of org.apache.cayenne.BaseDataObject in project cayenne by apache.

the class DataContextPrefetchExtrasIT method testPrefetch10.

/**
 * Tests to-one prefetching over relationships with compound keys.
 */
@Test
public void testPrefetch10() throws Exception {
    createCompoundDataSet();
    ObjectSelect<CompoundFkTestEntity> q = ObjectSelect.query(CompoundFkTestEntity.class).where(CompoundFkTestEntity.NAME.eq("CFK2")).prefetch("toCompoundPk", PrefetchTreeNode.UNDEFINED_SEMANTICS);
    List<CompoundFkTestEntity> objects = q.select(context);
    assertEquals(1, objects.size());
    BaseDataObject fk1 = objects.get(0);
    Object toOnePrefetch = fk1.readNestedProperty("toCompoundPk");
    assertNotNull(toOnePrefetch);
    assertTrue("Expected DataObject, got: " + toOnePrefetch.getClass().getName(), toOnePrefetch instanceof DataObject);
    DataObject pk1 = (DataObject) toOnePrefetch;
    assertEquals(PersistenceState.COMMITTED, pk1.getPersistenceState());
    assertEquals("CPK2", pk1.readPropertyDirectly("name"));
}
Also used : BaseDataObject(org.apache.cayenne.BaseDataObject) DataObject(org.apache.cayenne.DataObject) BaseDataObject(org.apache.cayenne.BaseDataObject) DataObject(org.apache.cayenne.DataObject) CompoundFkTestEntity(org.apache.cayenne.testdo.compound.CompoundFkTestEntity) BaseDataObject(org.apache.cayenne.BaseDataObject) Test(org.junit.Test)

Example 2 with BaseDataObject

use of org.apache.cayenne.BaseDataObject in project cayenne by apache.

the class DataContextPrefetchExtrasIT method testPrefetch11.

/**
 * Tests to-many prefetching over relationships with compound keys.
 */
@Test
public void testPrefetch11() throws Exception {
    createCompoundDataSet();
    ObjectSelect<CompoundPkTestEntity> q = ObjectSelect.query(CompoundPkTestEntity.class).where(CompoundPkTestEntity.NAME.eq("CPK2")).prefetch("compoundFkArray", PrefetchTreeNode.UNDEFINED_SEMANTICS);
    List<CompoundPkTestEntity> pks = q.select(context);
    assertEquals(1, pks.size());
    BaseDataObject pk1 = pks.get(0);
    List<?> toMany = (List<?>) pk1.readPropertyDirectly("compoundFkArray");
    assertNotNull(toMany);
    assertFalse(((ValueHolder) toMany).isFault());
    assertEquals(2, toMany.size());
    BaseDataObject fk1 = (BaseDataObject) toMany.get(0);
    assertEquals(PersistenceState.COMMITTED, fk1.getPersistenceState());
    BaseDataObject fk2 = (BaseDataObject) toMany.get(1);
    assertEquals(PersistenceState.COMMITTED, fk2.getPersistenceState());
}
Also used : CompoundPkTestEntity(org.apache.cayenne.testdo.compound.CompoundPkTestEntity) List(java.util.List) BaseDataObject(org.apache.cayenne.BaseDataObject) Test(org.junit.Test)

Aggregations

BaseDataObject (org.apache.cayenne.BaseDataObject)2 Test (org.junit.Test)2 List (java.util.List)1 DataObject (org.apache.cayenne.DataObject)1 CompoundFkTestEntity (org.apache.cayenne.testdo.compound.CompoundFkTestEntity)1 CompoundPkTestEntity (org.apache.cayenne.testdo.compound.CompoundPkTestEntity)1