Search in sources :

Example 11 with EntityNotFoundException

use of com.joliciel.jochre.EntityNotFoundException in project jochre by urieli.

the class GraphicsDao method loadShape.

public Shape loadShape(int shapeId) {
    Shape shape = this.jochreSession.getObjectCache().getEntity(Shape.class, shapeId);
    if (shape == null) {
        NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
        String sql = "SELECT " + SELECT_SHAPE + " FROM ocr_shape WHERE shape_id=:shape_id";
        MapSqlParameterSource paramSource = new MapSqlParameterSource();
        paramSource.addValue("shape_id", shapeId);
        LOG.debug(sql);
        logParameters(paramSource);
        try {
            shape = jt.queryForObject(sql, paramSource, new ShapeMapper());
        } catch (EmptyResultDataAccessException ex) {
            throw new EntityNotFoundException("No Shape found for shapeId " + shapeId);
        }
        this.jochreSession.getObjectCache().putEntity(Shape.class, shapeId, shape);
    }
    return shape;
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) EntityNotFoundException(com.joliciel.jochre.EntityNotFoundException)

Example 12 with EntityNotFoundException

use of com.joliciel.jochre.EntityNotFoundException in project jochre by urieli.

the class GraphicsDao method loadRowOfShapes.

RowOfShapes loadRowOfShapes(int rowId) {
    RowOfShapes row = this.jochreSession.getObjectCache().getEntity(RowOfShapes.class, rowId);
    if (row == null) {
        NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
        String sql = "SELECT " + SELECT_ROW + " FROM ocr_row WHERE row_id=:row_id";
        MapSqlParameterSource paramSource = new MapSqlParameterSource();
        paramSource.addValue("row_id", rowId);
        LOG.debug(sql);
        logParameters(paramSource);
        try {
            row = jt.queryForObject(sql, paramSource, new RowOfShapesMapper());
        } catch (EmptyResultDataAccessException ex) {
            throw new EntityNotFoundException("No RowOfShapes found for rowId " + rowId);
        }
        this.jochreSession.getObjectCache().putEntity(RowOfShapes.class, rowId, row);
    }
    return row;
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) EntityNotFoundException(com.joliciel.jochre.EntityNotFoundException)

Example 13 with EntityNotFoundException

use of com.joliciel.jochre.EntityNotFoundException in project jochre by urieli.

the class GraphicsDao method loadJochreImage.

public JochreImage loadJochreImage(int imageId) {
    JochreImage image = this.jochreSession.getObjectCache().getEntity(JochreImage.class, imageId);
    if (image == null) {
        NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
        String sql = "SELECT " + SELECT_IMAGE + " FROM ocr_image WHERE image_id=:image_id";
        MapSqlParameterSource paramSource = new MapSqlParameterSource();
        paramSource.addValue("image_id", imageId);
        LOG.debug(sql);
        logParameters(paramSource);
        try {
            image = jt.queryForObject(sql, paramSource, new JochreImageMapper());
        } catch (EmptyResultDataAccessException ex) {
            throw new EntityNotFoundException("No JochreImage found for imageId " + imageId);
        }
        this.jochreSession.getObjectCache().putEntity(JochreImage.class, imageId, image);
    }
    return image;
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) EntityNotFoundException(com.joliciel.jochre.EntityNotFoundException)

Aggregations

EntityNotFoundException (com.joliciel.jochre.EntityNotFoundException)13 EmptyResultDataAccessException (org.springframework.dao.EmptyResultDataAccessException)12 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)12 NamedParameterJdbcTemplate (org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)12 JochreSession (com.joliciel.jochre.JochreSession)1 Parameters (com.joliciel.jochre.security.Parameters)1 SecurityDao (com.joliciel.jochre.security.SecurityDao)1 User (com.joliciel.jochre.security.User)1 Date (java.util.Date)1 Session (org.zkoss.zk.ui.Session)1 Listen (org.zkoss.zk.ui.select.annotation.Listen)1