Search in sources :

Example 16 with SQLTemplate

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

Example 17 with SQLTemplate

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

Example 18 with SQLTemplate

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

Example 19 with SQLTemplate

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

Example 20 with SQLTemplate

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);
}
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