List of usage examples for org.springframework.jdbc.core.namedparam NamedParameterJdbcTemplate NamedParameterJdbcTemplate
public NamedParameterJdbcTemplate(JdbcOperations classicJdbcTemplate)
From source file:com.joliciel.jochre.security.SecurityDaoJdbc.java
@Override public User loadUser(int userId) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); String sql = "SELECT " + SELECT_USER + " FROM ocr_user WHERE user_id=:user_id"; MapSqlParameterSource paramSource = new MapSqlParameterSource(); paramSource.addValue("user_id", userId); LOG.info(sql);// w w w . j a va 2 s. c o m logParameters(paramSource); User user = null; try { user = (User) jt.queryForObject(sql, paramSource, new UserMapper(this.getSecurityServiceInternal())); } catch (EmptyResultDataAccessException ex) { ex.hashCode(); } return user; }
From source file:com.devicehive.dao.rdbms.DeviceDaoRdbmsImpl.java
@Autowired public void setDataSource(DataSource dataSource) { jdbcTemplate = new NamedParameterJdbcTemplate(dataSource); }
From source file:cherry.foundation.etl.LoaderImpl.java
/** * ?// w w w.ja v a 2s.com * * @param dataSource * @param sql SQL * @param provider ?? * @param limit ??? * @return ???? * @throws LimiterException ???? * @throws IOException ?? */ @Override public LoadResult load(DataSource dataSource, String sql, Provider provider, Limiter limiter) throws LimiterException, IOException { NamedParameterJdbcTemplate template = new NamedParameterJdbcTemplate(dataSource); limiter.start(); try { provider.begin(); long totalCount = 0; long successCount = 0; long failedCount = 0; Map<String, ?> data; while ((data = provider.provide()) != null) { totalCount += 1; try { template.update(sql, data); successCount += 1; } catch (DataAccessException ex) { if (allowedFailCount <= 0) { throw ex; } failedCount += 1; logger.warn("SQL failed: count={}, message={}", failedCount, ex.getMessage()); if (allowedFailCount < failedCount) { throw ex; } } if (batchCount > 0 && batchCount <= totalCount) { break; } limiter.tick(); } provider.end(); LoadResult result = new LoadResult(); result.setTotalCount(totalCount); result.setSuccessCount(successCount); result.setFailedCount(failedCount); return result; } finally { limiter.stop(); } }
From source file:net.firejack.platform.core.utils.db.DBUtils.java
/** * @param dataSource// w w w. ja v a 2s . com * @param dbName * @return */ public static boolean dbExists(DataSource dataSource, String dbName) { NamedParameterJdbcTemplate template = new NamedParameterJdbcTemplate(dataSource); SqlParameterSource namedParameters = new MapSqlParameterSource("dbName", dbName); String sql = "SELECT count(*) FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = :dbName"; int count = template.queryForInt(sql, namedParameters); return count > 0; }
From source file:com.branded.holdings.qpc.repository.jdbc.JdbcPetRepositoryImpl.java
@Autowired public JdbcPetRepositoryImpl(DataSource dataSource, OwnerRepository ownerRepository, VisitRepository visitRepository) { this.namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource); this.insertPet = new SimpleJdbcInsert(dataSource).withTableName("pets").usingGeneratedKeyColumns("id"); this.ownerRepository = ownerRepository; this.visitRepository = visitRepository; }
From source file:com.rambird.miles.repository.jdbc.JdbcCatgRepositoryImpl.java
@Autowired public JdbcCatgRepositoryImpl(DataSource dataSource, NamedParameterJdbcTemplate namedParameterJdbcTemplate) { this.insertMileCatg = new SimpleJdbcInsert(dataSource).withTableName("category") .usingGeneratedKeyColumns("catgid"); this.namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource); }
From source file:com.joliciel.jochre.boundaries.BoundaryDaoJdbc.java
@Override public Split loadSplit(int splitId) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); String sql = "SELECT " + SELECT_SPLIT + " FROM ocr_split WHERE split_id=:split_id"; MapSqlParameterSource paramSource = new MapSqlParameterSource(); paramSource.addValue("split_id", splitId); LOG.debug(sql);/*from www . java2 s . co m*/ logParameters(paramSource); Split split = null; try { split = (Split) jt.queryForObject(sql, paramSource, new SplitMapper(this.getBoundaryServiceInternal())); } catch (EmptyResultDataAccessException ex) { ex.hashCode(); } return split; }
From source file:xyz.vopen.passport.commons.jdbc.JdbcDaoSupport.java
/** * Create a NamedParameterJdbcTemplate for the given DataSource. Only * invoked if populating the DAO with a DataSource reference! * <p/>//from w ww . j a v a2 s.co m * Can be overridden in subclasses to provide a JdbcTemplate instance with * different configuration, or a custom NamedParameterJdbcTemplate subclass. * * @param dataSource the JDBC DataSource to create a NamedParameterJdbcTemplate for * @return the new NamedParameterJdbcTemplate instance * @see #setDataSource */ protected NamedParameterJdbcTemplate createNamedParameterJdbcTemplate(DataSource dataSource) { return new NamedParameterJdbcTemplate(dataSource); }
From source file:org.tradex.camel.enrich.TradeCommonCodeEnricher.java
/** * {@inheritDoc}//from w w w.j a v a2s . co m * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet() */ @Override public void afterPropertiesSet() throws Exception { jdbcTemplate = new NamedParameterJdbcTemplate(dataSource); }