use of org.springframework.jdbc.core.namedparam.MapSqlParameterSource in project perun by CESNET.
the class AttributesManagerImpl method getRequiredAttributes.
public List<Attribute> getRequiredAttributes(PerunSession sess, Resource resource, List<Integer> serviceIds) throws InternalErrorException {
try {
List<String> namespace = new ArrayList();
namespace.add(AttributesManager.NS_RESOURCE_ATTR_DEF);
namespace.add(AttributesManager.NS_RESOURCE_ATTR_CORE);
namespace.add(AttributesManager.NS_RESOURCE_ATTR_OPT);
namespace.add(AttributesManager.NS_RESOURCE_ATTR_VIRT);
MapSqlParameterSource parameters = new MapSqlParameterSource();
parameters.addValue("serviceIds", serviceIds);
parameters.addValue("resourceId", resource.getId());
parameters.addValue("namespace", namespace);
return this.namedParameterJdbcTemplate.query("select " + getAttributeMappingSelectQuery("resource_attr_values") + " from attr_names " + "join service_required_attrs on id=service_required_attrs.attr_id and service_required_attrs.service_id in (:serviceIds) " + "left join resource_attr_values on id=resource_attr_values.attr_id and resource_attr_values.resource_id=:resourceId " + "where namespace in (:namespace)", parameters, new AttributeRowMapper(sess, this, resource));
} catch (EmptyResultDataAccessException ex) {
log.debug("None required attributes found for resource: {} and services with id {} ", resource, serviceIds);
return new ArrayList<Attribute>();
} catch (RuntimeException ex) {
throw new InternalErrorException(ex);
}
}
use of org.springframework.jdbc.core.namedparam.MapSqlParameterSource in project perun by CESNET.
the class AttributesManagerImpl method getAttributes.
public List<Attribute> getAttributes(PerunSession sess, UserExtSource ues, List<String> attrNames) throws InternalErrorException {
MapSqlParameterSource parameters = new MapSqlParameterSource();
parameters.addValue("uesId", ues.getId());
parameters.addValue("nSC", AttributesManager.NS_UES_ATTR_CORE);
parameters.addValue("nSO", AttributesManager.NS_UES_ATTR_OPT);
parameters.addValue("nSD", AttributesManager.NS_UES_ATTR_DEF);
parameters.addValue("nSV", AttributesManager.NS_UES_ATTR_VIRT);
parameters.addValue("attrNames", attrNames);
try {
return namedParameterJdbcTemplate.query("select " + getAttributeMappingSelectQuery("ues") + " from attr_names " + "left join user_ext_source_attr_values ues on id=ues.attr_id and ues_id=:uesId " + "where namespace in ( :nSC,:nSO,:nSD,:nSV ) and attr_names.attr_name in ( :attrNames )", parameters, new AttributeRowMapper(sess, this, ues));
} catch (EmptyResultDataAccessException ex) {
return new ArrayList<Attribute>();
} catch (RuntimeException ex) {
throw new InternalErrorException(ex);
}
}
use of org.springframework.jdbc.core.namedparam.MapSqlParameterSource in project perun by CESNET.
the class AttributesManagerImpl method getAttributes.
public List<Attribute> getAttributes(PerunSession sess, Vo vo, List<String> attrNames) throws InternalErrorException {
MapSqlParameterSource parameters = new MapSqlParameterSource();
parameters.addValue("vId", vo.getId());
parameters.addValue("nSC", AttributesManager.NS_VO_ATTR_CORE);
parameters.addValue("nSO", AttributesManager.NS_VO_ATTR_OPT);
parameters.addValue("nSD", AttributesManager.NS_VO_ATTR_DEF);
parameters.addValue("nSV", AttributesManager.NS_VO_ATTR_VIRT);
parameters.addValue("attrNames", attrNames);
try {
return namedParameterJdbcTemplate.query("select " + getAttributeMappingSelectQuery("vot") + " from attr_names " + "left join vo_attr_values vot on id=vot.attr_id and vo_id=:vId " + "where namespace in ( :nSC,:nSO,:nSD,:nSV ) and attr_names.attr_name in ( :attrNames )", parameters, new AttributeRowMapper(sess, this, vo));
} catch (EmptyResultDataAccessException ex) {
return new ArrayList<Attribute>();
} catch (RuntimeException ex) {
throw new InternalErrorException(ex);
}
}
use of org.springframework.jdbc.core.namedparam.MapSqlParameterSource in project perun by CESNET.
the class ResourcesManagerImpl method getResourcesByIds.
public List<Resource> getResourcesByIds(PerunSession sess, List<Integer> resourcesIds) throws InternalErrorException {
if (resourcesIds.size() == 0) {
return new ArrayList<Resource>();
}
MapSqlParameterSource parameters = new MapSqlParameterSource();
parameters.addValue("ids", resourcesIds);
try {
return this.namedParameterJdbcTemplate.query("select " + resourceMappingSelectQuery + " from resources where resources.id in ( :ids )", parameters, RESOURCE_MAPPER);
} catch (RuntimeException ex) {
throw new InternalErrorException(ex);
}
}
use of org.springframework.jdbc.core.namedparam.MapSqlParameterSource in project perun by CESNET.
the class UsersManagerImpl method getUserExtsourcesByIds.
public List<UserExtSource> getUserExtsourcesByIds(PerunSession sess, List<Integer> ids) throws InternalErrorException {
if (ids.size() == 0) {
return new ArrayList<UserExtSource>();
}
MapSqlParameterSource parameters = new MapSqlParameterSource();
parameters.addValue("ids", ids);
try {
return namedParameterJdbcTemplate.query("select " + userExtSourceMappingSelectQuery + "," + ExtSourcesManagerImpl.extSourceMappingSelectQuery + " from user_ext_sources left join ext_sources on user_ext_sources.ext_sources_id=ext_sources.id where" + " user_ext_sources.id in ( :ids )", parameters, USEREXTSOURCE_MAPPER);
} catch (EmptyResultDataAccessException ex) {
return new ArrayList<UserExtSource>();
} catch (RuntimeException e) {
throw new InternalErrorException(e);
}
}
Aggregations