Search in sources :

Example 21 with ArtGroup

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

the class CayenneDataObjectFlattenedRelIT method testAddRemoveFlattenedRelationship1.

@Test
public void testAddRemoveFlattenedRelationship1() throws Exception {
    create1Artist1ArtGroupDataSet();
    Artist a1 = Cayenne.objectForPK(context, Artist.class, 33001);
    SelectQuery q = new SelectQuery(ArtGroup.class, ExpressionFactory.matchExp("name", "g1"));
    List<?> results = context.performQuery(q);
    assertEquals(1, results.size());
    ArtGroup group = (ArtGroup) results.get(0);
    a1.addToGroupArray(group);
    group.removeFromArtistArray(a1);
    queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            context.commitChanges();
        }
    });
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) SelectQuery(org.apache.cayenne.query.SelectQuery) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) ArtGroup(org.apache.cayenne.testdo.testmap.ArtGroup) Test(org.junit.Test)

Example 22 with ArtGroup

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

the class CayenneDataObjectFlattenedRelIT method testRemoveFlattenedRelationshipAndRootRecord.

// Demonstrates a possible bug in ordering of deletes, when a flattened relationships
// link record is deleted at the same time (same transaction) as one of the record to
// which it links.
@Test
public void testRemoveFlattenedRelationshipAndRootRecord() throws Exception {
    create1Artist1ArtGroup1ArtistGroupDataSet();
    Artist a1 = Cayenne.objectForPK(context, Artist.class, 33001);
    ArtGroup group = a1.getGroupArray().get(0);
    // Cause the delete of the link record
    a1.removeFromGroupArray(group);
    // Cause the deletion of the artist
    context.deleteObjects(a1);
    try {
        context.commitChanges();
    } catch (Exception e) {
        e.printStackTrace();
        fail("Should not have thrown the exception :" + e.getMessage());
    }
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) ArtGroup(org.apache.cayenne.testdo.testmap.ArtGroup) Test(org.junit.Test)

Example 23 with ArtGroup

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

the class CayenneDataObjectFlattenedRelIT method testReadFlattenedRelationship.

@Test
public void testReadFlattenedRelationship() throws Exception {
    create1Artist1ArtGroupDataSet();
    Artist a1 = Cayenne.objectForPK(context, Artist.class, 33001);
    List<ArtGroup> groupList = a1.getGroupArray();
    assertNotNull(groupList);
    assertEquals(0, groupList.size());
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) ArtGroup(org.apache.cayenne.testdo.testmap.ArtGroup) Test(org.junit.Test)

Example 24 with ArtGroup

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

the class CayenneDataObjectFlattenedRelIT method testDoubleCommitAddToFlattenedRelationship.

// Test case to show up a bug in committing more than once
@Test
public void testDoubleCommitAddToFlattenedRelationship() throws Exception {
    create1Artist1ArtGroupDataSet();
    Artist a1 = Cayenne.objectForPK(context, Artist.class, 33001);
    SelectQuery q = new SelectQuery(ArtGroup.class, ExpressionFactory.matchExp("name", "g1"));
    List<?> results = context.performQuery(q);
    assertEquals(1, results.size());
    ArtGroup group = (ArtGroup) results.get(0);
    a1.addToGroupArray(group);
    List<?> groupList = a1.getGroupArray();
    assertEquals(1, groupList.size());
    assertEquals("g1", ((ArtGroup) groupList.get(0)).getName());
    // Ensure that the commit doesn't fail
    a1.getObjectContext().commitChanges();
    try {
        // The bug caused the second commit to fail (the link record
        // was inserted again)
        a1.getObjectContext().commitChanges();
    } catch (Exception e) {
        e.printStackTrace();
        fail("Should not have thrown an exception");
    }
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) SelectQuery(org.apache.cayenne.query.SelectQuery) ArtGroup(org.apache.cayenne.testdo.testmap.ArtGroup) Test(org.junit.Test)

Example 25 with ArtGroup

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

the class CayenneDataObjectRelationshipsIT method testReflexiveRelationshipInsertOrder4.

@Test
public void testReflexiveRelationshipInsertOrder4() {
    // 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("subchild");
    childGroup2.setToParentGroup(childGroup1);
    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)

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