use of org.apache.cayenne.testdo.map_to_many.ClientIdMapToManyTarget in project cayenne by apache.
the class CayenneContextMapRelationshipIT method testReadToMany.
@Test
public void testReadToMany() throws Exception {
createTwoMapToManysWithTargetsDataSet();
ObjectId id = ObjectId.of("IdMapToMany", IdMapToMany.ID_PK_COLUMN, 1);
ClientIdMapToMany o1 = (ClientIdMapToMany) Cayenne.objectForQuery(context, new ObjectIdQuery(id));
Map<Object, ClientIdMapToManyTarget> targets = o1.getTargets();
assertTrue(((ValueHolder) targets).isFault());
assertNotNull(targets);
assertEquals(3, targets.size());
assertNotNull(targets.get(1));
assertNotNull(targets.get(2));
assertNotNull(targets.get(3));
}
use of org.apache.cayenne.testdo.map_to_many.ClientIdMapToManyTarget in project cayenne by apache.
the class CayenneContextMapRelationshipIT method testAddToMany.
@Test
public void testAddToMany() throws Exception {
createTwoMapToManysWithTargetsDataSet();
ObjectId id = ObjectId.of("IdMapToMany", IdMapToMany.ID_PK_COLUMN, 1);
ClientIdMapToMany o1 = (ClientIdMapToMany) Cayenne.objectForQuery(context, new ObjectIdQuery(id));
Map<Object, ClientIdMapToManyTarget> targets = o1.getTargets();
assertNotNull(targets);
assertEquals(3, targets.size());
ClientIdMapToManyTarget newTarget = o1.getObjectContext().newObject(ClientIdMapToManyTarget.class);
o1.addToTargets(newTarget);
assertEquals(4, targets.size());
assertSame(o1, newTarget.getMapToMany());
o1.getObjectContext().commitChanges();
o1.getObjectContext().performGenericQuery(new RefreshQuery());
assertEquals(4, o1.getTargets().size());
int newId = Cayenne.intPKForObject(newTarget);
assertSame(newTarget, o1.getTargets().get(newId));
assertEquals(PersistenceState.COMMITTED, o1.getPersistenceState());
assertEquals(PersistenceState.COMMITTED, newTarget.getPersistenceState());
}
use of org.apache.cayenne.testdo.map_to_many.ClientIdMapToManyTarget in project cayenne by apache.
the class ROPPrefetchToManyMapIT method test.
@Test
public void test() {
ObjectContext context = createROPContext();
ClientIdMapToMany map = context.newObject(ClientIdMapToMany.class);
ClientIdMapToManyTarget target = context.newObject(ClientIdMapToManyTarget.class);
target.setMapToMany(map);
context.commitChanges();
context.performQuery(new RefreshQuery());
ObjectSelect<ClientIdMapToMany> query = ObjectSelect.query(ClientIdMapToMany.class).prefetch("targets", PrefetchTreeNode.UNDEFINED_SEMANTICS);
final ClientIdMapToMany mapToMany = (ClientIdMapToMany) Cayenne.objectForQuery(context, query);
queryInterceptor.runWithQueriesBlocked(() -> assertEquals(mapToMany.getTargets().size(), 1));
}
Aggregations