Search in sources :

Example 1 with CompoundFkTestEntity

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));
}
Also used : CompoundPkTestEntity(org.apache.cayenne.testdo.compound.CompoundPkTestEntity) SQLTemplate(org.apache.cayenne.query.SQLTemplate) HashMap(java.util.HashMap) CompoundFkTestEntity(org.apache.cayenne.testdo.compound.CompoundFkTestEntity) Test(org.junit.Test)

Example 2 with CompoundFkTestEntity

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());
}
Also used : List(java.util.List) CompoundFkTestEntity(org.apache.cayenne.testdo.compound.CompoundFkTestEntity) Test(org.junit.Test)

Example 3 with CompoundFkTestEntity

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));
}
Also used : CompoundPkTestEntity(org.apache.cayenne.testdo.compound.CompoundPkTestEntity) HashMap(java.util.HashMap) EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) CompoundFkTestEntity(org.apache.cayenne.testdo.compound.CompoundFkTestEntity) Test(org.junit.Test)

Example 4 with CompoundFkTestEntity

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());
}
Also used : CompoundPkTestEntity(org.apache.cayenne.testdo.compound.CompoundPkTestEntity) SelectQuery(org.apache.cayenne.query.SelectQuery) Expression(org.apache.cayenne.exp.Expression) CompoundFkTestEntity(org.apache.cayenne.testdo.compound.CompoundFkTestEntity) Test(org.junit.Test)

Example 5 with CompoundFkTestEntity

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());
}
Also used : CompoundPkTestEntity(org.apache.cayenne.testdo.compound.CompoundPkTestEntity) SelectQuery(org.apache.cayenne.query.SelectQuery) Expression(org.apache.cayenne.exp.Expression) CompoundFkTestEntity(org.apache.cayenne.testdo.compound.CompoundFkTestEntity) Test(org.junit.Test)

Aggregations

CompoundFkTestEntity (org.apache.cayenne.testdo.compound.CompoundFkTestEntity)9 Test (org.junit.Test)9 CompoundPkTestEntity (org.apache.cayenne.testdo.compound.CompoundPkTestEntity)8 HashMap (java.util.HashMap)5 EJBQLQuery (org.apache.cayenne.query.EJBQLQuery)3 SelectQuery (org.apache.cayenne.query.SelectQuery)3 Expression (org.apache.cayenne.exp.Expression)2 SQLTemplate (org.apache.cayenne.query.SQLTemplate)2 List (java.util.List)1