Search in sources :

Example 26 with ArtGroup

use of org.apache.cayenne.testdo.testmap.ArtGroup in project cayenne by apache.

the class CayenneDataObjectRelationshipsIT method testReflexiveRelationshipInsertOrder2.

@Test
public void testReflexiveRelationshipInsertOrder2() {
    ArtGroup childGroup1 = context.newObject(ArtGroup.class);
    childGroup1.setName("child1");
    ArtGroup parentGroup = context.newObject(ArtGroup.class);
    parentGroup.setName("parent");
    childGroup1.setToParentGroup(parentGroup);
    context.commitChanges();
    childGroup1.setToParentGroup(null);
    context.commitChanges();
}
Also used : ArtGroup(org.apache.cayenne.testdo.testmap.ArtGroup) Test(org.junit.Test)

Example 27 with ArtGroup

use of org.apache.cayenne.testdo.testmap.ArtGroup in project cayenne by apache.

the class CayenneDataObjectRelationshipsIT method testReflexiveRelationshipInsertOrder3.

@Test
public void testReflexiveRelationshipInsertOrder3() {
    // multiple children, one created before parent, one after
    ArtGroup childGroup1 = context.newObject(ArtGroup.class);
    childGroup1.setName("child1");
    ArtGroup parentGroup = context.newObject(ArtGroup.class);
    parentGroup.setName("parent");
    childGroup1.setToParentGroup(parentGroup);
    ArtGroup childGroup2 = context.newObject(ArtGroup.class);
    childGroup2.setName("child2");
    childGroup2.setToParentGroup(parentGroup);
    context.commitChanges();
    childGroup1.setToParentGroup(null);
    context.commitChanges();
    childGroup2.setToParentGroup(null);
    context.commitChanges();
}
Also used : ArtGroup(org.apache.cayenne.testdo.testmap.ArtGroup) Test(org.junit.Test)

Example 28 with ArtGroup

use of org.apache.cayenne.testdo.testmap.ArtGroup in project cayenne by apache.

the class DataContextDeleteRulesIT method testNullifyToMany.

@Test
public void testNullifyToMany() {
    // ArtGroup childGroupsArray
    ArtGroup parentGroup = (ArtGroup) context.newObject("ArtGroup");
    parentGroup.setName("Parent");
    ArtGroup childGroup = (ArtGroup) context.newObject("ArtGroup");
    childGroup.setName("Child");
    parentGroup.addToChildGroupsArray(childGroup);
    // Preconditions - good to check to be sure
    assertEquals(parentGroup, childGroup.getToParentGroup());
    assertTrue(parentGroup.getChildGroupsArray().contains(childGroup));
    context.commitChanges();
    context.deleteObjects(parentGroup);
    // The things we are testing.
    assertNull(childGroup.getToParentGroup());
    // Although deleted, the property should be null (good cleanup policy)
    // assertFalse(parentGroup.getChildGroupsArray().contains(childGroup));
    context.commitChanges();
}
Also used : ArtGroup(org.apache.cayenne.testdo.testmap.ArtGroup) Test(org.junit.Test)

Example 29 with ArtGroup

use of org.apache.cayenne.testdo.testmap.ArtGroup in project cayenne by apache.

the class DataContextDeleteRulesIT method testCascadeToManyFlattened.

/**
 * Tests that deleting a source of a flattened relationship with CASCADE
 * rule results in deleting a join and a target.
 */
@Test
public void testCascadeToManyFlattened() {
    // testing Artist.groupArray relationship
    ArtGroup aGroup = context.newObject(ArtGroup.class);
    aGroup.setName("Group Name");
    Artist anArtist = context.newObject(Artist.class);
    anArtist.setArtistName("A Name");
    anArtist.addToGroupArray(aGroup);
    assertTrue(anArtist.getGroupArray().contains(aGroup));
    context.commitChanges();
    SQLTemplate checkQuery = new SQLTemplate(Artist.class, "SELECT * FROM ARTIST_GROUP");
    checkQuery.setFetchingDataRows(true);
    List<?> joins1 = context.performQuery(checkQuery);
    assertEquals(1, joins1.size());
    context.deleteObjects(anArtist);
    assertEquals(PersistenceState.DELETED, aGroup.getPersistenceState());
    assertFalse(anArtist.getGroupArray().contains(aGroup));
    context.commitChanges();
    List<?> joins2 = context.performQuery(checkQuery);
    assertEquals(0, joins2.size());
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) SQLTemplate(org.apache.cayenne.query.SQLTemplate) ArtGroup(org.apache.cayenne.testdo.testmap.ArtGroup) Test(org.junit.Test)

Aggregations

ArtGroup (org.apache.cayenne.testdo.testmap.ArtGroup)29 Test (org.junit.Test)29 Artist (org.apache.cayenne.testdo.testmap.Artist)16 SelectQuery (org.apache.cayenne.query.SelectQuery)9 UnitTestClosure (org.apache.cayenne.unit.di.UnitTestClosure)8 HashSet (java.util.HashSet)4 List (java.util.List)4 Set (java.util.Set)4 ValueHolder (org.apache.cayenne.ValueHolder)4 ObjectContext (org.apache.cayenne.ObjectContext)2 SQLTemplate (org.apache.cayenne.query.SQLTemplate)2 Painting (org.apache.cayenne.testdo.testmap.Painting)2 MockDataNode (org.apache.cayenne.access.MockDataNode)1 ObjEntity (org.apache.cayenne.map.ObjEntity)1 ObjRelationship (org.apache.cayenne.map.ObjRelationship)1