use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.
the class DataContextEJBQLSubqueryIT method testExists.
@Test
public void testExists() throws Exception {
createTwoArtistsFourPaintings();
String ejbql = "SELECT p FROM Painting p" + " WHERE EXISTS (" + " SELECT DISTINCT p1.paintingTitle FROM Painting p1" + " WHERE p1.paintingTitle = p.paintingTitle" + " AND p.estimatedPrice <> p1.estimatedPrice" + ")";
EJBQLQuery query = new EJBQLQuery(ejbql);
List<?> objects = context.performQuery(query);
assertEquals(2, objects.size());
Set<Object> ids = new HashSet<Object>();
Iterator<?> it = objects.iterator();
while (it.hasNext()) {
Object id = Cayenne.pkForObject((Persistent) it.next());
ids.add(id);
}
assertTrue(ids.contains(new Integer(33001)));
assertTrue(ids.contains(new Integer(33003)));
}
use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.
the class DataContextEJBQLSubqueryIT method testAny.
@Test
public void testAny() throws Exception {
if (!accessStackAdapter.supportsAllAnySome()) {
return;
}
createTwoArtistsFourPaintings();
String ejbql = "SELECT p FROM Painting p" + " WHERE p.estimatedPrice > ANY (" + " SELECT p1.estimatedPrice FROM Painting p1" + " WHERE p1.paintingTitle = 'P1'" + ")";
EJBQLQuery query = new EJBQLQuery(ejbql);
List<?> objects = context.performQuery(query);
assertEquals(3, objects.size());
Set<Object> ids = new HashSet<Object>();
Iterator<?> it = objects.iterator();
while (it.hasNext()) {
Object id = Cayenne.pkForObject((Persistent) it.next());
ids.add(id);
}
assertTrue(ids.contains(new Integer(33002)));
assertTrue(ids.contains(new Integer(33003)));
assertTrue(ids.contains(new Integer(33004)));
}
use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.
the class DataContextEJBQLSubqueryIT method testSome.
@Test
public void testSome() throws Exception {
if (!accessStackAdapter.supportsAllAnySome()) {
return;
}
createTwoArtistsFourPaintings();
String ejbql = "SELECT p FROM Painting p" + " WHERE p.estimatedPrice > SOME (" + " SELECT p1.estimatedPrice FROM Painting p1" + " WHERE p1.paintingTitle = 'P1'" + ")";
EJBQLQuery query = new EJBQLQuery(ejbql);
List<?> objects = context.performQuery(query);
assertEquals(3, objects.size());
Set<Object> ids = new HashSet<Object>();
Iterator<?> it = objects.iterator();
while (it.hasNext()) {
Object id = Cayenne.pkForObject((Persistent) it.next());
ids.add(id);
}
assertTrue(ids.contains(new Integer(33002)));
assertTrue(ids.contains(new Integer(33003)));
assertTrue(ids.contains(new Integer(33004)));
}
use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.
the class DataContextEJBQLSubqueryIT method testSubqueryNoQualifier.
@Test
public void testSubqueryNoQualifier() throws Exception {
if (!accessStackAdapter.supportsAllAnySome()) {
return;
}
createTwoArtistsFourPaintings();
String ejbql = "SELECT DISTINCT p FROM Painting p" + " WHERE p.estimatedPrice = ALL (" + " SELECT MAX(p1.estimatedPrice) FROM Painting p1" + ")";
EJBQLQuery query = new EJBQLQuery(ejbql);
List<?> objects = context.performQuery(query);
assertEquals(1, objects.size());
Set<Object> ids = new HashSet<Object>();
Iterator<?> it = objects.iterator();
while (it.hasNext()) {
Object id = Cayenne.pkForObject((Persistent) it.next());
ids.add(id);
}
assertTrue(ids.contains(new Integer(33004)));
}
use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.
the class DataContextEJBQLUpdateIT method testUpdateNoQualifierDecimal.
@Test
public void testUpdateNoQualifierDecimal() throws Exception {
createThreeArtistsTwoPaintings();
EJBQLQuery check = new EJBQLQuery("select count(p) from Painting p " + "WHERE p.estimatedPrice is NULL or p.estimatedPrice <> 1.1");
Object notUpdated = Cayenne.objectForQuery(context, check);
assertEquals(new Long(2l), notUpdated);
String ejbql = "UPDATE Painting AS p SET p.estimatedPrice = 1.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