use of org.apache.cayenne.testdo.relationships_flattened.FlattenedTest3 in project cayenne by apache.
the class FlattenedRelationshipsIT method testTakeObjectSnapshotFlattenedFault.
@Test
public void testTakeObjectSnapshotFlattenedFault() 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);
// test that taking a snapshot does not trigger a fault, and generally works well
DataRow snapshot = context.currentSnapshot(ft3);
assertEquals("ft3", snapshot.get("NAME"));
assertTrue(ft3.readPropertyDirectly("toFT1") instanceof Fault);
}
use of org.apache.cayenne.testdo.relationships_flattened.FlattenedTest3 in project cayenne by apache.
the class FlattenedArcKeyIT method testAttributes.
@Test
public void testAttributes() {
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);
assertSame(src, update.id1.getSourceId());
assertSame(target, update.id2.getSourceId());
assertSame(r1, update.relationship);
}
use of org.apache.cayenne.testdo.relationships_flattened.FlattenedTest3 in project cayenne by apache.
the class FlattenedArcKeyIT method testEquals.
@Test
public void testEquals() {
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);
assertTrue(update.equals(update1));
assertFalse(update.equals(update2));
}
use of org.apache.cayenne.testdo.relationships_flattened.FlattenedTest3 in project cayenne by apache.
the class FlattenedRelationshipsIT method testUnsetJoinWithPK.
@Test
public void testUnsetJoinWithPK() throws Exception {
createCircularJoinDataSet();
SQLTemplate joinSelect = new SQLTemplate(FlattenedTest1.class, "SELECT * FROM COMPLEX_JOIN");
joinSelect.setFetchingDataRows(true);
assertEquals(3, context.performQuery(joinSelect).size());
FlattenedTest1 ft1 = Cayenne.objectForPK(context, FlattenedTest1.class, 2);
assertEquals("ft12", ft1.getName());
List<FlattenedTest3> related = ft1.getFt3OverComplex();
assertTrue(((ValueHolder) related).isFault());
assertEquals(2, related.size());
FlattenedTest3 ft3 = Cayenne.objectForPK(context, FlattenedTest3.class, 3);
assertTrue(related.contains(ft3));
ft1.removeFromFt3OverComplex(ft3);
assertFalse(related.contains(ft3));
context.commitChanges();
// the thing here is that there are two join records between
// FT1 and FT3 (emulating invalid data or extras in the join table that
// are ignored in the object model).. all (2) joins must be deleted
assertEquals(1, context.performQuery(joinSelect).size());
}
use of org.apache.cayenne.testdo.relationships_flattened.FlattenedTest3 in project cayenne by apache.
the class FlattenedRelationshipsIT method testQualifyOnToManyFlattened.
@Test
public void testQualifyOnToManyFlattened() throws Exception {
FlattenedTest1 obj01 = context.newObject(FlattenedTest1.class);
FlattenedTest2 obj02 = context.newObject(FlattenedTest2.class);
FlattenedTest3 obj031 = context.newObject(FlattenedTest3.class);
FlattenedTest3 obj032 = context.newObject(FlattenedTest3.class);
FlattenedTest1 obj11 = context.newObject(FlattenedTest1.class);
FlattenedTest2 obj12 = context.newObject(FlattenedTest2.class);
FlattenedTest3 obj131 = context.newObject(FlattenedTest3.class);
obj01.setName("t01");
obj02.setName("t02");
obj031.setName("t031");
obj032.setName("t032");
obj02.setToFT1(obj01);
obj02.addToFt3Array(obj031);
obj02.addToFt3Array(obj032);
obj11.setName("t11");
obj131.setName("t131");
obj12.setName("t12");
obj12.addToFt3Array(obj131);
obj12.setToFT1(obj11);
context.commitChanges();
// test 1: qualify on flattened attribute
Expression qual1 = ExpressionFactory.matchExp("ft3Array.name", "t031");
SelectQuery query1 = new SelectQuery(FlattenedTest1.class, qual1);
List<?> objects1 = context.performQuery(query1);
assertEquals(1, objects1.size());
assertSame(obj01, objects1.get(0));
// test 2: qualify on flattened relationship
Expression qual2 = ExpressionFactory.matchExp("ft3Array", obj131);
SelectQuery query2 = new SelectQuery(FlattenedTest1.class, qual2);
List<?> objects2 = context.performQuery(query2);
assertEquals(1, objects2.size());
assertSame(obj11, objects2.get(0));
}
Aggregations