Example usage for org.springframework.jdbc.core.namedparam NamedParameterJdbcTemplate NamedParameterJdbcTemplate

List of usage examples for org.springframework.jdbc.core.namedparam NamedParameterJdbcTemplate NamedParameterJdbcTemplate

Introduction

In this page you can find the example usage for org.springframework.jdbc.core.namedparam NamedParameterJdbcTemplate NamedParameterJdbcTemplate.

Prototype

public NamedParameterJdbcTemplate(JdbcOperations classicJdbcTemplate) 

Source Link

Document

Create a new NamedParameterJdbcTemplate for the given classic Spring org.springframework.jdbc.core.JdbcTemplate .

Usage

From source file:com.flipkart.aesop.hbasedatalayer.AbstractHBaseDataLayerFactory.java

private void createJdbcTemplateMap() {
    jdbcTemplateMap = new HashMap<String, NamedParameterJdbcTemplate>();
    DataSource dataSource = getDataSource();
    NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
    jdbcTemplateMap.put(getDataSourceName(), namedParameterJdbcTemplate);

}

From source file:com.ushahidi.swiftriver.core.api.dao.impl.AbstractJpaContextDropDao.java

@Autowired
public void setDataSource(DataSource dataSource) {
    this.namedJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
}

From source file:com.github.ferstl.spring.jdbc.oracle.DatabaseConfiguration.java

@Bean
public NamedParameterJdbcTemplate npJdbcTemplate() throws Exception {
    return new NamedParameterJdbcTemplate(jdbcTemplate());
}

From source file:com.joliciel.lefff.LefffDaoImpl.java

public Attribute loadAttribute(int attributeId) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_ATTRIBUTE + " FROM lef_attribute WHERE attribute_id=:attribute_id";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("attribute_id", attributeId);

    LOG.info(sql);/*from ww w.ja  va 2  s .  c o m*/
    LefffDaoImpl.LogParameters(paramSource);
    Attribute attribute = null;
    try {
        attribute = (Attribute) jt.queryForObject(sql, paramSource,
                new AttributeMapper(this.getLefffServiceInternal()));
    } catch (EmptyResultDataAccessException ex) {
        ex.hashCode();
    }
    return attribute;
}

From source file:com.gst.portfolio.search.service.SearchReadPlatformServiceImpl.java

@Autowired
public SearchReadPlatformServiceImpl(final PlatformSecurityContext context, final RoutingDataSource dataSource,
        final LoanProductReadPlatformService loanProductReadPlatformService,
        final OfficeReadPlatformService officeReadPlatformService) {
    this.context = context;
    this.namedParameterjdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
    this.loanProductReadPlatformService = loanProductReadPlatformService;
    this.officeReadPlatformService = officeReadPlatformService;
}

From source file:org.surfnet.cruncher.repository.StatisticsRepositoryImpl.java

/**
 * {@inheritDoc}/* w w  w. j  a  v a 2 s. co m*/
 */
@Override
public List<LoginData> getLogins(final LocalDate start, final LocalDate end, final String idpEntityId,
        final String spEntityId) {
    final List<LoginData> result = new ArrayList<LoginData>();

    NamedParameterJdbcTemplate namedJdbcTemplate = new NamedParameterJdbcTemplate(cruncherJdbcTemplate);

    String query = "select * from aggregated_log_logins " + "where " + "entryday >= :startDate AND "
            + "entryday <= :endDate AND " + "(:spEntityId IS NULL OR spentityid = :spEntityId) AND "
            + "(:idpEntityId IS NULL OR idpentityid = :idpEntityId) "
            + "order by idpentityid, spentityid, entryday ";

    Map<String, Object> parameterMap = getParameterMap(start, end, idpEntityId, spEntityId);

    namedJdbcTemplate.query(query, parameterMap, new RowMapper<Object>() {
        private Map<LocalDate, Integer> queryResult = new HashMap<LocalDate, Integer>();
        private LoginData currentAggregate = null;

        @Override
        public Object mapRow(ResultSet rs, int row) throws SQLException {
            LoginData currentRow = getLoginDataFromRow(rs);

            /*
             * aggregate if sp/idp entityid differs from previous record
             * do not aggregate if on first record
             * if on last record, aggregate last entries
             */
            if (!currentRow.equals(currentAggregate) && !rs.isFirst()) {
                //record is different, aggregate previous one and start fresh
                result.add(aggregateCurrentEntry(currentAggregate, start, end));
                queryResult = new HashMap<LocalDate, Integer>();

            }
            queryResult.put(new LocalDate(rs.getDate("entryday")), rs.getInt("entrycount"));
            currentAggregate = currentRow;

            if (rs.isLast()) {
                // aggregate last set
                result.add(aggregateCurrentEntry(currentAggregate, start, end));
            }

            /*
             * This is kinda weird, but single row results are stored in 
             * queryResult (hashmap) or aggregated in result (List<loginData)
             */
            return null;
        }

        private LoginData aggregateCurrentEntry(final LoginData loginData, final LocalDate start,
                final LocalDate end) {
            LocalDate current = start;

            int total = 0;
            while (current.isBefore(end.plusDays(1))) {
                Integer count = queryResult.get(current);
                if (count == null) {
                    loginData.getData().add(0);
                } else {
                    loginData.getData().add(count);
                    total += count;
                }
                current = current.plusDays(1);
            }
            loginData.setTotal(total);
            loginData.setPointStart(start.toDate().getTime());
            loginData.setPointEnd(end.toDate().getTime());
            loginData.setPointInterval(POINT_INTERVAL);
            return loginData;
        }

        private LoginData getLoginDataFromRow(ResultSet rs) throws SQLException {
            LoginData result = new LoginData();
            result.setIdpEntityId(rs.getString("idpentityid"));
            result.setIdpname(rs.getString("idpentityname"));
            result.setSpEntityId(rs.getString("spentityid"));
            result.setSpName(rs.getString("spentityname"));
            return result;
        }
    });
    return result;
}

From source file:com.joliciel.jochre.doc.DocumentDaoJdbc.java

@Override
public List<JochrePage> findJochrePages(JochreDocument jochreDocument) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_PAGE + " FROM ocr_page WHERE page_doc_id=:page_doc_id"
            + " ORDER BY page_index";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("page_doc_id", jochreDocument.getId());

    LOG.info(sql);/*from  w ww .j a  v  a 2s .  com*/
    logParameters(paramSource);
    @SuppressWarnings("unchecked")
    List<JochrePage> jochrePages = jt.query(sql, paramSource,
            new JochrePageMapper(this.getDocumentServiceInternal()));

    return jochrePages;
}

From source file:com.joliciel.jochre.security.SecurityDaoJdbc.java

@Override
public List<User> findUsers() {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_USER + " FROM ocr_user" + " ORDER BY user_last_name, user_first_name";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();

    LOG.info(sql);/*from w  w w .  j  a va 2  s. c o  m*/
    logParameters(paramSource);
    @SuppressWarnings("unchecked")
    List<User> users = jt.query(sql, paramSource, new UserMapper(this.getSecurityServiceInternal()));
    return users;
}

From source file:org.smart.migrate.dao.impl.DefaultImportDao.java

@Override
public void deleteTargetDataByPrimaryKeys(TableSetting tableSetting, List<String> primaryKeys) {
    String sql = "DELETE FROM " + tableSetting.getTargetTable() + " WHERE " + tableSetting.getTargetPK()
            + " in (:ids)";
    NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(targetJdbcTemplate);
    MapSqlParameterSource parameters = new MapSqlParameterSource();
    parameters.addValue("ids", primaryKeys);
    namedParameterJdbcTemplate.update(sql, parameters);
}