Example usage for org.springframework.jdbc.object SqlQuery compile

List of usage examples for org.springframework.jdbc.object SqlQuery compile

Introduction

In this page you can find the example usage for org.springframework.jdbc.object SqlQuery compile.

Prototype

public final void compile() throws InvalidDataAccessApiUsageException 

Source Link

Document

Compile this query.

Usage

From source file:org.springframework.jdbc.object.SqlQueryTests.java

public void testQueryWithoutParams() throws SQLException {
    mockResultSet.next();/*  w  ww  .  jav  a 2 s .  c o m*/
    ctrlResultSet.setReturnValue(true);
    mockResultSet.getInt(1);
    ctrlResultSet.setReturnValue(1);
    mockResultSet.next();
    ctrlResultSet.setReturnValue(false);
    mockResultSet.close();
    ctrlResultSet.setVoidCallable();

    mockPreparedStatement.executeQuery();
    ctrlPreparedStatement.setReturnValue(mockResultSet);
    if (debugEnabled) {
        mockPreparedStatement.getWarnings();
        ctrlPreparedStatement.setReturnValue(null);
    }
    mockPreparedStatement.close();
    ctrlPreparedStatement.setVoidCallable();

    mockConnection.prepareStatement(SELECT_ID);
    ctrlConnection.setReturnValue(mockPreparedStatement);

    replay();

    SqlQuery query = new MappingSqlQueryWithParameters() {
        protected Object mapRow(ResultSet rs, int rownum, Object[] params, Map context) throws SQLException {
            assertTrue("params were null", params == null);
            assertTrue("context was null", context == null);
            return new Integer(rs.getInt(1));
        }
    };

    query.setDataSource(mockDataSource);
    query.setSql(SELECT_ID);
    query.compile();
    List list = query.execute();
    assertTrue("Found customers", list.size() != 0);
    for (Iterator itr = list.iterator(); itr.hasNext();) {
        Integer id = (Integer) itr.next();
        assertTrue("Customer id was assigned correctly", id.intValue() == 1);
    }
}