Search in sources :

Example 11 with NamedParameterJdbcTemplate

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;
}
Also used : DataSourceConfVO(com.netsteadfast.greenstep.vo.DataSourceConfVO) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) DataSourceDriverVO(com.netsteadfast.greenstep.vo.DataSourceDriverVO)

Example 12 with NamedParameterJdbcTemplate

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;
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) SQLException(java.sql.SQLException) GargoyleException(com.kyj.fx.voeditor.visual.exceptions.GargoyleException) NotSupportException(com.kyj.fx.voeditor.visual.exceptions.NotSupportException)

Aggregations

NamedParameterJdbcTemplate (org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)12 HashMap (java.util.HashMap)5 GargoyleException (com.kyj.fx.voeditor.visual.exceptions.GargoyleException)3 NotSupportException (com.kyj.fx.voeditor.visual.exceptions.NotSupportException)3 SQLException (java.sql.SQLException)3 ServiceException (com.netsteadfast.greenstep.base.exception.ServiceException)2 Date (java.util.Date)2 DataSourceConfVO (com.netsteadfast.greenstep.vo.DataSourceConfVO)1 DataSourceDriverVO (com.netsteadfast.greenstep.vo.DataSourceDriverVO)1 SysVO (com.netsteadfast.greenstep.vo.SysVO)1 DataSource (javax.sql.DataSource)1 DataSource (org.apache.tomcat.jdbc.pool.DataSource)1 JobExecutionException (org.quartz.JobExecutionException)1 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)1 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)1 DataSourceTransactionManager (org.springframework.jdbc.datasource.DataSourceTransactionManager)1 TransactionTemplate (org.springframework.transaction.support.TransactionTemplate)1