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.graphics.GraphicsDaoJdbc.java

public List<JochreImage> findImages(ImageStatus[] imageStatuses) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_IMAGE + " FROM ocr_image WHERE image_imgstatus_id in (:image_imgstatus_id)"
            + " ORDER BY image_id";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    List<Integer> imageStatusList = new ArrayList<Integer>();
    for (ImageStatus imageStatus : imageStatuses)
        imageStatusList.add(imageStatus.getId());
    paramSource.addValue("image_imgstatus_id", imageStatusList);

    LOG.debug(sql);/*  www .  ja v a  2s.  c o m*/
    logParameters(paramSource);
    @SuppressWarnings("unchecked")
    List<JochreImage> images = jt.query(sql, paramSource,
            new JochreImageMapper(this.getGraphicsServiceInternal()));

    return images;
}

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

@Override
public List<Author> findAuthors(JochreDocument jochreDocument) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_AUTHOR + " FROM ocr_author"
            + " INNER JOIN ocr_doc_author_map ON docauthor_author_id = author_id"
            + " WHERE docauthor_doc_id=:docauthor_doc_id" + " ORDER BY author_last_name, author_first_name";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("docauthor_doc_id", jochreDocument.getId());

    LOG.info(sql);/*  w  w w. j  a v a2  s .  co m*/
    logParameters(paramSource);
    @SuppressWarnings("unchecked")
    List<Author> authors = jt.query(sql, paramSource, new AuthorMapper(this.getDocumentServiceInternal()));

    return authors;
}

From source file:com.gst.portfolio.loanaccount.service.LoanReadPlatformServiceImpl.java

@Autowired
public LoanReadPlatformServiceImpl(final PlatformSecurityContext context,
        final ApplicationCurrencyRepositoryWrapper applicationCurrencyRepository,
        final LoanProductReadPlatformService loanProductReadPlatformService,
        final ClientReadPlatformService clientReadPlatformService,
        final GroupReadPlatformService groupReadPlatformService,
        final LoanDropdownReadPlatformService loanDropdownReadPlatformService,
        final FundReadPlatformService fundReadPlatformService,
        final ChargeReadPlatformService chargeReadPlatformService,
        final CodeValueReadPlatformService codeValueReadPlatformService, final RoutingDataSource dataSource,
        final CalendarReadPlatformService calendarReadPlatformService,
        final StaffReadPlatformService staffReadPlatformService,
        final PaymentTypeReadPlatformService paymentTypeReadPlatformService,
        final LoanRepaymentScheduleTransactionProcessorFactory loanRepaymentScheduleTransactionProcessorFactory,
        final FloatingRatesReadPlatformService floatingRatesReadPlatformService,
        final LoanUtilService loanUtilService, final ConfigurationDomainService configurationDomainService,
        final AccountDetailsReadPlatformService accountDetailsReadPlatformService,
        final LoanRepositoryWrapper loanRepositoryWrapper) {
    this.context = context;
    this.loanRepositoryWrapper = loanRepositoryWrapper;
    this.applicationCurrencyRepository = applicationCurrencyRepository;
    this.loanProductReadPlatformService = loanProductReadPlatformService;
    this.clientReadPlatformService = clientReadPlatformService;
    this.groupReadPlatformService = groupReadPlatformService;
    this.loanDropdownReadPlatformService = loanDropdownReadPlatformService;
    this.fundReadPlatformService = fundReadPlatformService;
    this.chargeReadPlatformService = chargeReadPlatformService;
    this.codeValueReadPlatformService = codeValueReadPlatformService;
    this.calendarReadPlatformService = calendarReadPlatformService;
    this.staffReadPlatformService = staffReadPlatformService;
    this.jdbcTemplate = new JdbcTemplate(dataSource);
    this.namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
    this.paymentTypeReadPlatformService = paymentTypeReadPlatformService;
    this.loanRepaymentScheduleTransactionProcessorFactory = loanRepaymentScheduleTransactionProcessorFactory;
    this.floatingRatesReadPlatformService = floatingRatesReadPlatformService;
    this.loanUtilService = loanUtilService;
    this.configurationDomainService = configurationDomainService;
    this.accountDetailsReadPlatformService = accountDetailsReadPlatformService;
}

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

public void savePhraseSubunit(PhraseSubunitInternal phraseSubunit) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("psubunit_punit_id",
            phraseSubunit.getPhraseUnit() == null ? null : phraseSubunit.getPhraseUnit().getId());
    paramSource.addValue("psubunit_word_id", phraseSubunit.getWordId() == 0 ? null : phraseSubunit.getWordId());
    paramSource.addValue("psubunit_position", phraseSubunit.getPosition());
    paramSource.addValue("psubunit_cat_id",
            phraseSubunit.getCategoryId() == 0 ? null : phraseSubunit.getCategoryId());
    paramSource.addValue("psubunit_subcat_id",
            phraseSubunit.getSubCategoryId() == 0 ? null : phraseSubunit.getSubCategoryId());
    paramSource.addValue("psubunit_morph_id",
            phraseSubunit.getMorphologyId() == 0 ? null : phraseSubunit.getMorphologyId());

    if (phraseSubunit.isNew()) {
        String sql = "SELECT nextval('ftb_phrase_subunit_psubunit_id_seq')";
        LOG.info(sql);/*from w  w  w .  j  a  v a 2 s. co  m*/
        int phraseSubunitId = jt.queryForInt(sql, paramSource);
        paramSource.addValue("psubunit_id", phraseSubunitId);

        sql = "INSERT INTO ftb_phrase_subunit (psubunit_id, psubunit_punit_id, psubunit_word_id, psubunit_position"
                + ", psubunit_cat_id, psubunit_subcat_id, psubunit_morph_id) "
                + "VALUES (:psubunit_id, :psubunit_punit_id, :psubunit_word_id, :psubunit_position"
                + ", :psubunit_cat_id, :psubunit_subcat_id, :psubunit_morph_id)";

        LOG.info(sql);
        TreebankDaoImpl.LogParameters(paramSource);
        jt.update(sql, paramSource);

        phraseSubunit.setId(phraseSubunitId);
    } else {
        paramSource.addValue("psubunit_id", phraseSubunit.getId());
        String sql = "UPDATE ftb_phrase_subunit" + " SET psubunit_punit_id=:psubunit_punit_id"
                + ", psubunit_word_id=:psubunit_word_id" + ", psubunit_position=:psubunit_position"
                + ", psubunit_cat_id=:psubunit_cat_id" + ", psubunit_subcat_id=:psubunit_subcat_id"
                + ", psubunit_morph_id=:psubunit_morph_id " + " WHERE psubunit_id = :psubunit_id";

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

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

public Predicate loadPredicate(String predicateText) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_PREDICATE + " FROM lef_predicate WHERE predicate_text=:predicate_text";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("predicate_text", predicateText);

    LOG.info(sql);//from   ww  w. j av a2s.  c  om
    LefffDaoImpl.LogParameters(paramSource);
    Predicate predicate = null;
    try {
        predicate = (Predicate) jt.queryForObject(sql, paramSource,
                new PredicateMapper(this.getLefffServiceInternal()));
    } catch (EmptyResultDataAccessException ex) {
        ex.hashCode();
    }
    return predicate;
}

From source file:com.joliciel.talismane.terminology.postgres.PostGresTerminologyBase.java

@Override
public Set<Term> getParents(final Term term) {
    MONITOR.startTask("getParents");
    try {/*from  www .j a  v  a 2  s .c om*/
        NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
        String sql = "SELECT " + SELECT_TERM + " FROM term" + " INNER JOIN text ON term_text_id=text_id"
                + " INNER JOIN term_expansions ON term_id = termexp_term_id"
                + " WHERE termexp_expansion_id = :term_id" + " ORDER BY text_text";
        MapSqlParameterSource paramSource = new MapSqlParameterSource();
        paramSource.addValue("term_id", ((PostGresTerm) term).getId());

        LOG.trace(sql);
        LogParameters(paramSource);
        @SuppressWarnings("unchecked")
        List<Term> terms = jt.query(sql, paramSource, new TermMapper());

        Set<Term> termSet = new TreeSet<Term>(new TermFrequencyComparator());
        termSet.addAll(terms);
        return termSet;
    } finally {
        MONITOR.endTask("getHeads");
    }
}

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

@Override
public VersStatistic getVersStats(LocalDate startDate, LocalDate endDate, String spEntityId) {
    final VersStatistic result = new VersStatistic();

    NamedParameterJdbcTemplate namedJdbcTemplate = new NamedParameterJdbcTemplate(cruncherJdbcTemplate);
    String query = "select idpentityid, sum(entrycount) as loginCount from aggregated_log_logins " + "where "
            + "entryday >= :startDate AND " + "entryday <= :endDate AND " + "spentityid = :spEntityId "
            + "group by idpentityid " + "order by idpentityid";

    Map<String, Object> parameterMap = new HashMap<String, Object>();
    parameterMap.put("startDate", new Date(startDate.toDateMidnight().getMillis()));
    parameterMap.put("endDate", new Date(endDate.toDateMidnight().getMillis()));
    parameterMap.put("spEntityId", spEntityId);

    namedJdbcTemplate.query(query, parameterMap, new RowMapper<VersStatistic>() {

        @Override/*from w w w  . j  ava  2s .  c o m*/
        public VersStatistic mapRow(ResultSet rs, int row) throws SQLException {
            String idpEntityId = rs.getString("idpEntityId");
            result.addInstitutionLoginCount(idpEntityId, rs.getLong("loginCount"));

            // no rowbased result
            return null;
        }
    });

    return result;
}

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

public void savePredicate(PredicateInternal predicate) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("predicate_text", predicate.getText());
    if (predicate.isNew()) {
        String sql = "SELECT nextval('seq_predicate_id')";
        LOG.info(sql);//www  . j  ava2  s  .c  om
        int predicateId = jt.queryForInt(sql, paramSource);
        paramSource.addValue("predicate_id", predicateId);

        sql = "INSERT INTO lef_predicate (predicate_id, predicate_text) VALUES (:predicate_id, :predicate_text)";

        LOG.info(sql);
        LefffDaoImpl.LogParameters(paramSource);
        jt.update(sql, paramSource);
        predicate.setId(predicateId);
    } else {
        String sql = "UPDATE lef_predicate" + " SET predicate_text = :predicate_text"
                + " WHERE predicate_id = :predicate_id";

        paramSource.addValue("predicate_id", predicate.getId());
        LOG.info(sql);
        LefffDaoImpl.LogParameters(paramSource);
        jt.update(sql, paramSource);
    }
}

From source file:com.joliciel.talismane.terminology.postgres.PostGresTerminologyBase.java

@Override
public Set<Term> getExpansions(Term term) {
    MONITOR.startTask("getExpansions");
    try {//from   ww w  .jav  a 2 s .c o  m
        NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
        String sql = "SELECT " + SELECT_TERM + " FROM term" + " INNER JOIN text ON term_text_id=text_id"
                + " INNER JOIN term_expansions ON term_id = termexp_expansion_id"
                + " WHERE termexp_term_id = :term_id" + " ORDER BY text_text";
        MapSqlParameterSource paramSource = new MapSqlParameterSource();
        paramSource.addValue("term_id", ((PostGresTerm) term).getId());

        LOG.trace(sql);
        LogParameters(paramSource);
        @SuppressWarnings("unchecked")
        List<Term> terms = jt.query(sql, paramSource, new TermMapper());

        Set<Term> termSet = new TreeSet<Term>(new TermFrequencyComparator());
        termSet.addAll(terms);
        return termSet;
    } finally {
        MONITOR.endTask("getExpansions");
    }
}

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

@Override
public void saveAuthor(Author author) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    AuthorInternal iAuthor = (AuthorInternal) author;

    paramSource.addValue("author_first_name", author.getFirstName());
    paramSource.addValue("author_last_name", author.getLastName());
    paramSource.addValue("author_first_name_local", author.getFirstNameLocal());
    paramSource.addValue("author_last_name_local", author.getLastNameLocal());
    String sql = null;/* ww w  .  j a v a  2  s.c  o m*/

    if (author.isNew()) {
        sql = "SELECT nextval('ocr_author_id_seq')";
        LOG.info(sql);
        int authorId = jt.queryForInt(sql, paramSource);
        paramSource.addValue("author_id", authorId);

        sql = "INSERT INTO ocr_author (author_id, author_first_name, author_last_name"
                + ", author_first_name_local, author_last_name_local) "
                + "VALUES (:author_id, :author_first_name, :author_last_name"
                + ", :author_first_name_local, :author_last_name_local)";

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

        iAuthor.setId(authorId);
    } else {
        paramSource.addValue("author_id", author.getId());

        sql = "UPDATE ocr_author" + " SET author_first_name = :author_first_name"
                + ", author_last_name = :author_last_name"
                + ", author_first_name_local = :author_first_name_local"
                + ", author_last_name_local = :author_last_name_local" + " WHERE author_id = :author_id";

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