Search in sources :

Example 56 with EmptyResultDataAccessException

use of org.springframework.dao.EmptyResultDataAccessException in project spring-data-jdbc by spring-projects.

the class JdbcRepositoryQuery method execute.

@Override
public Object execute(Object[] objects) {
    String query = determineQuery();
    MapSqlParameterSource parameters = bindParameters(objects);
    if (queryMethod.isModifyingQuery()) {
        int updatedCount = context.getTemplate().update(query, parameters);
        Class<?> returnedObjectType = queryMethod.getReturnedObjectType();
        return (returnedObjectType == boolean.class || returnedObjectType == Boolean.class) ? updatedCount != 0 : updatedCount;
    }
    if (queryMethod.isCollectionQuery() || queryMethod.isStreamQuery()) {
        return context.getTemplate().query(query, parameters, rowMapper);
    }
    try {
        return context.getTemplate().queryForObject(query, parameters, rowMapper);
    } catch (EmptyResultDataAccessException e) {
        return null;
    }
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException)

Example 57 with EmptyResultDataAccessException

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

the class JdbcMysqlImpl method queryForDate.

@Override
public java.util.Date queryForDate(String sql, StatementParameter param) {
    Object[] args = param.getArgs();
    int[] argTypes = param.getArgTypes();
    try {
        java.util.Date result = this.getJdbcTemplate().queryForObject(sql, args, argTypes, java.util.Date.class);
        return result;
    } catch (EmptyResultDataAccessException e) {
        return null;
    }
}
Also used : Date(java.util.Date) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException)

Example 58 with EmptyResultDataAccessException

use of org.springframework.dao.EmptyResultDataAccessException in project lavagna by digitalfondue.

the class CalendarService method getCalDavCalendar.

public Calendar getCalDavCalendar(String userToken) throws URISyntaxException, ParseException {
    UserWithPermission user;
    try {
        user = findUserFromCalendarToken(userToken);
    } catch (EmptyResultDataAccessException ex) {
        throw new SecurityException("Invalid token");
    }
    if (userRepository.isCalendarFeedDisabled(user)) {
        throw new SecurityException("Calendar feed disabled");
    }
    final Calendar calendar = new Calendar();
    calendar.getProperties().add(new ProdId("-//Lavagna//iCal4j 1.0//EN"));
    calendar.getProperties().add(Version.VERSION_2_0);
    calendar.getProperties().add(CalScale.GREGORIAN);
    calendar.getProperties().add(Method.PUBLISH);
    final List<VEvent> events = new ArrayList<>();
    final String applicationUrl = StringUtils.appendIfMissing(configurationRepository.getValue(Key.BASE_APPLICATION_URL), "/");
    final CalendarEventHandler handler = new CalendarVEventHandler(applicationUrl, cardDataService, userRepository, events);
    // Milestones
    addMilestoneEvents(handler, user);
    // Cards
    addCardEvents(handler, user);
    calendar.getComponents().addAll(events);
    return calendar;
}
Also used : VEvent(net.fortuna.ical4j.model.component.VEvent) StandardCalendarEventHandler(io.lavagna.service.calendarutils.StandardCalendarEventHandler) CalendarEventHandler(io.lavagna.service.calendarutils.CalendarEventHandler) Calendar(net.fortuna.ical4j.model.Calendar) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) ProdId(net.fortuna.ical4j.model.property.ProdId) CalendarVEventHandler(io.lavagna.service.calendarutils.CalendarVEventHandler)

Example 59 with EmptyResultDataAccessException

use of org.springframework.dao.EmptyResultDataAccessException in project nextprot-api by calipho-sib.

the class UserDaoImpl method getUserByUsername.

@Override
public User getUserByUsername(String username) throws DataAccessException {
    Map<String, String> namedParams = new HashMap<String, String>();
    namedParams.put("user_name", username);
    String sql = sqlDictionary.getSQLQuery("read-user-by-name");
    NamedParameterJdbcTemplate template = new NamedParameterJdbcTemplate(dsLocator.getUserDataSource());
    List<User> users = template.query(sql, namedParams, new UsersExtractor());
    if (users.isEmpty())
        throw new EmptyResultDataAccessException(1);
    return users.get(0);
}
Also used : User(org.nextprot.api.user.domain.User) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException)

Example 60 with EmptyResultDataAccessException

use of org.springframework.dao.EmptyResultDataAccessException in project rpki-validator-3 by RIPE-NCC.

the class TrustAnchorController method validationResults.

@GetMapping(path = "/{id}/validation-run")
public ResponseEntity<ApiResponse<ValidationRunResource>> validationResults(@PathVariable long id, HttpServletResponse response, Locale locale) throws IOException {
    TrustAnchor trustAnchor = trustAnchorRepository.get(id);
    ValidationRun validationRun = validationRunRepository.findLatestCompletedForTrustAnchor(trustAnchor).orElseThrow(() -> new EmptyResultDataAccessException("latest validation run for trust anchor " + id, 1));
    response.sendRedirect(linkTo(methodOn(ValidationRunController.class).get(validationRun.getId(), locale)).toString());
    return null;
}
Also used : ValidationRun(net.ripe.rpki.validator3.domain.ValidationRun) TrustAnchorValidationRun(net.ripe.rpki.validator3.domain.TrustAnchorValidationRun) TrustAnchor(net.ripe.rpki.validator3.domain.TrustAnchor) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) GetMapping(org.springframework.web.bind.annotation.GetMapping)

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