use of org.springframework.dao.EmptyResultDataAccessException in project perun by CESNET.
the class PerunNotifObjectDaoImpl method isObjectRelation.
@Override
public boolean isObjectRelation(int templateId, Integer objectId) {
logger.debug("IsObjectRelation for templateId: {}, objectId: {}", Arrays.asList(templateId, objectId));
try {
SqlRowSet rowSet = this.getJdbcTemplate().queryForRowSet("select * from pn_regex_object where regex_id = ? AND object_id = ?", templateId, objectId);
logger.debug("Relation between templateId: {} and objectId: {}, found.", Arrays.asList(templateId, objectId));
return rowSet.next();
} catch (EmptyResultDataAccessException ex) {
//This exception signals empty row
logger.debug("Relation between templateId: {}, and objectId: {}, not found", Arrays.asList(templateId, objectId));
return false;
}
}
use of org.springframework.dao.EmptyResultDataAccessException in project perun by CESNET.
the class PerunNotifRegexDaoImpl method getPerunNotifRegexById.
@Override
public PerunNotifRegex getPerunNotifRegexById(int id) throws InternalErrorException {
logger.debug("Loading regex from db by id: {}", id);
PerunNotifRegex regex = null;
try {
regex = this.getJdbcTemplate().queryForObject("SELECT * from pn_regex where id = ?", new Object[] { id }, PerunNotifRegex.PERUN_NOTIF_REGEX);
} catch (EmptyResultDataAccessException ex) {
logger.debug("Regex with id: {}, not found.", id);
return null;
}
logger.debug("Regex with id: {}, loaded from db. Loading objects.", id);
List<PerunNotifObject> objects = this.getJdbcTemplate().query("SELECT * from pn_object object JOIN pn_regex_object bind ON object.id = bind.object_id WHERE bind.regex_id = ?", new Object[] { regex.getId() }, PerunNotifObject.PERUN_NOTIF_OBJECT);
regex.addObjects(objects);
logger.debug("Objects loaded result: {}", regex);
return regex;
}
use of org.springframework.dao.EmptyResultDataAccessException in project perun by CESNET.
the class PerunNotifTemplateDaoImpl method getPerunNotifTemplateById.
@Override
public PerunNotifTemplate getPerunNotifTemplateById(int id) throws InternalErrorException {
PerunNotifTemplate template = null;
try {
template = this.getJdbcTemplate().queryForObject("SELECT * from pn_template where id = ?", new Object[] { id }, PerunNotifTemplate.PERUN_NOTIF_TEMPLATE);
} catch (EmptyResultDataAccessException ex) {
//This exception is thrown when object is not found
return null;
}
Set<PerunNotifRegex> regexes = perunNotifRegexDao.getPerunNotifRegexForTemplateId(template.getId());
template.setMatchingRegexs(regexes);
List<PerunNotifReceiver> perunNotifReceiver = this.getJdbcTemplate().query("SELECT * from pn_receiver where template_id = ?", new Object[] { template.getId() }, PerunNotifReceiver.PERUN_NOTIF_RECEIVER);
template.setReceivers(perunNotifReceiver);
List<PerunNotifTemplateMessage> perunNotifTemplateMessages = this.getJdbcTemplate().query("SELECT * from pn_template_message where template_id = ?", new Object[] { template.getId() }, PerunNotifTemplateMessage.PERUN_NOTIF_TEMPLATE_MESSAGE_ROW_MAPPER);
template.setPerunNotifTemplateMessages(perunNotifTemplateMessages);
return template;
}
use of org.springframework.dao.EmptyResultDataAccessException in project bamboobsc by billchen198318.
the class SysMessageUtil method get.
public static String get(String code) {
if (code == null || "".equals(code)) {
return "";
}
if (sysMsgMap.get(code) != null) {
return sysMsgMap.get(code);
}
init();
if (jdbcTemplate == null) {
return "";
}
String message = null;
TbSysCode sysCode = new TbSysCode();
sysCode.setCode(code);
Map<String, Object> queryMap = getQuery(sysCode);
if (queryMap == null) {
return "";
}
try {
message = jdbcTemplate.queryForObject(((String) queryMap.get(SqlGenerateUtil.RETURN_SQL)), (Object[]) queryMap.get(SqlGenerateUtil.RETURN_PARAMS), String.class);
if (message != null) {
sysMsgMap.put(code, message);
}
} catch (EmptyResultDataAccessException eda) {
System.out.println(eda.getMessage().toString());
} catch (Exception e) {
e.printStackTrace();
}
return message == null ? code : message;
}
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;
}
}
Aggregations