Search in sources :

Example 21 with SQLTemplate

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 ")));
}
Also used : SQLTemplate(org.apache.cayenne.query.SQLTemplate) Test(org.junit.Test)

Example 22 with SQLTemplate

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"));
}
Also used : SQLTemplate(org.apache.cayenne.query.SQLTemplate) Test(org.junit.Test)

Example 23 with SQLTemplate

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')"));
}
Also used : SQLTemplate(org.apache.cayenne.query.SQLTemplate) Test(org.junit.Test)

Example 24 with SQLTemplate

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"));
}
Also used : SQLTemplate(org.apache.cayenne.query.SQLTemplate) Test(org.junit.Test)

Example 25 with SQLTemplate

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')"));
}
Also used : SQLTemplate(org.apache.cayenne.query.SQLTemplate) Test(org.junit.Test)

Aggregations

SQLTemplate (org.apache.cayenne.query.SQLTemplate)118 Test (org.junit.Test)108 Artist (org.apache.cayenne.testdo.testmap.Artist)27 DataRow (org.apache.cayenne.DataRow)18 HashMap (java.util.HashMap)16 MockOperationObserver (org.apache.cayenne.access.MockOperationObserver)14 Query (org.apache.cayenne.query.Query)14 SelectQuery (org.apache.cayenne.query.SelectQuery)11 Painting (org.apache.cayenne.testdo.testmap.Painting)11 List (java.util.List)8 Connection (java.sql.Connection)7 SQLAction (org.apache.cayenne.query.SQLAction)7 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)6 Map (java.util.Map)5 OperationObserver (org.apache.cayenne.access.OperationObserver)5 DataMap (org.apache.cayenne.map.DataMap)5 AbstractPerson (org.apache.cayenne.testdo.inheritance_people.AbstractPerson)5 PersonNotes (org.apache.cayenne.testdo.inheritance_people.PersonNotes)5 Date (java.sql.Date)4 FrontBaseAdapter (org.apache.cayenne.dba.frontbase.FrontBaseAdapter)4