use of org.apache.cayenne.testdo.compound.CompoundFkTestEntity in project cayenne by apache.
the class DataContextEJBQLQueryCompoundIT method testSelectFromWhereMatchOnMultiColumnObjectReverse.
@Test
public void testSelectFromWhereMatchOnMultiColumnObjectReverse() throws Exception {
if (!accessStackAdapter.supportsReverseComparison()) {
return;
}
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 :param = e.toCompoundPk";
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 DataContextEJBQLQueryCompoundIT method testSelectFromWhereNoMatchOnMultiColumnObject.
@Test
public void testSelectFromWhereNoMatchOnMultiColumnObject() 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(33001, Cayenne.intPKForObject(o1));
}
use of org.apache.cayenne.testdo.compound.CompoundFkTestEntity in project cayenne by apache.
the class DataContextSQLTemplateCompoundIT method testBindObjectNotEqualCompound.
@Test
public void testBindObjectNotEqualCompound() 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 #bindObjectNotEqual($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(7, Cayenne.intPKForObject(p));
}
use of org.apache.cayenne.testdo.compound.CompoundFkTestEntity in project cayenne by apache.
the class DataContextCompoundRelIT method testInsert.
@Test
public void testInsert() {
CompoundPkTestEntity master = context.newObject(CompoundPkTestEntity.class);
CompoundFkTestEntity detail = context.newObject(CompoundFkTestEntity.class);
master.addToCompoundFkArray(detail);
master.setName("m1");
master.setKey1("key11");
master.setKey2("key21");
detail.setName("d1");
context.commitChanges();
context.invalidateObjects(master, detail);
SelectQuery q = new SelectQuery(CompoundPkTestEntity.class);
List<?> objs = context1.performQuery(q);
assertEquals(1, objs.size());
master = (CompoundPkTestEntity) objs.get(0);
assertEquals("m1", master.getName());
List<?> details = master.getCompoundFkArray();
assertEquals(1, details.size());
detail = (CompoundFkTestEntity) details.get(0);
assertEquals("d1", detail.getName());
}
Aggregations