use of org.apache.cayenne.QueryResponse in project cayenne by apache.
the class DataContextEJBQLDeleteIT method testDeleteNoIdVar.
@Test
public void testDeleteNoIdVar() throws Exception {
createPaintingsDataSet();
String ejbql = "delete from Painting";
EJBQLQuery query = new EJBQLQuery(ejbql);
QueryResponse result = context.performGenericQuery(query);
int[] count = result.firstUpdateCount();
assertNotNull(count);
assertEquals(1, count.length);
assertEquals(2, count[0]);
}
use of org.apache.cayenne.QueryResponse in project cayenne by apache.
the class DataContextEJBQLDeleteIT method testDeleteSameEntityQualifier.
@Test
public void testDeleteSameEntityQualifier() throws Exception {
createPaintingsDataSet();
String ejbql = "delete from Painting AS p WHERE p.paintingTitle = 'P2'";
EJBQLQuery query = new EJBQLQuery(ejbql);
QueryResponse result = context.performGenericQuery(query);
int[] count = result.firstUpdateCount();
assertNotNull(count);
assertEquals(1, count.length);
assertEquals(1, count[0]);
ObjectContext freshContext = runtime.newContext();
assertNotNull(Cayenne.objectForPK(freshContext, Painting.class, 33001));
assertNull(Cayenne.objectForPK(freshContext, Painting.class, 33002));
}
use of org.apache.cayenne.QueryResponse 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.QueryResponse in project cayenne by apache.
the class DataContextEJBQLUpdateIT method testUpdateNoQualifierString.
@Test
public void testUpdateNoQualifierString() throws Exception {
createThreeArtistsTwoPaintings();
EJBQLQuery check = new EJBQLQuery("select count(p) from Painting p " + "WHERE p.paintingTitle is NULL or p.paintingTitle <> 'XX'");
Object notUpdated = Cayenne.objectForQuery(context, check);
assertEquals(new Long(2l), notUpdated);
String ejbql = "UPDATE Painting AS p SET p.paintingTitle = 'XX'";
EJBQLQuery query = new EJBQLQuery(ejbql);
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.QueryResponse in project cayenne by apache.
the class DataContextEJBQLUpdateIT method testUpdateNoQualifierMultipleItems.
// This fails until we implement arithmetic exps
// public void testUpdateNoQualifierArithmeticExpression() throws Exception {
// createThreeArtistsTwoPaintings();
//
//
// EJBQLQuery check = new EJBQLQuery("select count(p) from Painting p "
// + "WHERE p.paintingTitle is NULL or p.estimatedPrice <= 5000");
//
// Object notUpdated = Cayenne.objectForQuery(context, check);
// assertEquals(new Long(2l), notUpdated);
//
// String ejbql = "UPDATE Painting AS p SET p.estimatedPrice = p.estimatedPrice * 2";
// EJBQLQuery query = new EJBQLQuery(ejbql);
//
// 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);
// }
@Test
public void testUpdateNoQualifierMultipleItems() throws Exception {
createThreeArtistsTwoPaintings();
EJBQLQuery check = new EJBQLQuery("select count(p) from Painting p " + "WHERE p.estimatedPrice is NULL or p.estimatedPrice <> 1");
Object notUpdated = Cayenne.objectForQuery(context, check);
assertEquals(new Long(2l), notUpdated);
String ejbql = "UPDATE Painting AS p SET p.paintingTitle = 'XX', p.estimatedPrice = 1";
EJBQLQuery query = new EJBQLQuery(ejbql);
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);
}
Aggregations