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;
}
}
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;
}
}
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;
}
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);
}
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;
}
Aggregations