use of org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate in project bamboobsc by billchen198318.
the class ManualJdbcTemplateFactory method getManualJdbcTemplate.
public static NamedParameterJdbcTemplate getManualJdbcTemplate(String confOid) throws ServiceException, Exception {
if (jdbcTemplateTreadLocal.get() != null && jdbcTemplateTreadLocal.get().getDataSourceConf().getOid().equals(confOid)) {
return jdbcTemplateTreadLocal.get().getJdbcTemplate();
}
DataSourceConfVO conf = new DataSourceConfVO();
conf.setOid(confOid);
DefaultResult<DataSourceConfVO> confResult = dataSourceConfService.findObjectByOid(conf);
if (confResult.getValue() == null) {
throw new ServiceException(confResult.getSystemMessage().getValue());
}
conf = confResult.getValue();
DataSourceDriverVO driver = new DataSourceDriverVO();
driver.setId(conf.getDriverId());
DefaultResult<DataSourceDriverVO> driverResult = dataSourceDriverService.findByUK(driver);
if (driverResult.getValue() == null) {
throw new ServiceException(driverResult.getSystemMessage().getValue());
}
driver = driverResult.getValue();
NamedParameterJdbcTemplate jdbcTemplate = DataUtils.getManualJdbcTemplate(Class.forName(driver.getClassName()), conf.getJdbcUrl(), conf.getDbAccount(), conf.getDbPassword());
DataProperty dataProperty = new DataProperty();
dataProperty.setDataSourceConf(conf);
dataProperty.setJdbcTemplate(jdbcTemplate);
jdbcTemplateTreadLocal.set(dataProperty);
return jdbcTemplate;
}
use of org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate in project Gargoyle by callakrsos.
the class DbUtil method select.
public static <T> List<T> select(DataSource dataSource, final String sql, Map<String, Object> paramMap, RowMapper<T> rowMapper) throws Exception {
List<T> query = null;
try {
noticeQuery(sql);
NamedParameterJdbcTemplate jdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
// String _sql = ValueUtil.getVelocityToText(sql, paramMap);
// LOGGER.debug(_sql);
query = jdbcTemplate.query(sql, new MapSqlParameterSource(paramMap), rowMapper);
} catch (Exception e) {
throw e;
}
return query;
}
Aggregations