Search in sources :

Example 6 with MapToMany

use of org.apache.cayenne.testdo.map_to_many.MapToMany in project cayenne by apache.

the class CDOMapRelationshipIT method testModifyToManyKey.

@Test
public void testModifyToManyKey() throws Exception {
    createTestDataSet();
    MapToMany o1 = Cayenne.objectForPK(context, MapToMany.class, 1);
    Map targets = o1.getTargets();
    MapToManyTarget target = (MapToManyTarget) targets.get("B");
    target.setName("B1");
    o1.getObjectContext().commitChanges();
    assertNull(o1.getTargets().get("B"));
    assertSame(target, o1.getTargets().get("B1"));
}
Also used : Map(java.util.Map) MapToManyTarget(org.apache.cayenne.testdo.map_to_many.MapToManyTarget) IdMapToMany(org.apache.cayenne.testdo.map_to_many.IdMapToMany) MapToMany(org.apache.cayenne.testdo.map_to_many.MapToMany) Test(org.junit.Test)

Example 7 with MapToMany

use of org.apache.cayenne.testdo.map_to_many.MapToMany in project cayenne by apache.

the class CDOMapRelationshipIT method testReadToMany.

@Test
public void testReadToMany() throws Exception {
    createTestDataSet();
    MapToMany o1 = Cayenne.objectForPK(context, MapToMany.class, 1);
    Map targets = o1.getTargets();
    assertTrue(((ValueHolder) targets).isFault());
    assertNotNull(targets);
    assertEquals(3, targets.size());
    assertNotNull(targets.get("A"));
    assertNotNull(targets.get("B"));
    assertNotNull(targets.get("C"));
    assertEquals(1, Cayenne.intPKForObject((Persistent) targets.get("A")));
    assertEquals(2, Cayenne.intPKForObject((Persistent) targets.get("B")));
    assertEquals(3, Cayenne.intPKForObject((Persistent) targets.get("C")));
}
Also used : Map(java.util.Map) IdMapToMany(org.apache.cayenne.testdo.map_to_many.IdMapToMany) MapToMany(org.apache.cayenne.testdo.map_to_many.MapToMany) Test(org.junit.Test)

Example 8 with MapToMany

use of org.apache.cayenne.testdo.map_to_many.MapToMany in project cayenne by apache.

the class CDOMapRelationshipIT method testReadToManyPrefetching.

@Test
public void testReadToManyPrefetching() throws Exception {
    createTestDataSet();
    SelectQuery query = new SelectQuery(MapToMany.class, ExpressionFactory.matchDbExp(MapToMany.ID_PK_COLUMN, new Integer(1)));
    query.addPrefetch(MapToMany.TARGETS.disjoint());
    MapToMany o1 = (MapToMany) Cayenne.objectForQuery(context, query);
    Map targets = o1.getTargets();
    assertFalse(((ValueHolder) targets).isFault());
    assertNotNull(targets);
    assertEquals(3, targets.size());
    assertNotNull(targets.get("A"));
    assertNotNull(targets.get("B"));
    assertNotNull(targets.get("C"));
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) Map(java.util.Map) IdMapToMany(org.apache.cayenne.testdo.map_to_many.IdMapToMany) MapToMany(org.apache.cayenne.testdo.map_to_many.MapToMany) Test(org.junit.Test)

Aggregations

MapToMany (org.apache.cayenne.testdo.map_to_many.MapToMany)8 Test (org.junit.Test)8 Map (java.util.Map)7 IdMapToMany (org.apache.cayenne.testdo.map_to_many.IdMapToMany)6 MapToManyTarget (org.apache.cayenne.testdo.map_to_many.MapToManyTarget)4 RefreshQuery (org.apache.cayenne.query.RefreshQuery)3 Set (java.util.Set)1 SelectQuery (org.apache.cayenne.query.SelectQuery)1 SetToMany (org.apache.cayenne.testdo.relationships_set_to_many.SetToMany)1