Search in sources :

Example 16 with CompoundPkTestEntity

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

the class DataContextEJBQLUpdateCompoundIT method testUpdateNoQualifierToOneCompoundPK.

@Test
public void testUpdateNoQualifierToOneCompoundPK() throws Exception {
    createTwoCompoundPKTwoFK();
    Map<String, String> key1 = new HashMap<>();
    key1.put(CompoundPkTestEntity.KEY1_PK_COLUMN, "b1");
    key1.put(CompoundPkTestEntity.KEY2_PK_COLUMN, "b2");
    CompoundPkTestEntity object = Cayenne.objectForPK(context, CompoundPkTestEntity.class, key1);
    EJBQLQuery check = new EJBQLQuery("select count(e) from CompoundFkTestEntity e WHERE e.toCompoundPk <> :param");
    check.setParameter("param", object);
    Object notUpdated = Cayenne.objectForQuery(context, check);
    assertEquals(new Long(1l), notUpdated);
    String ejbql = "UPDATE CompoundFkTestEntity e SET e.toCompoundPk = :param";
    EJBQLQuery query = new EJBQLQuery(ejbql);
    query.setParameter("param", object);
    QueryResponse result = context.performGenericQuery(query);
    int[] count = result.firstUpdateCount();
    assertNotNull(count);
    assertEquals(1, count.length);
    assertEquals(2, count[0]);
    notUpdated = Cayenne.objectForQuery(context, check);
    assertEquals(new Long(0l), notUpdated);
}
Also used : CompoundPkTestEntity(org.apache.cayenne.testdo.compound.CompoundPkTestEntity) HashMap(java.util.HashMap) EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) QueryResponse(org.apache.cayenne.QueryResponse) Test(org.junit.Test)

Example 17 with CompoundPkTestEntity

use of org.apache.cayenne.testdo.compound.CompoundPkTestEntity 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);
    List<CompoundPkTestEntity> objs = ObjectSelect.query(CompoundPkTestEntity.class).select(context1);
    assertEquals(1, objs.size());
    assertEquals("m1", objs.get(0).getName());
    List<CompoundFkTestEntity> details = objs.get(0).getCompoundFkArray();
    assertEquals(1, details.size());
    assertEquals("d1", details.get(0).getName());
}
Also used : CompoundPkTestEntity(org.apache.cayenne.testdo.compound.CompoundPkTestEntity) 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