Search in sources :

Example 6 with ArtGroup

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

the class DataContextDeleteRulesIT method testNullifyToManyFlattened.

/**
 * Tests that deleting a source of a flattened relationship with NULLIFY
 * rule results in deleting a join together with the object deleted.
 */
@Test
public void testNullifyToManyFlattened() {
    // testing ArtGroup.artistArray relationship
    ArtGroup aGroup = context.newObject(ArtGroup.class);
    aGroup.setName("Group Name");
    Artist anArtist = context.newObject(Artist.class);
    anArtist.setArtistName("A Name");
    aGroup.addToArtistArray(anArtist);
    context.commitChanges();
    // Preconditions
    assertTrue(aGroup.getArtistArray().contains(anArtist));
    assertTrue(anArtist.getGroupArray().contains(aGroup));
    SQLTemplate checkQuery = new SQLTemplate(Artist.class, "SELECT * FROM ARTIST_GROUP");
    checkQuery.setFetchingDataRows(true);
    List<?> joins1 = context.performQuery(checkQuery);
    assertEquals(1, joins1.size());
    context.deleteObjects(aGroup);
    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)

Example 7 with ArtGroup

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

the class CDOReflexiveRelIT method testComplexInsertUpdateOrdering.

@Test
public void testComplexInsertUpdateOrdering() {
    ArtGroup parentGroup = context.newObject(ArtGroup.class);
    parentGroup.setName("parent");
    context.commitChanges();
    // Check that the update and insert both work write
    ArtGroup childGroup1 = context.newObject(ArtGroup.class);
    childGroup1.setName("child1");
    childGroup1.setToParentGroup(parentGroup);
    context.commitChanges();
    childGroup1.setToParentGroup(null);
    context.commitChanges();
}
Also used : ArtGroup(org.apache.cayenne.testdo.testmap.ArtGroup) Test(org.junit.Test)

Example 8 with ArtGroup

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

the class CDOReflexiveRelIT method testAddDeleteNoCommit.

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

Example 9 with ArtGroup

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

the class CayenneDataObjectFlattenedRelIT method testReadFlattenedRelationship2.

@Test
public void testReadFlattenedRelationship2() throws Exception {
    create1Artist1ArtGroup1ArtistGroupDataSet();
    Artist a1 = Cayenne.objectForPK(context, Artist.class, 33001);
    List<ArtGroup> groupList = a1.getGroupArray();
    assertNotNull(groupList);
    assertEquals(1, groupList.size());
    assertEquals(PersistenceState.COMMITTED, groupList.get(0).getPersistenceState());
    assertEquals("g1", groupList.get(0).getName());
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) ArtGroup(org.apache.cayenne.testdo.testmap.ArtGroup) Test(org.junit.Test)

Example 10 with ArtGroup

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

the class CayenneDataObjectFlattenedRelIT method testRemoveFromFlattenedRelationship.

@Test
public void testRemoveFromFlattenedRelationship() throws Exception {
    create1Artist1ArtGroup1ArtistGroupDataSet();
    Artist a1 = Cayenne.objectForPK(context, Artist.class, 33001);
    ArtGroup group = a1.getGroupArray().get(0);
    a1.removeFromGroupArray(group);
    List<ArtGroup> groupList = a1.getGroupArray();
    assertEquals(0, groupList.size());
    // Ensure that the commit doesn't fail
    a1.getObjectContext().commitChanges();
    // and check again
    groupList = a1.getGroupArray();
    assertEquals(0, groupList.size());
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) 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