Java Code Examples for org.springframework.dao.DataAccessException.getCause()

The following are Jave code examples for showing how to use getCause() of the org.springframework.dao.DataAccessException class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: OperatieBRP   File:   Source Code and License Vote up 6 votes
public List<Long> zoekPersonen(final SqlStamementZoekPersoon sql, final boolean postgres) throws QueryCancelledException {
    final JdbcTemplate jdbcTemplate = new JdbcTemplate(masterDataSource);
    if (postgres) {
        //statement timeout zorgt ook voor het cancellen van query op server
        jdbcTemplate.execute(String.format("set local statement_timeout = %d", TimeUnit.SECONDS.toMillis(maxStatementDuurSec)));
    try {
        return jdbcTemplate.queryForList(sql.getSql(), Long.class, (Object[]) sql.getParameters().toArray());
    } catch (DataAccessException e) {
        if (e.getCause() != null && e.getCause() instanceof SQLException && SQL_TIMEOUT_CODE.equals(((SQLException) e.getCause()).getSQLState())) {
            throw new QueryCancelledException(e);
        throw e;