use of org.apache.cayenne.query.QueryChain in project cayenne by apache.
the class DataContextEJBQLFunctionalExpressionsIT method testTRIM.
@Test
public void testTRIM() {
// insert via a SQL template to prevent adapter trimming and such...
QueryChain inserts = new QueryChain();
inserts.addQuery(new SQLTemplate(Artist.class, "INSERT INTO ARTIST (ARTIST_ID,ARTIST_NAME) VALUES(1, ' A')"));
inserts.addQuery(new SQLTemplate(Artist.class, "INSERT INTO ARTIST (ARTIST_ID,ARTIST_NAME) VALUES(2, 'A ')"));
context.performGenericQuery(inserts);
Artist a1 = Cayenne.objectForPK(context, Artist.class, 1);
Artist a2 = Cayenne.objectForPK(context, Artist.class, 2);
EJBQLQuery query = new EJBQLQuery("SELECT a FROM Artist a WHERE TRIM(a.artistName) = 'A'");
List<?> objects = context.performQuery(query);
assertEquals(2, objects.size());
assertTrue(objects.contains(a1));
assertTrue(objects.contains(a2));
query = new EJBQLQuery("SELECT a FROM Artist a WHERE TRIM(LEADING FROM a.artistName) = 'A'");
objects = context.performQuery(query);
// this is fuzzy cause some DB trim trailing data by default
assertTrue(objects.size() == 1 || objects.size() == 2);
assertTrue(objects.contains(a1));
query = new EJBQLQuery("SELECT a FROM Artist a WHERE TRIM(TRAILING FROM a.artistName) = 'A'");
objects = context.performQuery(query);
assertEquals(1, objects.size());
assertTrue(objects.contains(a2));
query = new EJBQLQuery("SELECT a FROM Artist a WHERE TRIM(BOTH FROM a.artistName) = 'A'");
objects = context.performQuery(query);
assertEquals(2, objects.size());
assertTrue(objects.contains(a1));
assertTrue(objects.contains(a2));
}
use of org.apache.cayenne.query.QueryChain in project cayenne by apache.
the class DataContextQueryChainIT method testSelectQuery.
@Test
public void testSelectQuery() {
Artist a1 = context.newObject(Artist.class);
a1.setArtistName("X");
context.commitChanges();
QueryChain chain = new QueryChain();
chain.addQuery(new SelectQuery(Artist.class));
chain.addQuery(new SelectQuery(Artist.class));
QueryResponse r = context.performGenericQuery(chain);
// data comes back as datarows
assertEquals(2, r.size());
r.reset();
r.next();
List<?> l1 = r.currentList();
r.next();
List<?> l2 = r.currentList();
assertTrue(l1.get(0) instanceof DataRow);
assertTrue(l2.get(0) instanceof DataRow);
}
Aggregations