use of org.apache.cayenne.query.SQLTemplate in project cayenne by apache.
the class SQLTemplateActionIT method selectObjects.
@Test
public void selectObjects() throws Exception {
createFourArtists();
String templateString = "SELECT * FROM ARTIST";
SQLTemplate sqlTemplate = new SQLTemplate(Artist.class, templateString);
if (unitDbAdapter.isLowerCaseNames()) {
sqlTemplate.setColumnNamesCapitalization(CapsStrategy.UPPER);
}
@SuppressWarnings("unchecked") List<Artist> artists = (List<Artist>) objectContext.performQuery(sqlTemplate);
assertEquals(4, artists.size());
for (Artist artist : artists) {
assertTrue(artist.getArtistName().startsWith("artist"));
}
}
use of org.apache.cayenne.query.SQLTemplate in project cayenne by apache.
the class EJBQLSelectTranslatorIT method testSelectFromWhereLess.
@Test
public void testSelectFromWhereLess() {
SQLTemplate query = translateSelect("select p from Painting p where p.estimatedPrice < 1.0");
String sql = query.getDefaultTemplate();
assertTrue(sql, sql.endsWith("WHERE t0.ESTIMATED_PRICE < #bind($id0 'DECIMAL')"));
}
use of org.apache.cayenne.query.SQLTemplate in project cayenne by apache.
the class EJBQLSelectTranslatorIT method testSelectFromWhereNot.
@Test
public void testSelectFromWhereNot() {
SQLTemplate query = translateSelect("select a from Artist a where not (a.artistName = 'Dali')");
String sql = query.getDefaultTemplate();
assertTrue(sql, sql.startsWith("SELECT"));
assertTrue(sql, sql.endsWith("WHERE NOT " + "t0.ARTIST_NAME = #bind('Dali' 'VARCHAR')"));
}
use of org.apache.cayenne.query.SQLTemplate in project cayenne by apache.
the class EJBQLSelectTranslatorIT method testSelectFromWhereBetween.
@Test
public void testSelectFromWhereBetween() {
SQLTemplate query = translateSelect("select p from Painting p where p.estimatedPrice between 3 and 5");
String sql = query.getDefaultTemplate();
assertTrue(sql, sql.endsWith("WHERE t0.ESTIMATED_PRICE " + "BETWEEN #bind($id0 'INTEGER') AND #bind($id1 'INTEGER')"));
}
use of org.apache.cayenne.query.SQLTemplate in project cayenne by apache.
the class EJBQLSelectTranslatorIT method testSelectMultipleJoinsToTheSameTable.
@Test
public void testSelectMultipleJoinsToTheSameTable() throws Exception {
SQLTemplate query = translateSelect("SELECT a " + "FROM Artist a JOIN a.paintingArray b JOIN a.paintingArray c " + "WHERE b.paintingTitle = 'P1' AND c.paintingTitle = 'P2'");
String sql = query.getDefaultTemplate();
assertTrue(sql, sql.startsWith("SELECT"));
assertTrue(sql, sql.indexOf("INNER JOIN PAINTING t1 ON (t0.ARTIST_ID = t1.ARTIST_ID)") > 0);
assertTrue(sql, sql.indexOf("INNER JOIN PAINTING t2 ON (t0.ARTIST_ID = t2.ARTIST_ID)") > 0);
}
Aggregations