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());
}
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();
}
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);
}
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());
}
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());
}
Aggregations