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

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

Introduction

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

Prototype

@Override
    public <T> List<T> queryForList(String sql, Map<String, ?> paramMap, Class<T> elementType)
            throws DataAccessException 

Source Link

Usage

From source file:ch.digitalfondue.npjt.QueryType.java

private static List<Object> handleList(String template, NamedParameterJdbcTemplate jdbc,
        SqlParameterSource parameters, Collection<ColumnMapperFactory> columnMapperFactories, Class<Object> c,
        HasRowmapper r) {//from   w  w  w. ja  va  2  s  .  c  o m
    if (r.present) {
        return jdbc.query(template, parameters, r.rowMapper);
    } else {
        RowMapper<Object> rowMapper = matchToOutput(columnMapperFactories, c);
        if (rowMapper != null) {
            return jdbc.query(template, parameters, rowMapper);
        } else {
            return jdbc.queryForList(template, parameters, c);
        }
    }
}

From source file:dao.AdvSearchDAO.java

public static List<String> getTableNames(String scopes) {
    List<String> tables = null;
    if (StringUtils.isNotBlank(scopes)) {
        String[] scopeArray = scopes.split(",");
        List<String> scopeList = Arrays.asList(scopeArray);
        Map<String, List> param = Collections.singletonMap("scopes", scopeList);
        NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(
                getJdbcTemplate().getDataSource());
        tables = namedParameterJdbcTemplate.queryForList(GET_DATASET_TABLE_NAMES_BY_SCOPE, param, String.class);
    } else {//w w  w . jav a  2s  . co m
        tables = getJdbcTemplate().queryForList(GET_DATASET_TABLE_NAMES, String.class);
    }

    return tables;
}

From source file:dao.AdvSearchDAO.java

public static List<String> getFlowNames(String applications) {
    List<String> flowNames = null;
    if (StringUtils.isNotBlank(applications)) {
        String[] appArray = applications.split(",");
        List<String> appList = Arrays.asList(appArray);
        Map<String, List> param = Collections.singletonMap("apps", appList);
        NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(
                getJdbcTemplate().getDataSource());
        flowNames = namedParameterJdbcTemplate.queryForList(GET_FLOW_NAMES_BY_APP, param, String.class);
    } else {/*  w  w w .  j ava 2 s .  c o m*/
        flowNames = getJdbcTemplate().queryForList(GET_FLOW_NAMES, String.class);
    }

    return flowNames;
}

From source file:com.joliciel.jochre.graphics.GraphicsDaoJdbc.java

@Override
public List<Integer> findShapeIds(String letter) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT shape_id FROM ocr_shape" + " INNER JOIN ocr_group ON shape_group_id = group_id"
            + " INNER JOIN ocr_row ON group_row_id = row_id"
            + " INNER JOIN ocr_paragraph ON row_paragraph_id = paragraph_id"
            + " INNER JOIN ocr_image ON paragraph_image_id = image_id"
            + " WHERE image_imgstatus_id = :image_imgstatus_id" + " AND shape_letter = :shape_letter"
            + " ORDER BY shape_id";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("image_imgstatus_id", ImageStatus.TRAINING_VALIDATED.getId());
    paramSource.addValue("shape_letter", letter);

    LOG.debug(sql);//from  w w  w  .  jav a2s  .  com
    logParameters(paramSource);
    @SuppressWarnings("unchecked")
    List<Integer> shapeIds = jt.queryForList(sql, paramSource, Integer.class);
    return shapeIds;
}

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

@SuppressWarnings("unchecked")
public List<Integer> findWordIds(int minId, int maxId) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT word_id FROM ftb_word" + " WHERE word_id >= :min_id" + " AND word_id <= :max_id"
            + " ORDER BY word_id";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("min_id", minId);
    paramSource.addValue("max_id", maxId);

    LOG.info(sql);/*from  w  w  w.  j ava  2 s .  c o m*/
    TreebankDaoImpl.LogParameters(paramSource);
    List<Integer> sentenceIds = jt.queryForList(sql, paramSource, Integer.class);

    return sentenceIds;
}

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

@SuppressWarnings("unchecked")
public List<Integer> findSentenceIds(int minId, int maxId) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT sentence_id FROM ftb_sentence" + " WHERE sentence_id >= :min_id"
            + " AND sentence_id <= :max_id" + " ORDER BY sentence_id";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("min_id", minId);
    paramSource.addValue("max_id", maxId);

    LOG.info(sql);//from   w  ww .  j av  a  2s .  c  om
    TreebankDaoImpl.LogParameters(paramSource);
    List<Integer> sentenceIds = jt.queryForList(sql, paramSource, Integer.class);

    return sentenceIds;
}

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

public List<Integer> findSentenceIds(TreebankFile treebankFile) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT sentence_id" + " FROM ftb_sentence" + " WHERE sentence_file_id=:sentence_file_id"
            + " ORDER BY sentence_id";

    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("sentence_file_id", treebankFile.getId());

    LOG.info(sql);/* w w  w.  j av a 2  s.c  o m*/
    TreebankDaoImpl.LogParameters(paramSource);

    @SuppressWarnings("unchecked")
    List<Integer> sentenceIds = jt.queryForList(sql, paramSource, Integer.class);

    return sentenceIds;
}

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

@SuppressWarnings("unchecked")
@Override/*from  ww w. ja v a 2 s .  c om*/
public List<Integer> findSentenceIds(TreebankSubSet treebankSubSet, int numIds, int startId) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    String sql = "SELECT sentence_id FROM ftb_sentence" + " WHERE sentence_id >= :min_id";
    paramSource.addValue("min_id", startId);

    String andWord = " AND ";
    for (String whereClause : this.getWhereClausesForSubSet(treebankSubSet, paramSource)) {
        sql += andWord + whereClause;
    }

    sql += " ORDER BY sentence_id";
    if (numIds > 0) {
        sql += " LIMIT :maxResults";
        paramSource.addValue("maxResults", numIds);
    }
    LOG.info(sql);
    TreebankDaoImpl.LogParameters(paramSource);
    List<Integer> sentenceIds = jt.queryForList(sql, paramSource, Integer.class);

    return sentenceIds;
}

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

@SuppressWarnings("unchecked")
public List<Integer> findCompoundWordIds(int minId, int maxId) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT word_id FROM ftb_word, ftb_phrase_unit" + " WHERE word_id >= :min_id"
            + " AND word_id <= :max_id" + " AND word_id = punit_word_id" + " AND punit_compound = true"
            + " AND punit_id not in" + " (select psubunit_punit_id from ftb_phrase_subunit"
            + " group by psubunit_punit_id" + " having count(*)=1)" + " GROUP BY word_id" + " ORDER BY word_id";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("min_id", minId);
    paramSource.addValue("max_id", maxId);

    LOG.info(sql);/*from w w w. j a  v a2 s.c o m*/
    TreebankDaoImpl.LogParameters(paramSource);
    List<Integer> wordIds = jt.queryForList(sql, paramSource, Integer.class);

    return wordIds;
}

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

@SuppressWarnings("unchecked")
public List<Integer> findCompoundPhraseUnitIds(int minId, int maxId, boolean includeSingleSubunitCompounds) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT punit_id FROM ftb_phrase_unit" + " WHERE punit_id >= :min_id"
            + " AND punit_id <= :max_id" + " AND punit_compound = true";
    if (!includeSingleSubunitCompounds) {
        sql += " AND punit_id not in" + " (select psubunit_punit_id from ftb_phrase_subunit"
                + " group by psubunit_punit_id" + " having count(*)=1)";
    }/* w ww .  j  a v a 2  s .c om*/
    sql += " ORDER BY punit_id";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("min_id", minId);
    paramSource.addValue("max_id", maxId);

    LOG.info(sql);
    TreebankDaoImpl.LogParameters(paramSource);
    List<Integer> phraseUnitIds = jt.queryForList(sql, paramSource, Integer.class);

    return phraseUnitIds;
}