Search in sources :

Example 46 with EmptyResultDataAccessException

use of org.springframework.dao.EmptyResultDataAccessException in project CzechIdMng by bcvsolutions.

the class AbstractIntegrationTest method cleanup.

/**
 * After method ends.
 *
 * @since 11.1.0
 */
@After
public void cleanup() {
    evictCaches();
    // 
    // delete all related long running tasks
    UUID transactionId = TransactionContextHolder.getContext().getTransactionId();
    // 
    // clean up created events
    IdmEntityEventFilter eventFilter = new IdmEntityEventFilter();
    eventFilter.setTransactionId(transactionId);
    entityEventManager.findEvents(eventFilter, null).forEach(event -> {
        try {
            if (entityEventManager.getEvent(event.getId()) != null) {
                entityEventManager.deleteEvent(event);
            }
        } catch (EmptyResultDataAccessException ex) {
        // ok - already deleted asynchronously
        } catch (Exception ex) {
            LOG.warn("Event [{}] cannot be deleted.", event.getId(), ex);
        }
    });
    // clean up created long running tasks by executed method
    // 
    IdmLongRunningTaskFilter taskFilter = new IdmLongRunningTaskFilter();
    taskFilter.setTransactionId(transactionId);
    longRunningTaskService.find(taskFilter, null).forEach(task -> {
        if (task.isRunning()) {
            try {
                longRunningTaskManager.interrupt(task.getId());
                task = longRunningTaskService.get(task);
            } catch (ResultCodeException ex) {
                LOG.warn("Task [{}] cannot be interrupted.", task.getId(), ex);
            }
            if (task.isRunning()) {
                task.setRunning(false);
                task = longRunningTaskService.save(task);
            }
        }
        if (longRunningTaskService.get(task) != null) {
            longRunningTaskService.delete(task);
        }
    });
}
Also used : ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) IdmLongRunningTaskFilter(eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter) UUID(java.util.UUID) IdmEntityEventFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityEventFilter) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) After(org.junit.After)

Example 47 with EmptyResultDataAccessException

use of org.springframework.dao.EmptyResultDataAccessException in project metacat by Netflix.

the class MySqlTagService method get.

/**
 * Returns the TagItem for the given <code>name</code>.
 *
 * @param name tag name
 * @return TagItem
 */
@Transactional(readOnly = true)
public TagItem get(final String name) {
    try {
        return jdbcTemplate.queryForObject(SQL_GET_TAG_ITEM, new Object[] { name }, new int[] { Types.VARCHAR }, (rs, rowNum) -> {
            final TagItem tagItem = new TagItem();
            tagItem.setId(rs.getLong("id"));
            tagItem.setName(rs.getString("name"));
            tagItem.setCreatedBy(rs.getString("createdBy"));
            tagItem.setLastUpdated(rs.getDate("lastUpdated"));
            tagItem.setLastUpdatedBy(rs.getString("lastUpdatedBy"));
            tagItem.setDateCreated(rs.getDate("dateCreated"));
            tagItem.setValues(getValues(rs.getLong("id")));
            return tagItem;
        });
    } catch (EmptyResultDataAccessException e) {
        return null;
    } catch (Exception e) {
        final String message = String.format("Failed to get the tag for name %s", name);
        log.error(message, e);
        throw new UserMetadataServiceException(message, e);
    }
}
Also used : UserMetadataServiceException(com.netflix.metacat.common.server.usermetadata.UserMetadataServiceException) TagItem(com.netflix.metacat.common.server.model.TagItem) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) SQLException(java.sql.SQLException) MetacatBadRequestException(com.netflix.metacat.common.exception.MetacatBadRequestException) UserMetadataServiceException(com.netflix.metacat.common.server.usermetadata.UserMetadataServiceException) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 48 with EmptyResultDataAccessException

use of org.springframework.dao.EmptyResultDataAccessException in project leopard by tanhaichao.

the class ExporterMysqlImpl method export.

@Override
public <T> List<T> export(Class<T> model, int start, int size) {
    ExportSqlBuilder builder = new ExportSqlBuilder(model, ExportSqlBuilder.ESC_MYSQL);
    String tableName = builder.getTableName();
    String sql = builder.buildSql();
    System.out.println(sql);
    // return jdbc.queryForList(sql, model);
    try {
        return jdbc.getJdbcTemplate().query(sql, new ExporterLeopardBeanPropertyRowMapper<T>(model, tableName));
    } catch (EmptyResultDataAccessException e) {
        return null;
    }
}
Also used : EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) ExportSqlBuilder(io.leopard.exporter.ExportSqlBuilder)

Example 49 with EmptyResultDataAccessException

use of org.springframework.dao.EmptyResultDataAccessException in project leopard by tanhaichao.

the class ExporterOracleImpl method export.

@Override
public <T> List<T> export(Class<T> model, int start, int size) {
    ExportSqlBuilder builder = new ExportSqlBuilder(model, ExportSqlBuilder.ESC_ORACLE);
    String tableName = builder.getTableName();
    String sql = builder.buildSql();
    System.out.println(sql);
    // return jdbc.queryForList(sql, model);
    try {
        return jdbc.getJdbcTemplate().query(sql, new ExporterLeopardBeanPropertyRowMapper<T>(model, tableName));
    } catch (EmptyResultDataAccessException e) {
        return null;
    }
}
Also used : EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) ExportSqlBuilder(io.leopard.exporter.ExportSqlBuilder)

Example 50 with EmptyResultDataAccessException

use of org.springframework.dao.EmptyResultDataAccessException in project camel by apache.

the class SqlRouteTest method testInsert.

@Test
public void testInsert() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    template.sendBody("direct:insert", new Object[] { 10, "test", "test" });
    mock.assertIsSatisfied();
    try {
        String projectName = jdbcTemplate.queryForObject("select project from projects where id = 10", String.class);
        assertEquals("test", projectName);
    } catch (EmptyResultDataAccessException e) {
        fail("no row inserted");
    }
    Integer actualUpdateCount = mock.getExchanges().get(0).getIn().getHeader(SqlConstants.SQL_UPDATE_COUNT, Integer.class);
    assertEquals((Integer) 1, actualUpdateCount);
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) Test(org.junit.Test)

Aggregations

EmptyResultDataAccessException (org.springframework.dao.EmptyResultDataAccessException)99 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)46 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)31 ArrayList (java.util.ArrayList)19 HashSet (java.util.HashSet)9 Transactional (org.springframework.transaction.annotation.Transactional)9 Group (cz.metacentrum.perun.core.api.Group)8 User (cz.metacentrum.perun.core.api.User)8 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)7 SQLException (java.sql.SQLException)7 Test (org.junit.Test)6 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)6 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 Autowired (org.springframework.beans.factory.annotation.Autowired)4 Service (cz.metacentrum.perun.core.api.Service)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)3