use of org.apache.cayenne.query.SQLTemplate in project cayenne by apache.
the class EJBQLSelectTranslatorIT method testSelectFromWhereOrEqual.
@Test
public void testSelectFromWhereOrEqual() {
SQLTemplate query = translateSelect("select a from Artist a where a.artistName = 'Dali' " + "or a.artistName = 'Malevich'");
String sql = query.getDefaultTemplate();
SQLTemplate query1 = translateSelect("select a from Artist a where a.artistName = 'Picasso' " + "or a.artistName = 'Malevich' " + "or a.artistName = 'Dali'");
String sql1 = query1.getDefaultTemplate();
assertTrue(sql, sql.startsWith("SELECT"));
assertTrue(sql, sql.indexOf(" FROM ARTIST t0 WHERE ") > 0);
assertEquals(1, countDelimiters(sql, " OR ", sql.indexOf("WHERE ")));
assertTrue(sql1, sql1.startsWith("SELECT"));
assertTrue(sql1, sql.indexOf(" FROM ARTIST t0 WHERE ") > 0);
assertEquals(2, countDelimiters(sql1, " OR ", sql.indexOf("WHERE ")));
}
use of org.apache.cayenne.query.SQLTemplate in project cayenne by apache.
the class EJBQLSelectTranslatorIT method testColumnPaths.
@Test
public void testColumnPaths() {
SQLTemplate query = translateSelect("select p.estimatedPrice, p.toArtist.artistName from Painting p");
String sql = query.getDefaultTemplate();
assertTrue(sql, sql.startsWith("SELECT " + "#result('t0.ESTIMATED_PRICE' 'java.math.BigDecimal' 'sc0' 'sc0' 3), " + "#result('t1.ARTIST_NAME' 'java.lang.String' 'sc1' 'sc1' 1) FROM"));
}
use of org.apache.cayenne.query.SQLTemplate in project cayenne by apache.
the class EJBQLSelectTranslatorIT method testSelectFromWhereEqual.
@Test
public void testSelectFromWhereEqual() {
SQLTemplate query = translateSelect("select a from Artist a where a.artistName = 'Dali'");
String sql = query.getDefaultTemplate();
assertTrue(sql, sql.startsWith("SELECT"));
assertTrue(sql, sql.endsWith(" FROM ARTIST t0 WHERE t0.ARTIST_NAME =" + " #bind('Dali' 'VARCHAR')"));
}
use of org.apache.cayenne.query.SQLTemplate in project cayenne by apache.
the class EJBQLSelectTranslatorIT method testMax.
@Test
public void testMax() {
SQLTemplate query = translateSelect("select max(p.estimatedPrice) from Painting p");
String sql = query.getDefaultTemplate();
assertTrue(sql, sql.startsWith("SELECT " + "#result('MAX(t0.ESTIMATED_PRICE)' 'java.math.BigDecimal' 'sc0') " + "FROM PAINTING t0"));
}
use of org.apache.cayenne.query.SQLTemplate in project cayenne by apache.
the class EJBQLSelectTranslatorIT method testSelectFromWhereGreaterOrEqual.
@Test
public void testSelectFromWhereGreaterOrEqual() {
SQLTemplate query = translateSelect("select p from Painting p where p.estimatedPrice >= 2");
String sql = query.getDefaultTemplate();
assertTrue(sql, sql.endsWith("WHERE t0.ESTIMATED_PRICE >= #bind($id0 'INTEGER')"));
}
Aggregations