Search in sources :

Example 16 with MockOperationObserver

use of org.apache.cayenne.access.MockOperationObserver in project cayenne by apache.

the class SQLTemplateActionIT method testSelectUtilDate.

@Test
public void testSelectUtilDate() throws Exception {
    createFourArtists();
    String templateString = "SELECT #result('DATE_OF_BIRTH' 'java.util.Date' 'DOB') " + "FROM ARTIST WHERE ARTIST_ID = #bind($id)";
    SQLTemplate template = new SQLTemplate(Object.class, templateString);
    sqlTemplateCustomizer.updateSQLTemplate(template);
    Map<String, Object> bindings = new HashMap<>();
    bindings.put("id", 101);
    template.setParameters(bindings);
    SQLAction plan = adapter.getAction(template, node);
    MockOperationObserver observer = new MockOperationObserver();
    try (Connection c = dataSourceFactory.getSharedDataSource().getConnection()) {
        plan.performAction(c, observer);
    }
    List<DataRow> rows = observer.rowsForQuery(template);
    assertNotNull(rows);
    assertEquals(1, rows.size());
    DataRow row = rows.get(0);
    assertNotNull(row.get("DOB"));
    assertEquals(java.util.Date.class, row.get("DOB").getClass());
}
Also used : SQLTemplate(org.apache.cayenne.query.SQLTemplate) HashMap(java.util.HashMap) Connection(java.sql.Connection) SQLAction(org.apache.cayenne.query.SQLAction) MockOperationObserver(org.apache.cayenne.access.MockOperationObserver) DataRow(org.apache.cayenne.DataRow) Test(org.junit.Test)

Aggregations

MockOperationObserver (org.apache.cayenne.access.MockOperationObserver)16 SQLTemplate (org.apache.cayenne.query.SQLTemplate)14 Test (org.junit.Test)14 HashMap (java.util.HashMap)8 Connection (java.sql.Connection)7 SQLAction (org.apache.cayenne.query.SQLAction)7 DataRow (org.apache.cayenne.DataRow)5 Query (org.apache.cayenne.query.Query)3 PreparedStatementResultSetHandler (com.mockrunner.jdbc.PreparedStatementResultSetHandler)2 MockConnection (com.mockrunner.mock.jdbc.MockConnection)2 Date (java.sql.Date)2 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)2 DataNode (org.apache.cayenne.access.DataNode)2 RowReaderFactory (org.apache.cayenne.access.jdbc.reader.RowReaderFactory)2 DeleteBatchTranslator (org.apache.cayenne.access.translator.batch.DeleteBatchTranslator)2 JdbcAdapter (org.apache.cayenne.dba.JdbcAdapter)2 DbAttribute (org.apache.cayenne.map.DbAttribute)2 DbEntity (org.apache.cayenne.map.DbEntity)2 EntityResolver (org.apache.cayenne.map.EntityResolver)2 DeleteBatchQuery (org.apache.cayenne.query.DeleteBatchQuery)2