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.joliciel.jochre.boundaries.BoundaryDaoJdbc.java

@Override
public void saveSplit(Split split) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    SplitInternal iSplit = (SplitInternal) split;

    paramSource.addValue("split_shape_id", split.getShapeId());
    paramSource.addValue("split_position", split.getPosition());
    String sql = null;/* ww  w  . ja  v  a 2s.com*/

    if (split.isNew()) {
        sql = "SELECT nextval('ocr_split_id_seq')";
        LOG.debug(sql);
        int splitId = jt.queryForInt(sql, paramSource);
        paramSource.addValue("split_id", splitId);

        sql = "INSERT INTO ocr_split (split_id, split_shape_id, split_position) "
                + "VALUES (:split_id, :split_shape_id, :split_position)";

        LOG.debug(sql);
        logParameters(paramSource);
        jt.update(sql, paramSource);

        iSplit.setId(splitId);
    } else {
        paramSource.addValue("split_id", split.getId());

        sql = "UPDATE ocr_split" + " SET split_shape_id = :split_shape_id"
                + ", split_position = :split_position" + " WHERE split_id = :split_id";

        LOG.debug(sql);
        logParameters(paramSource);
        jt.update(sql, paramSource);
    }
}

From source file:org.tradex.jdbc.JDBCHelper.java

/**
 * Issues a query for an int/* ww  w .ja  v a2 s  .c o m*/
 * @param sql The SQL
 * @param binds The bind values
 * @return an int value
 */
public int templateQueryForInt(CharSequence sql, Object... binds) {
    NamedParameterJdbcTemplate template = new NamedParameterJdbcTemplate(ds);
    return template.queryForInt(sql.toString(), getBinds(sql.toString().trim().toUpperCase(), binds));
}

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

@Override
public void saveJochrePage(JochrePage jochrePage) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    JochrePageInternal iJochrePage = (JochrePageInternal) jochrePage;

    paramSource.addValue("page_doc_id", jochrePage.getDocumentId());
    paramSource.addValue("page_index", jochrePage.getIndex());
    String sql = null;//w  ww  .java2s.c  om

    if (jochrePage.isNew()) {
        sql = "SELECT nextval('ocr_page_id_seq')";
        LOG.info(sql);
        int jochrePageId = jt.queryForInt(sql, paramSource);
        paramSource.addValue("page_id", jochrePageId);

        sql = "INSERT INTO ocr_page (page_id, page_doc_id, page_index) "
                + "VALUES (:page_id, :page_doc_id, :page_index)";

        LOG.info(sql);
        logParameters(paramSource);
        jt.update(sql, paramSource);

        iJochrePage.setId(jochrePageId);
    } else {
        paramSource.addValue("page_id", jochrePage.getId());

        sql = "UPDATE ocr_page" + " SET page_doc_id = :page_doc_id" + ", page_index = :page_index"
                + " WHERE page_id = :page_id";

        LOG.info(sql);
        logParameters(paramSource);
        jt.update(sql, paramSource);
    }
}

From source file:org.springframework.security.oauth2.provider.client.JdbcClientDetailsService.java

public JdbcClientDetailsService(DataSource dataSource) {
    Assert.notNull(dataSource, "DataSource required");
    this.jdbcTemplate = new JdbcTemplate(dataSource);
    this.listFactory = new DefaultJdbcListFactory(new NamedParameterJdbcTemplate(jdbcTemplate));
}

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

@Override
public void saveTargetData(TableSetting tableSetting, List<Map<String, Object>> targetDataList) {

    String sql = "INSERT INTO " + tableSetting.getTargetTable() + " ("
            + SettingUtils.getTargetFields(tableSetting) + ")";
    sql += " VALUES (" + SettingUtils.getTargetPreparedFields(tableSetting) + ")";

    NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(targetJdbcTemplate);
    List<MapSqlParameterSource> parameterSources = new ArrayList<MapSqlParameterSource>();
    for (Map<String, Object> targetData : targetDataList) {
        MapSqlParameterSource psource = new MapSqlParameterSource();
        psource.addValues(targetData);// w w w.j  a v a 2  s.c  o m
        parameterSources.add(psource);
    }

    namedParameterJdbcTemplate.batchUpdate(sql, parameterSources.toArray(new MapSqlParameterSource[0]));
}

From source file:com.lixiaocong.social.MyJdbcUsersConnection.java

public Set<String> findUserIdsConnectedTo(String providerId, Set<String> providerUserIds) {
    MapSqlParameterSource parameters = new MapSqlParameterSource();
    parameters.addValue("providerId", providerId);
    parameters.addValue("providerUserIds", providerUserIds);
    final Set<String> localUserIds = new HashSet<String>();
    return new NamedParameterJdbcTemplate(jdbcTemplate).query(
            "select userId from " + tablePrefix
                    + "UserConnection where providerId = :providerId and providerUserId in (:providerUserIds)",
            parameters, new ResultSetExtractor<Set<String>>() {
                public Set<String> extractData(ResultSet rs) throws SQLException, DataAccessException {
                    while (rs.next()) {
                        localUserIds.add(rs.getString("userId"));
                    }/*w  w  w.  j  a v  a  2 s  .  co m*/
                    return localUserIds;
                }
            });
}

From source file:cherry.foundation.etl.ExtractorImplTest.java

private NamedParameterJdbcTemplate getTemplate() {
    return new NamedParameterJdbcTemplate(dataSource);
}

From source file:com.joliciel.frenchTreebank.TreebankDaoImpl.java

public Category loadCategory(int categoryId) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_CATEGORY + " FROM ftb_category WHERE cat_id=:cat_id";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("cat_id", categoryId);

    LOG.info(sql);// w  ww .  j  a  v a  2s .c  o  m
    TreebankDaoImpl.LogParameters(paramSource);
    Category category = null;
    try {
        category = (Category) jt.queryForObject(sql, paramSource, new CategoryMapper());
    } catch (EmptyResultDataAccessException ex) {
        ex.hashCode();
    }
    return category;
}

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

@SuppressWarnings("unchecked")
@Override/*  www .  j a  v  a2  s  .  co m*/
public List<Attribute> findAttributes(LefffEntryInternal entry) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_ATTRIBUTE + " FROM lef_attribute, lef_entry_attribute"
            + " WHERE attribute_id = entatt_attribute_id AND entatt_entry_id = :entry_id"
            + " ORDER BY attribute_code, attribute_value";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("entry_id", entry.getId());

    LOG.info(sql);
    LefffDaoImpl.LogParameters(paramSource);
    List<Attribute> attributes = jt.query(sql, paramSource,
            new AttributeMapper(this.getLefffServiceInternal()));

    return attributes;
}

From source file:egovframework.rte.fdl.security.securedobject.impl.SecuredObjectDAO.java

public void setDataSource(DataSource dataSource) {
    this.namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
}