use of org.apache.cayenne.testdo.compound.CompoundFkTestEntity in project cayenne by apache.
the class DataContextSQLTemplateCompoundIT method testBindObjectEqualCompound.
@Test
public void testBindObjectEqualCompound() throws Exception {
createTwoCompoundPKsAndCompoundFKsDataSet();
Map<String, String> pk = new HashMap<>();
pk.put(CompoundPkTestEntity.KEY1_PK_COLUMN, "a1");
pk.put(CompoundPkTestEntity.KEY2_PK_COLUMN, "a2");
CompoundPkTestEntity a = Cayenne.objectForPK(context, CompoundPkTestEntity.class, pk);
String template = "SELECT * FROM COMPOUND_FK_TEST t0" + " WHERE #bindObjectEqual($a [ 't0.F_KEY1', 't0.F_KEY2' ] [ 'KEY1', 'KEY2' ] ) ORDER BY PKEY";
SQLTemplate query = new SQLTemplate(CompoundFkTestEntity.class, template);
query.setColumnNamesCapitalization(CapsStrategy.UPPER);
query.setParams(Collections.singletonMap("a", a));
List<CompoundFkTestEntity> objects = context.performQuery(query);
assertEquals(1, objects.size());
CompoundFkTestEntity p = objects.get(0);
assertEquals(6, Cayenne.intPKForObject(p));
}
use of org.apache.cayenne.testdo.compound.CompoundFkTestEntity in project cayenne by apache.
the class QueryWithCompoundJoinIT method testEJBQLCompoundJoin.
@Test
public void testEJBQLCompoundJoin() throws Exception {
EJBQLQuery query = new EJBQLQuery("select f from CompoundFkTestEntity f inner join f.toCompoundPk p where p.name like 'a%'");
List res = context.performQuery(query);
assertEquals(1, res.size());
assertTrue(res.get(0) instanceof CompoundFkTestEntity);
assertEquals("test", ((CompoundFkTestEntity) res.get(0)).getName());
}
use of org.apache.cayenne.testdo.compound.CompoundFkTestEntity in project cayenne by apache.
the class DataContextEJBQLQueryCompoundIT method testSelectFromWhereMatchOnMultiColumnObject.
@Test
public void testSelectFromWhereMatchOnMultiColumnObject() throws Exception {
createTwoCompoundPKTwoFK();
Map<String, String> key1 = new HashMap<>();
key1.put(CompoundPkTestEntity.KEY1_PK_COLUMN, "b1");
key1.put(CompoundPkTestEntity.KEY2_PK_COLUMN, "b2");
CompoundPkTestEntity a = Cayenne.objectForPK(context, CompoundPkTestEntity.class, key1);
String ejbql = "select e from CompoundFkTestEntity e WHERE e.toCompoundPk = :param";
EJBQLQuery query = new EJBQLQuery(ejbql);
query.setParameter("param", a);
List<?> ps = context.performQuery(query);
assertEquals(1, ps.size());
CompoundFkTestEntity o1 = (CompoundFkTestEntity) ps.get(0);
assertEquals(33002, Cayenne.intPKForObject(o1));
}
use of org.apache.cayenne.testdo.compound.CompoundFkTestEntity in project cayenne by apache.
the class DataContextCompoundRelIT method testFetchQualifyingToMany.
@Test
public void testFetchQualifyingToMany() throws Exception {
CompoundPkTestEntity master = (CompoundPkTestEntity) context.newObject("CompoundPkTestEntity");
CompoundPkTestEntity master1 = (CompoundPkTestEntity) context.newObject("CompoundPkTestEntity");
CompoundFkTestEntity detail = (CompoundFkTestEntity) context.newObject("CompoundFkTestEntity");
CompoundFkTestEntity detail1 = (CompoundFkTestEntity) context.newObject("CompoundFkTestEntity");
master.addToCompoundFkArray(detail);
master1.addToCompoundFkArray(detail1);
master.setName("m1");
master.setKey1("key11");
master.setKey2("key21");
master1.setName("m2");
master1.setKey1("key12");
master1.setKey2("key22");
detail.setName("d1");
detail1.setName("d2");
context.commitChanges();
context.invalidateObjects(master, master1, detail, detail1);
Expression qual = ExpressionFactory.matchExp("compoundFkArray", detail1);
SelectQuery q = new SelectQuery(CompoundPkTestEntity.class, qual);
List<?> objs = context1.performQuery(q);
assertEquals(1, objs.size());
master = (CompoundPkTestEntity) objs.get(0);
assertEquals("m2", master.getName());
}
use of org.apache.cayenne.testdo.compound.CompoundFkTestEntity in project cayenne by apache.
the class DataContextCompoundRelIT method testFetchQualifyingToOne.
@Test
public void testFetchQualifyingToOne() {
CompoundPkTestEntity master = (CompoundPkTestEntity) context.newObject("CompoundPkTestEntity");
CompoundPkTestEntity master1 = (CompoundPkTestEntity) context.newObject("CompoundPkTestEntity");
CompoundFkTestEntity detail = (CompoundFkTestEntity) context.newObject("CompoundFkTestEntity");
CompoundFkTestEntity detail1 = (CompoundFkTestEntity) context.newObject("CompoundFkTestEntity");
master.addToCompoundFkArray(detail);
master1.addToCompoundFkArray(detail1);
master.setName("m1");
master.setKey1("key11");
master.setKey2("key21");
master1.setName("m2");
master1.setKey1("key12");
master1.setKey2("key22");
detail.setName("d1");
detail1.setName("d2");
context.commitChanges();
context.invalidateObjects(master, master1, detail, detail1);
Expression qual = ExpressionFactory.matchExp("toCompoundPk", master);
SelectQuery q = new SelectQuery(CompoundFkTestEntity.class, qual);
List<?> objs = context1.performQuery(q);
assertEquals(1, objs.size());
detail = (CompoundFkTestEntity) objs.get(0);
assertEquals("d1", detail.getName());
}
Aggregations