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);
}
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());
}
Aggregations