use of org.springframework.jdbc.core.RowMapperResultSetExtractor in project dhis2-core by dhis2.
the class JdbcUtils method generatedKeys.
private static void generatedKeys(PreparedStatement ps, KeyHolder keyHolder) throws SQLException {
List<Map<String, Object>> keys = keyHolder.getKeyList();
ResultSet rs = ps.getGeneratedKeys();
if (rs == null)
return;
try {
keys.addAll(new RowMapperResultSetExtractor<>(new ColumnMapRowMapper(), 1).extractData(rs));
} finally {
rs.close();
}
}
use of org.springframework.jdbc.core.RowMapperResultSetExtractor 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;
}
use of org.springframework.jdbc.core.RowMapperResultSetExtractor 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;
}
}
use of org.springframework.jdbc.core.RowMapperResultSetExtractor in project camel by apache.
the class DrillEndpoint method queryForList.
public List<?> queryForList(ResultSet rs) throws SQLException {
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;
}
use of org.springframework.jdbc.core.RowMapperResultSetExtractor in project Gargoyle by callakrsos.
the class DbUtil method select.
public static <T> List<T> select(final Connection con, final String sql, int fetchCount, RowMapper<T> mapper) throws Exception {
List<T> resultList = Collections.emptyList();
try {
noticeQuery(sql);
PreparedStatement prepareStatement = null;
ResultSet executeQuery = null;
/* 쿼리 타임아웃 시간 설정 SEC */
// int queryTimeout = getQueryTimeout();
prepareStatement = con.prepareStatement(sql);
LOGGER.debug(sql);
if (fetchCount > 0) {
prepareStatement.setFetchSize(fetchCount);
}
executeQuery = prepareStatement.executeQuery();
RowMapperResultSetExtractor<T> rowMapperResultSetExtractor = new RowMapperResultSetExtractor<T>(mapper);
resultList = rowMapperResultSetExtractor.extractData(executeQuery);
} catch (Throwable e) {
throw e;
} finally {
close(con);
}
return resultList;
}
Aggregations