Search in sources :

Example 6 with CompoundFkTestEntity

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));
}
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 7 with CompoundFkTestEntity

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));
}
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 8 with CompoundFkTestEntity

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));
}
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 9 with CompoundFkTestEntity

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