use of org.springframework.dao.EmptyResultDataAccessException in project summerb by skarpushin.
the class EasyCrudDaoMySqlImpl method findById.
@Override
public TDto findById(TId id) {
MapSqlParameterSource params = new MapSqlParameterSource();
params.addValue("id", id);
try {
return jdbc.queryForObject(sqlFindById, params, rowMapper);
} catch (EmptyResultDataAccessException e) {
return null;
}
}
use of org.springframework.dao.EmptyResultDataAccessException in project summerb by skarpushin.
the class EasyCrudDaoMySqlImpl method findOneByQuery.
@Override
public TDto findOneByQuery(Query query) {
MapSqlParameterSource params = new MapSqlParameterSource();
String whereClause = queryToNativeSqlCompiler.buildWhereClauseAndPopulateParams(query, params);
try {
return jdbc.queryForObject(sqlFindByCustomQuery + "WHERE " + whereClause, params, rowMapper);
} catch (EmptyResultDataAccessException e) {
return null;
}
}
use of org.springframework.dao.EmptyResultDataAccessException in project perun by CESNET.
the class urn_perun_user_attribute_def_virt_groupNames method getAttributeValue.
@Override
public Attribute getAttributeValue(PerunSessionImpl sess, User user, AttributeDefinition attributeDefinition) {
Attribute attribute = new Attribute(attributeDefinition);
Set<String> groupNames = new TreeSet<>();
List<Pair<String, String>> names;
try {
names = sess.getPerunBl().getDatabaseManagerBl().getJdbcPerunTemplate().query("SELECT" + " DISTINCT vos.short_name AS vo_short_name, groups.name AS group_name" + " FROM" + " members" + " JOIN vos ON vos.id = members.vo_id AND members.user_id = ? AND members.status = ?" + " JOIN groups_members ON groups_members.member_id = members.id AND groups_members.source_group_status = ?" + " JOIN groups ON groups_members.group_id = groups.id" + " ORDER BY vo_short_name, group_name", ROW_MAPPER, user.getId(), Status.VALID.getCode(), MemberGroupStatus.VALID.getCode());
} catch (EmptyResultDataAccessException e) {
names = new ArrayList<>();
} catch (RuntimeException e) {
throw new InternalErrorException(e);
}
for (Pair<String, String> one : names) {
String voShortName = one.getLeft();
groupNames.add(voShortName);
if (!VosManager.MEMBERS_GROUP.equals(one.getRight())) {
String groupName = one.getRight();
groupNames.add(voShortName + ":" + groupName);
}
}
attribute.setValue(new ArrayList<>(groupNames));
return attribute;
}
use of org.springframework.dao.EmptyResultDataAccessException in project perun by CESNET.
the class PerunNotifTemplateDaoImpl method getPerunNotifTemplateById.
@Override
public PerunNotifTemplate getPerunNotifTemplateById(int id) {
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 perun by CESNET.
the class FacilitiesManagerImpl method getAdmins.
@Override
public List<User> getAdmins(PerunSession sess, Facility facility) {
try {
// direct admins
Set<User> setOfAdmins = new HashSet<>(jdbc.query("select " + UsersManagerImpl.userMappingSelectQuery + " from authz join users on authz.user_id=users.id" + " where authz.facility_id=? and authz.role_id=(select id from roles where name=?)", UsersManagerImpl.USER_MAPPER, facility.getId(), Role.FACILITYADMIN.toLowerCase()));
// admins through a group
List<Group> listOfGroupAdmins = getAdminGroups(sess, facility);
for (Group authorizedGroup : listOfGroupAdmins) {
setOfAdmins.addAll(jdbc.query("select " + UsersManagerImpl.userMappingSelectQuery + " from users join members on users.id=members.user_id " + "join groups_members on groups_members.member_id=members.id where groups_members.group_id=?", UsersManagerImpl.USER_MAPPER, authorizedGroup.getId()));
}
return new ArrayList<>(setOfAdmins);
} catch (EmptyResultDataAccessException e) {
return new ArrayList<>();
} catch (RuntimeException e) {
throw new InternalErrorException(e);
}
}
Aggregations