Search in sources :

Example 6 with EntityNotFoundException

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

the class SecurityDao method findUser.

public User findUser(String username) {
    User user = this.jochreSession.getObjectCache().getEntity(User.class, username);
    if (user == null) {
        NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
        String sql = "SELECT " + SELECT_USER + " FROM ocr_user WHERE user_username=:user_username";
        MapSqlParameterSource paramSource = new MapSqlParameterSource();
        paramSource.addValue("user_username", username);
        LOG.info(sql);
        logParameters(paramSource);
        try {
            user = jt.queryForObject(sql, paramSource, new UserMapper());
        } catch (EmptyResultDataAccessException ex) {
            throw new EntityNotFoundException("No User found for username " + username);
        }
        this.jochreSession.getObjectCache().putEntity(User.class, username, user);
    }
    return user;
}
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 7 with EntityNotFoundException

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

the class SecurityDao method loadParameters.

public Parameters loadParameters() {
    int parametersId = 1;
    Parameters parameters = this.jochreSession.getObjectCache().getEntity(Parameters.class, parametersId);
    if (parameters == null) {
        NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
        String sql = "SELECT " + SELECT_PARAM + " FROM ocr_param WHERE param_id=:param_id";
        MapSqlParameterSource paramSource = new MapSqlParameterSource();
        paramSource.addValue("param_id", parametersId);
        LOG.info(sql);
        logParameters(paramSource);
        try {
            parameters = jt.queryForObject(sql, paramSource, new ParametersMapper());
        } catch (EmptyResultDataAccessException ex) {
            throw new EntityNotFoundException("No Parameters found for parameters id " + parametersId);
        }
        this.jochreSession.getObjectCache().putEntity(Parameters.class, parametersId, parameters);
    }
    return parameters;
}
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 8 with EntityNotFoundException

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

the class DocumentDao method loadJochreDocument.

public JochreDocument loadJochreDocument(int docId) {
    JochreDocument document = this.jochreSession.getObjectCache().getEntity(JochreDocument.class, docId);
    if (document == null) {
        NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
        String sql = "SELECT " + SELECT_DOCUMENT + " FROM ocr_document WHERE doc_id=:doc_id";
        MapSqlParameterSource paramSource = new MapSqlParameterSource();
        paramSource.addValue("doc_id", docId);
        LOG.info(sql);
        logParameters(paramSource);
        try {
            document = jt.queryForObject(sql, paramSource, new JochreDocumentMapper());
        } catch (EmptyResultDataAccessException ex) {
            throw new EntityNotFoundException("No JochreDocument found for documentId " + docId);
        }
        this.jochreSession.getObjectCache().putEntity(JochreDocument.class, docId, document);
    }
    return document;
}
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 9 with EntityNotFoundException

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

the class DocumentDao method loadJochreDocument.

public JochreDocument loadJochreDocument(String name) {
    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
    String sql = "SELECT " + SELECT_DOCUMENT + " FROM ocr_document WHERE doc_name=:doc_name";
    MapSqlParameterSource paramSource = new MapSqlParameterSource();
    paramSource.addValue("doc_name", name);
    LOG.info(sql);
    logParameters(paramSource);
    JochreDocument jochreDocument = null;
    try {
        jochreDocument = jt.queryForObject(sql, paramSource, new JochreDocumentMapper());
    } catch (EmptyResultDataAccessException ex) {
        throw new EntityNotFoundException("No JochreDocument found for name " + name);
    }
    return jochreDocument;
}
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 10 with EntityNotFoundException

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

the class DocumentDao method loadJochrePage.

public JochrePage loadJochrePage(int pageId) {
    JochrePage page = this.jochreSession.getObjectCache().getEntity(JochrePage.class, pageId);
    if (page == null) {
        NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource());
        String sql = "SELECT " + SELECT_PAGE + " FROM ocr_page WHERE page_id=:page_id";
        MapSqlParameterSource paramSource = new MapSqlParameterSource();
        paramSource.addValue("page_id", pageId);
        LOG.info(sql);
        logParameters(paramSource);
        try {
            page = jt.queryForObject(sql, paramSource, new JochrePageMapper());
        } catch (EmptyResultDataAccessException ex) {
            throw new EntityNotFoundException("No JochrePage found for pageId " + pageId);
        }
        this.jochreSession.getObjectCache().putEntity(JochrePage.class, pageId, page);
    }
    return page;
}
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