Search in sources :

Example 1 with FlattenedTest3

use of org.apache.cayenne.testdo.relationships_flattened.FlattenedTest3 in project cayenne by apache.

the class FlattenedArcKeyIT method testHashCode.

@Test
public void testHashCode() {
    ObjectId src = new ObjectId("X");
    ObjectId target = new ObjectId("Y");
    ObjRelationship r1 = entityResolver.getObjEntity(FlattenedTest3.class).getRelationship(FlattenedTest3.TO_FT1.getName());
    FlattenedArcKey update = new FlattenedArcKey(src, target, r1);
    FlattenedArcKey update1 = new FlattenedArcKey(target, src, r1.getReverseRelationship());
    ObjRelationship r3 = entityResolver.getObjEntity(FlattenedTest1.class).getRelationship(FlattenedTest1.FT3OVER_COMPLEX.getName());
    FlattenedArcKey update2 = new FlattenedArcKey(target, src, r3);
    int h = update.hashCode();
    int h1 = update1.hashCode();
    int h2 = update2.hashCode();
    assertTrue(h == h1);
    assertTrue(h == update.hashCode());
    assertFalse(h == h2);
}
Also used : FlattenedTest3(org.apache.cayenne.testdo.relationships_flattened.FlattenedTest3) ObjRelationship(org.apache.cayenne.map.ObjRelationship) FlattenedTest1(org.apache.cayenne.testdo.relationships_flattened.FlattenedTest1) ObjectId(org.apache.cayenne.ObjectId) Test(org.junit.Test)

Example 2 with FlattenedTest3

use of org.apache.cayenne.testdo.relationships_flattened.FlattenedTest3 in project cayenne by apache.

the class FlattenedRelationshipInContextIT method testIsToOneTargetModifiedFlattenedFault1.

@Test
public void testIsToOneTargetModifiedFlattenedFault1() throws Exception {
    createFlattenedTestDataSet();
    // fetch
    List<?> ft3s = context.performQuery(new SelectQuery(FlattenedTest3.class));
    assertEquals(1, ft3s.size());
    FlattenedTest3 ft3 = (FlattenedTest3) ft3s.get(0);
    // mark as dirty for the purpose of the test...
    ft3.setPersistenceState(PersistenceState.MODIFIED);
    assertTrue(ft3.readPropertyDirectly("toFT1") instanceof Fault);
    // test that checking for modifications does not trigger a fault, and generally
    // works well
    ClassDescriptor d = context.getEntityResolver().getClassDescriptor("FlattenedTest3");
    ArcProperty flattenedRel = (ArcProperty) d.getProperty("toFT1");
    ObjectDiff diff = context.getObjectStore().registerDiff(ft3.getObjectId(), null);
    assertFalse(DataRowUtils.isToOneTargetModified(flattenedRel, ft3, diff));
    assertTrue(ft3.readPropertyDirectly("toFT1") instanceof Fault);
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) FlattenedTest3(org.apache.cayenne.testdo.relationships_flattened.FlattenedTest3) ArcProperty(org.apache.cayenne.reflect.ArcProperty) ClassDescriptor(org.apache.cayenne.reflect.ClassDescriptor) Fault(org.apache.cayenne.Fault) Test(org.junit.Test)

Example 3 with FlattenedTest3

use of org.apache.cayenne.testdo.relationships_flattened.FlattenedTest3 in project cayenne by apache.

the class FlattenedRelationshipsIT method testRefetchWithFlattenedFaultToOneTarget1.

@Test
public void testRefetchWithFlattenedFaultToOneTarget1() throws Exception {
    createFlattenedTestDataSet();
    // fetch
    List<?> ft3s = context.performQuery(new SelectQuery(FlattenedTest3.class));
    assertEquals(1, ft3s.size());
    FlattenedTest3 ft3 = (FlattenedTest3) ft3s.get(0);
    assertTrue(ft3.readPropertyDirectly("toFT1") instanceof Fault);
    // refetch
    context.performQuery(new SelectQuery(FlattenedTest3.class));
    assertTrue(ft3.readPropertyDirectly("toFT1") instanceof Fault);
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) FlattenedTest3(org.apache.cayenne.testdo.relationships_flattened.FlattenedTest3) Test(org.junit.Test)

Example 4 with FlattenedTest3

use of org.apache.cayenne.testdo.relationships_flattened.FlattenedTest3 in project cayenne by apache.

the class FlattenedRelationshipsIT method testInsertJoinWithPK.

@Test
public void testInsertJoinWithPK() throws Exception {
    FlattenedTest1 obj01 = context.newObject(FlattenedTest1.class);
    FlattenedTest3 obj11 = context.newObject(FlattenedTest3.class);
    FlattenedTest3 obj12 = context.newObject(FlattenedTest3.class);
    obj01.setName("t01");
    obj11.setName("t11");
    obj12.setName("t12");
    obj01.addToFt3OverComplex(obj11);
    obj01.addToFt3OverComplex(obj12);
    context.commitChanges();
    int pk = Cayenne.intPKForObject(obj01);
    context.invalidateObjects(obj01, obj11, obj12);
    FlattenedTest1 fresh01 = Cayenne.objectForPK(context1, FlattenedTest1.class, pk);
    assertEquals("t01", fresh01.getName());
    ValueHolder related = (ValueHolder) fresh01.getFt3OverComplex();
    assertTrue(related.isFault());
    assertEquals(2, ((List<?>) related).size());
}
Also used : FlattenedTest3(org.apache.cayenne.testdo.relationships_flattened.FlattenedTest3) FlattenedTest1(org.apache.cayenne.testdo.relationships_flattened.FlattenedTest1) Test(org.junit.Test)

Example 5 with FlattenedTest3

use of org.apache.cayenne.testdo.relationships_flattened.FlattenedTest3 in project cayenne by apache.

the class FlattenedRelationshipsIT method testToOneSeriesFlattenedRel.

@Test
public void testToOneSeriesFlattenedRel() {
    FlattenedTest1 ft1 = (FlattenedTest1) context.newObject("FlattenedTest1");
    ft1.setName("FT1Name");
    FlattenedTest2 ft2 = (FlattenedTest2) context.newObject("FlattenedTest2");
    ft2.setName("FT2Name");
    FlattenedTest3 ft3 = (FlattenedTest3) context.newObject("FlattenedTest3");
    ft3.setName("FT3Name");
    ft2.setToFT1(ft1);
    ft2.addToFt3Array(ft3);
    context.commitChanges();
    context.invalidateObjects(ft1, ft2, ft3);
    SelectQuery q = new SelectQuery(FlattenedTest3.class);
    q.setQualifier(ExpressionFactory.matchExp("name", "FT3Name"));
    List<?> results = context1.performQuery(q);
    assertEquals(1, results.size());
    FlattenedTest3 fetchedFT3 = (FlattenedTest3) results.get(0);
    FlattenedTest1 fetchedFT1 = fetchedFT3.getToFT1();
    assertEquals("FT1Name", fetchedFT1.getName());
}
Also used : FlattenedTest3(org.apache.cayenne.testdo.relationships_flattened.FlattenedTest3) SelectQuery(org.apache.cayenne.query.SelectQuery) FlattenedTest1(org.apache.cayenne.testdo.relationships_flattened.FlattenedTest1) FlattenedTest2(org.apache.cayenne.testdo.relationships_flattened.FlattenedTest2) Test(org.junit.Test)

Aggregations

FlattenedTest3 (org.apache.cayenne.testdo.relationships_flattened.FlattenedTest3)10 Test (org.junit.Test)10 FlattenedTest1 (org.apache.cayenne.testdo.relationships_flattened.FlattenedTest1)6 SelectQuery (org.apache.cayenne.query.SelectQuery)5 ObjectId (org.apache.cayenne.ObjectId)3 ObjRelationship (org.apache.cayenne.map.ObjRelationship)3 FlattenedTest2 (org.apache.cayenne.testdo.relationships_flattened.FlattenedTest2)2 Fault (org.apache.cayenne.Fault)1 Expression (org.apache.cayenne.exp.Expression)1 SQLTemplate (org.apache.cayenne.query.SQLTemplate)1 ArcProperty (org.apache.cayenne.reflect.ArcProperty)1 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)1