Search in sources :

Example 6 with RefreshQuery

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

the class CDOSetRelationshipIT method testAddToMany.

@Test
public void testAddToMany() throws Exception {
    createTestDataSet();
    SetToMany o1 = Cayenne.objectForPK(context, SetToMany.class, 1);
    Set targets = o1.getTargets();
    assertNotNull(targets);
    assertEquals(3, targets.size());
    SetToManyTarget newTarget = o1.getObjectContext().newObject(SetToManyTarget.class);
    o1.addToTargets(newTarget);
    assertEquals(4, targets.size());
    assertTrue(o1.getTargets().contains(newTarget));
    assertSame(o1, newTarget.getSetToMany());
    o1.getObjectContext().commitChanges();
    o1.getObjectContext().performGenericQuery(new RefreshQuery());
    assertEquals(4, o1.getTargets().size());
}
Also used : Set(java.util.Set) RefreshQuery(org.apache.cayenne.query.RefreshQuery) SetToMany(org.apache.cayenne.testdo.relationships_set_to_many.SetToMany) SetToManyTarget(org.apache.cayenne.testdo.relationships_set_to_many.SetToManyTarget) Test(org.junit.Test)

Example 7 with RefreshQuery

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

the class CDOCollectionRelationshipIT method testAddToMany.

@Test
public void testAddToMany() throws Exception {
    CollectionToMany o1 = Cayenne.objectForPK(context, CollectionToMany.class, 1);
    Collection<?> targets = o1.getTargets();
    assertNotNull(targets);
    assertEquals(3, targets.size());
    CollectionToManyTarget newTarget = o1.getObjectContext().newObject(CollectionToManyTarget.class);
    o1.addToTargets(newTarget);
    assertEquals(4, targets.size());
    assertTrue(o1.getTargets().contains(newTarget));
    assertSame(o1, newTarget.getCollectionToMany());
    o1.getObjectContext().commitChanges();
    o1.getObjectContext().performGenericQuery(new RefreshQuery());
    assertEquals(4, o1.getTargets().size());
}
Also used : CollectionToMany(org.apache.cayenne.testdo.relationships_collection_to_many.CollectionToMany) RefreshQuery(org.apache.cayenne.query.RefreshQuery) CollectionToManyTarget(org.apache.cayenne.testdo.relationships_collection_to_many.CollectionToManyTarget) Test(org.junit.Test)

Example 8 with RefreshQuery

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

the class CDOMapRelationshipIT method testRemoveToMany.

@Test
public void testRemoveToMany() throws Exception {
    createTestDataSet();
    MapToMany o1 = Cayenne.objectForPK(context, MapToMany.class, 1);
    Map targets = o1.getTargets();
    assertEquals(3, targets.size());
    MapToManyTarget target = (MapToManyTarget) targets.get("B");
    o1.removeFromTargets(target);
    assertEquals(2, targets.size());
    assertNull(o1.getTargets().get("B"));
    assertNull(target.getMapToMany());
    o1.getObjectContext().commitChanges();
    o1.getObjectContext().performGenericQuery(new RefreshQuery());
    assertEquals(2, o1.getTargets().size());
    assertNotNull(o1.getTargets().get("A"));
    assertNotNull(o1.getTargets().get("C"));
}
Also used : RefreshQuery(org.apache.cayenne.query.RefreshQuery) 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 9 with RefreshQuery

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

the class CDOMapRelationshipIT method testAddToMany.

@Test
public void testAddToMany() throws Exception {
    createTestDataSet();
    MapToMany o1 = Cayenne.objectForPK(context, MapToMany.class, 1);
    Map targets = o1.getTargets();
    assertNotNull(targets);
    assertEquals(3, targets.size());
    MapToManyTarget newTarget = o1.getObjectContext().newObject(MapToManyTarget.class);
    newTarget.setName("X");
    o1.addToTargets(newTarget);
    assertEquals(4, targets.size());
    assertSame(newTarget, o1.getTargets().get("X"));
    assertSame(o1, newTarget.getMapToMany());
    o1.getObjectContext().commitChanges();
    o1.getObjectContext().performGenericQuery(new RefreshQuery());
    assertEquals(4, o1.getTargets().size());
}
Also used : RefreshQuery(org.apache.cayenne.query.RefreshQuery) 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 10 with RefreshQuery

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

the class CDOMapRelationshipIT method testAddToManyViaReverse.

@Test
public void testAddToManyViaReverse() throws Exception {
    createTestDataSet();
    MapToMany o1 = Cayenne.objectForPK(context, MapToMany.class, 1);
    Map targets = o1.getTargets();
    assertNotNull(targets);
    assertEquals(3, targets.size());
    MapToManyTarget newTarget = o1.getObjectContext().newObject(MapToManyTarget.class);
    newTarget.setName("X");
    newTarget.setMapToMany(o1);
    assertSame(o1, newTarget.getMapToMany());
    assertEquals(4, targets.size());
    assertSame(newTarget, o1.getTargets().get("X"));
    o1.getObjectContext().commitChanges();
    o1.getObjectContext().performGenericQuery(new RefreshQuery());
    assertEquals(4, o1.getTargets().size());
}
Also used : RefreshQuery(org.apache.cayenne.query.RefreshQuery) 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)

Aggregations

RefreshQuery (org.apache.cayenne.query.RefreshQuery)24 Test (org.junit.Test)21 SelectQuery (org.apache.cayenne.query.SelectQuery)9 Artist (org.apache.cayenne.testdo.testmap.Artist)9 Painting (org.apache.cayenne.testdo.testmap.Painting)5 Map (java.util.Map)3 Set (java.util.Set)3 Expression (org.apache.cayenne.exp.Expression)3 ObjectIdQuery (org.apache.cayenne.query.ObjectIdQuery)3 Query (org.apache.cayenne.query.Query)3 IdMapToMany (org.apache.cayenne.testdo.map_to_many.IdMapToMany)3 MapToMany (org.apache.cayenne.testdo.map_to_many.MapToMany)3 MapToManyTarget (org.apache.cayenne.testdo.map_to_many.MapToManyTarget)3 CollectionToMany (org.apache.cayenne.testdo.relationships_collection_to_many.CollectionToMany)3 CollectionToManyTarget (org.apache.cayenne.testdo.relationships_collection_to_many.CollectionToManyTarget)3 SetToMany (org.apache.cayenne.testdo.relationships_set_to_many.SetToMany)3 SetToManyTarget (org.apache.cayenne.testdo.relationships_set_to_many.SetToManyTarget)3 Collection (java.util.Collection)2 ClientIdMapToMany (org.apache.cayenne.testdo.map_to_many.ClientIdMapToMany)2 ClientIdMapToManyTarget (org.apache.cayenne.testdo.map_to_many.ClientIdMapToManyTarget)2