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

@Override
public void loadOriginalImage(JochreImageInternal jochreImage) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT image_image FROM ocr_image WHERE image_id=:image_id";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("image_id", jochreImage.getId());

    LOG.debug(sql);/*from  ww  w . j  a  v a2s  . c o m*/
    logParameters(paramSource);

    byte[] pixels = (byte[]) jt.query(sql, paramSource, new ResultSetExtractor() {
        @Override
        public Object extractData(ResultSet rs) throws SQLException, DataAccessException {
            if (rs.next()) {
                byte[] pixels = rs.getBytes("image_image");

                return pixels;
            } else {
                return null;
            }
        }

    });

    ByteArrayInputStream is = new ByteArrayInputStream(pixels);
    BufferedImage image;
    try {
        image = ImageIO.read(is);
        is.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    jochreImage.setOriginalImageDB(image);
}

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

@Override
public List<Term> getMarkedTerms() {
    MONITOR.startTask("getMarkedTerms");
    try {//from w  ww. j a v a  2s  .  co m
        NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
        String sql = "SELECT " + SELECT_TERM + " FROM term" + " INNER JOIN text ON term_text_id=text_id"
                + " WHERE term_marked = :term_marked" + " AND term_project_id = :term_project_id"
                + " ORDER BY text_text";
        MapSqlParameterSource paramSource = new MapSqlParameterSource();
        paramSource.addValue("term_marked", true);
        paramSource.addValue("term_project_id", this.getCurrentProjectId());

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

        return terms;

    } finally {
        MONITOR.endTask("getMarkedTerms");
    }
}

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

public void deleteCategory(int categoryId) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    String sql = "DELETE FROM lef_category WHERE category_id = :category_id";
    paramSource.addValue("category_id", categoryId);
    LOG.info(sql);/*from   www.ja  v  a 2  s.co m*/
    LefffDaoImpl.LogParameters(paramSource);
    jt.update(sql, paramSource);
}

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

@Override
public void saveOriginalImage(JochreImage jochreImage) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("image_id", jochreImage.getId());

    ByteArrayOutputStream os = new ByteArrayOutputStream();
    try {/*  www  .  j ava  2 s  . com*/
        ImageIO.write(jochreImage.getOriginalImage(), "png", os);
        os.flush();
        paramSource.addValue("image_image", os.toByteArray());
        os.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    String sql = "UPDATE ocr_image SET image_image = :image_image" + " WHERE image_id = :image_id";

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

From source file:com.atypon.wayf.guice.WayfGuiceModule.java

@Provides
@Singleton/*from www  .j  a v  a 2  s .  c om*/
public NamedParameterJdbcTemplate getJdbcTemplate(@Named("jdbc.driver") String driver,
        @Named("jdbc.username") String username, @Named("jdbc.password") String password,
        @Named("jdbc.url") String url, @Named("jdbc.maxActive") Integer maxActive,
        @Named("jdbc.maxIdle") Integer maxIdle, @Named("jdbc.initialSize") Integer initialSize,
        @Named("jdbc.validationQuery") String validationQuery) {
    BasicDataSource dataSource = new BasicDataSource();

    dataSource.setDriverClassName(driver);
    dataSource.setUsername(username);
    dataSource.setPassword(password);
    dataSource.setUrl(url);
    dataSource.setMaxActive(maxActive);
    dataSource.setMaxIdle(maxIdle);
    dataSource.setInitialSize(initialSize);
    dataSource.setValidationQuery(validationQuery);

    return new NamedParameterJdbcTemplate(dataSource);
}

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

@Override
public Author loadAuthor(int authorId) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_AUTHOR + " FROM ocr_author WHERE author_id=:author_id";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("author_id", authorId);

    LOG.info(sql);/*from  ww  w.ja va2s.c o m*/
    logParameters(paramSource);
    Author author = null;
    try {
        author = (Author) jt.queryForObject(sql, paramSource,
                new AuthorMapper(this.getDocumentServiceInternal()));
    } catch (EmptyResultDataAccessException ex) {
        ex.hashCode();
    }
    return author;
}

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

public List<JochreImage> findImages(JochrePage jochrePage) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_IMAGE + " FROM ocr_image WHERE image_page_id=:image_page_id"
            + " ORDER BY image_index";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("image_page_id", jochrePage.getId());

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

    return images;
}

From source file:com.p5solutions.core.jpa.orm.EntityParserImpl.java

/**
 * @see com.p5solutions.core.jpa.orm.EntityParser#getJdbcTemplate()
 *//*from   ww w. jav  a  2  s  .c  om*/
@Override
public NamedParameterJdbcTemplate getJdbcTemplate() {
    if (jdbcTemplate == null) {
        jdbcTemplate = new NamedParameterJdbcTemplate(getDataSource());
    }
    return jdbcTemplate;
}

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

@Override
public List<Author> findAuthors() {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_AUTHOR + " FROM ocr_author"
            + " ORDER BY author_last_name, author_first_name";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();

    LOG.info(sql);/*from   w ww . j  av  a  2  s. c  o m*/
    logParameters(paramSource);
    @SuppressWarnings("unchecked")
    List<Author> authors = jt.query(sql, paramSource, new AuthorMapper(this.getDocumentServiceInternal()));

    return authors;
}

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

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

    LOG.info(sql);// w  ww. j a va 2  s . c  o  m
    LefffDaoImpl.LogParameters(paramSource);
    Predicate predicate = null;
    try {
        predicate = (Predicate) jt.queryForObject(sql, paramSource,
                new PredicateMapper(this.getLefffServiceInternal()));
    } catch (EmptyResultDataAccessException ex) {
        ex.hashCode();
    }
    return predicate;
}