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"));
}
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());
}
Aggregations