Search in sources :

Example 1 with BeanPropertyRowMapper

use of org.springframework.jdbc.core.BeanPropertyRowMapper in project camel by apache.

the class DefaultSqlEndpoint method queryForStreamList.

@SuppressWarnings("unchecked")
public ResultSetIterator queryForStreamList(Connection connection, Statement statement, ResultSet rs) throws SQLException {
    if (outputClass == null) {
        RowMapper rowMapper = new ColumnMapRowMapper();
        return new ResultSetIterator(connection, statement, rs, rowMapper);
    } else {
        Class<?> outputClzz = getCamelContext().getClassResolver().resolveClass(outputClass);
        RowMapper rowMapper = new BeanPropertyRowMapper(outputClzz);
        return new ResultSetIterator(connection, statement, rs, rowMapper);
    }
}
Also used : BeanPropertyRowMapper(org.springframework.jdbc.core.BeanPropertyRowMapper) ColumnMapRowMapper(org.springframework.jdbc.core.ColumnMapRowMapper) BeanPropertyRowMapper(org.springframework.jdbc.core.BeanPropertyRowMapper) RowMapper(org.springframework.jdbc.core.RowMapper) ColumnMapRowMapper(org.springframework.jdbc.core.ColumnMapRowMapper)

Example 2 with BeanPropertyRowMapper

use of org.springframework.jdbc.core.BeanPropertyRowMapper in project camel by apache.

the class DefaultSqlEndpoint method queryForObject.

@SuppressWarnings("unchecked")
public Object queryForObject(ResultSet rs) throws SQLException {
    Object result = null;
    if (outputClass == null) {
        RowMapper rowMapper = new ColumnMapRowMapper();
        RowMapperResultSetExtractor<Map<String, Object>> mapper = new RowMapperResultSetExtractor<Map<String, Object>>(rowMapper);
        List<Map<String, Object>> data = mapper.extractData(rs);
        if (data.size() > 1) {
            throw new SQLDataException("Query result not unique for outputType=SelectOne. Got " + data.size() + " count instead.");
        } else if (data.size() == 1) {
            // Set content depend on number of column from query result
            Map<String, Object> row = data.get(0);
            if (row.size() == 1) {
                result = row.values().iterator().next();
            } else {
                result = row;
            }
        }
    } else {
        Class<?> outputClzz = getCamelContext().getClassResolver().resolveClass(outputClass);
        RowMapper rowMapper = new BeanPropertyRowMapper(outputClzz);
        RowMapperResultSetExtractor<?> mapper = new RowMapperResultSetExtractor(rowMapper);
        List<?> data = mapper.extractData(rs);
        if (data.size() > 1) {
            throw new SQLDataException("Query result not unique for outputType=SelectOne. Got " + data.size() + " count instead.");
        } else if (data.size() == 1) {
            result = data.get(0);
        }
    }
    // If data.size is zero, let result be null.
    return result;
}
Also used : ColumnMapRowMapper(org.springframework.jdbc.core.ColumnMapRowMapper) BeanPropertyRowMapper(org.springframework.jdbc.core.BeanPropertyRowMapper) SQLDataException(java.sql.SQLDataException) RowMapperResultSetExtractor(org.springframework.jdbc.core.RowMapperResultSetExtractor) Map(java.util.Map) BeanPropertyRowMapper(org.springframework.jdbc.core.BeanPropertyRowMapper) RowMapper(org.springframework.jdbc.core.RowMapper) ColumnMapRowMapper(org.springframework.jdbc.core.ColumnMapRowMapper)

Example 3 with BeanPropertyRowMapper

use of org.springframework.jdbc.core.BeanPropertyRowMapper in project camel by apache.

the class DefaultSqlEndpoint method queryForList.

@SuppressWarnings("unchecked")
public List<?> queryForList(ResultSet rs, boolean allowMapToClass) throws SQLException {
    if (allowMapToClass && outputClass != null) {
        Class<?> outputClazz = getCamelContext().getClassResolver().resolveClass(outputClass);
        RowMapper rowMapper = new BeanPropertyRowMapper(outputClazz);
        RowMapperResultSetExtractor<?> mapper = new RowMapperResultSetExtractor(rowMapper);
        List<?> data = mapper.extractData(rs);
        return data;
    } else {
        ColumnMapRowMapper rowMapper = new ColumnMapRowMapper();
        RowMapperResultSetExtractor<Map<String, Object>> mapper = new RowMapperResultSetExtractor<Map<String, Object>>(rowMapper);
        List<Map<String, Object>> data = mapper.extractData(rs);
        return data;
    }
}
Also used : BeanPropertyRowMapper(org.springframework.jdbc.core.BeanPropertyRowMapper) ColumnMapRowMapper(org.springframework.jdbc.core.ColumnMapRowMapper) RowMapperResultSetExtractor(org.springframework.jdbc.core.RowMapperResultSetExtractor) Map(java.util.Map) BeanPropertyRowMapper(org.springframework.jdbc.core.BeanPropertyRowMapper) RowMapper(org.springframework.jdbc.core.RowMapper) ColumnMapRowMapper(org.springframework.jdbc.core.ColumnMapRowMapper)

Example 4 with BeanPropertyRowMapper

use of org.springframework.jdbc.core.BeanPropertyRowMapper in project Gargoyle by callakrsos.

the class MacroFavorDAO method getRoots.

/**
	 * 루트 데이터 리턴
	 * 
	 * @inheritDoc
	 */
public List<MacroItemVO> getRoots() throws Exception {
    List<MacroItemVO> select = Collections.emptyList();
    try (Connection connection = getConnection()) {
        String sql = "select * from  meerkat.tbm_sys_fav_macro_sql where parent_macro_id is null";
        select = DbUtil.select(connection, sql, 10, new BeanPropertyRowMapper<>(MacroItemVO.class));
    }
    System.out.println(select);
    return select;
}
Also used : BeanPropertyRowMapper(org.springframework.jdbc.core.BeanPropertyRowMapper) Connection(java.sql.Connection)

Aggregations

BeanPropertyRowMapper (org.springframework.jdbc.core.BeanPropertyRowMapper)4 ColumnMapRowMapper (org.springframework.jdbc.core.ColumnMapRowMapper)3 RowMapper (org.springframework.jdbc.core.RowMapper)3 Map (java.util.Map)2 RowMapperResultSetExtractor (org.springframework.jdbc.core.RowMapperResultSetExtractor)2 Connection (java.sql.Connection)1 SQLDataException (java.sql.SQLDataException)1