Example usage for org.springframework.jdbc.object MappingSqlQuery MappingSqlQuery

List of usage examples for org.springframework.jdbc.object MappingSqlQuery MappingSqlQuery

Introduction

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

Prototype

public MappingSqlQuery() 

Source Link

Document

Constructor that allows use as a JavaBean.

Usage

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

public void testQueryWithoutEnoughParams() {
    replay();/*from   ww w  . j a  va2 s.c o m*/

    MappingSqlQuery query = new MappingSqlQuery() {
        protected Object mapRow(ResultSet rs, int rownum) throws SQLException {
            return new Integer(rs.getInt(1));
        }

    };
    query.setDataSource(mockDataSource);
    query.setSql(SELECT_ID_WHERE);
    query.declareParameter(new SqlParameter(COLUMN_NAMES[0], COLUMN_TYPES[0]));
    query.declareParameter(new SqlParameter(COLUMN_NAMES[1], COLUMN_TYPES[1]));
    query.compile();

    try {
        List list = query.execute();
        fail("Shouldn't succeed in running query without enough params");
    } catch (InvalidDataAccessApiUsageException ex) {
        // OK
    }
}

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

public void testQueryWithMissingMapParams() {
    replay();//from  w ww . j a v a 2  s  . c o m

    MappingSqlQuery query = new MappingSqlQuery() {
        protected Object mapRow(ResultSet rs, int rownum) throws SQLException {
            return new Integer(rs.getInt(1));
        }
    };
    query.setDataSource(mockDataSource);
    query.setSql(SELECT_ID_WHERE);
    query.declareParameter(new SqlParameter(COLUMN_NAMES[0], COLUMN_TYPES[0]));
    query.declareParameter(new SqlParameter(COLUMN_NAMES[1], COLUMN_TYPES[1]));
    query.compile();

    try {
        Map params = new HashMap();
        params.put(COLUMN_NAMES[0], "Value");
        List list = query.executeByNamedParam(params);
        fail("Shouldn't succeed in running query with missing params");
    } catch (InvalidDataAccessApiUsageException ex) {
        // OK
    }
}