Search in sources :

Example 1 with CompoundPkTestEntity

use of org.apache.cayenne.testdo.compound.CompoundPkTestEntity in project cayenne by apache.

the class DataContextCompoundRelIT method testFetchQualifyingToOne.

@Test
public void testFetchQualifyingToOne() {
    CompoundPkTestEntity master = context.newObject(CompoundPkTestEntity.class);
    CompoundPkTestEntity master1 = context.newObject(CompoundPkTestEntity.class);
    CompoundFkTestEntity detail = context.newObject(CompoundFkTestEntity.class);
    CompoundFkTestEntity detail1 = context.newObject(CompoundFkTestEntity.class);
    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);
    List<CompoundFkTestEntity> objs = ObjectSelect.query(CompoundFkTestEntity.class).where(CompoundFkTestEntity.TO_COMPOUND_PK.eq(master)).select(context1);
    assertEquals(1, objs.size());
    assertEquals("d1", objs.get(0).getName());
}
Also used : CompoundPkTestEntity(org.apache.cayenne.testdo.compound.CompoundPkTestEntity) CompoundFkTestEntity(org.apache.cayenne.testdo.compound.CompoundFkTestEntity) Test(org.junit.Test)

Example 2 with CompoundPkTestEntity

use of org.apache.cayenne.testdo.compound.CompoundPkTestEntity in project cayenne by apache.

the class DataContextCompoundRelIT method testFetchQualifyingToMany.

@Test
public void testFetchQualifyingToMany() {
    CompoundPkTestEntity master = context.newObject(CompoundPkTestEntity.class);
    CompoundPkTestEntity master1 = context.newObject(CompoundPkTestEntity.class);
    CompoundFkTestEntity detail = context.newObject(CompoundFkTestEntity.class);
    CompoundFkTestEntity detail1 = context.newObject(CompoundFkTestEntity.class);
    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);
    List<CompoundPkTestEntity> objs = ObjectSelect.query(CompoundPkTestEntity.class).where(CompoundPkTestEntity.COMPOUND_FK_ARRAY.contains(detail1)).select(context1);
    assertEquals(1, objs.size());
    assertEquals("m2", objs.get(0).getName());
}
Also used : CompoundPkTestEntity(org.apache.cayenne.testdo.compound.CompoundPkTestEntity) CompoundFkTestEntity(org.apache.cayenne.testdo.compound.CompoundFkTestEntity) Test(org.junit.Test)

Example 3 with CompoundPkTestEntity

use of org.apache.cayenne.testdo.compound.CompoundPkTestEntity 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 4 with CompoundPkTestEntity

use of org.apache.cayenne.testdo.compound.CompoundPkTestEntity 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 5 with CompoundPkTestEntity

use of org.apache.cayenne.testdo.compound.CompoundPkTestEntity 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)

Aggregations

CompoundPkTestEntity (org.apache.cayenne.testdo.compound.CompoundPkTestEntity)17 Test (org.junit.Test)17 CompoundFkTestEntity (org.apache.cayenne.testdo.compound.CompoundFkTestEntity)9 HashMap (java.util.HashMap)7 EJBQLQuery (org.apache.cayenne.query.EJBQLQuery)4 ObjectIdQuery (org.apache.cayenne.query.ObjectIdQuery)2 SQLTemplate (org.apache.cayenne.query.SQLTemplate)2 List (java.util.List)1 BaseDataObject (org.apache.cayenne.BaseDataObject)1 QueryResponse (org.apache.cayenne.QueryResponse)1 SQLGenerationVisitor (org.apache.cayenne.access.sqlbuilder.SQLGenerationVisitor)1 StringBuilderAppendable (org.apache.cayenne.access.sqlbuilder.StringBuilderAppendable)1 Node (org.apache.cayenne.access.sqlbuilder.sqltree.Node)1