use of org.apache.cayenne.testdo.relationships_flattened.FlattenedTest1 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);
}
use of org.apache.cayenne.testdo.relationships_flattened.FlattenedTest1 in project cayenne by apache.
the class DataContextEJBQLFlattenedRelationshipsIT method testCollectionMemberOfThetaJoinLongRelationshipSequence.
@Test
public void testCollectionMemberOfThetaJoinLongRelationshipSequence() throws Exception {
createFt1234();
String ejbql = "SELECT f FROM FlattenedTest4 f, FlattenedTest1 ft " + "WHERE f MEMBER OF ft.ft4ArrayFor1 AND ft = :ft";
FlattenedTest1 ft = Cayenne.objectForPK(context, FlattenedTest1.class, 1);
EJBQLQuery query = new EJBQLQuery(ejbql);
query.setParameter("ft", ft);
List<?> objects = context.performQuery(query);
assertEquals(1, objects.size());
Set<Object> ids = new HashSet<Object>();
Iterator<?> it = objects.iterator();
while (it.hasNext()) {
Object id = Cayenne.pkForObject((Persistent) it.next());
ids.add(id);
}
assertTrue(ids.contains(new Integer(1)));
ft = Cayenne.objectForPK(context, FlattenedTest1.class, 2);
query = new EJBQLQuery(ejbql);
query.setParameter("ft", ft);
objects = context.performQuery(query);
assertEquals(0, objects.size());
}
use of org.apache.cayenne.testdo.relationships_flattened.FlattenedTest1 in project cayenne by apache.
the class FlattenedRelationshipsIT method testFlattenedComplexToOneRelationship.
/**
* Should be able to save/insert an object with flattened (complex) toOne relationship
* @throws Exception
*/
@Test
public void testFlattenedComplexToOneRelationship() throws Exception {
FlattenedTest1 ft1 = context.newObject(FlattenedTest1.class);
ft1.setName("FT1");
FlattenedTest5 ft5 = context.newObject(FlattenedTest5.class);
ft5.setName("FT5");
ft5.setToFT1(ft1);
context.commitChanges();
FlattenedTest5 ft5Persisted = ObjectSelect.query(FlattenedTest5.class).selectFirst(context);
assertEquals(ft1, ft5Persisted.getToFT1());
}
use of org.apache.cayenne.testdo.relationships_flattened.FlattenedTest1 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());
}
use of org.apache.cayenne.testdo.relationships_flattened.FlattenedTest1 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());
}
Aggregations