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

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

Introduction

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

Prototype

public List<T> execute() throws DataAccessException 

Source Link

Document

Convenient method to execute without parameters nor context.

Usage

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

public void testQueryWithoutParams() throws SQLException {
    mockResultSet.next();/*from w w w .jav  a2  s . co 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);
    }
}