Search in sources :

Example 11 with MapSqlParameterSource

use of org.springframework.jdbc.core.namedparam.MapSqlParameterSource in project perun by CESNET.

the class AttributesManagerImpl method getAllAttributesStartWithNameWithoutNullValue.

public List<Attribute> getAllAttributesStartWithNameWithoutNullValue(PerunSession sess, Group group, String startPartOfName) throws InternalErrorException {
    MapSqlParameterSource parameters = new MapSqlParameterSource();
    parameters.addValue("gId", group.getId());
    parameters.addValue("nSC", AttributesManager.NS_GROUP_ATTR_CORE);
    parameters.addValue("nSO", AttributesManager.NS_GROUP_ATTR_OPT);
    parameters.addValue("nSD", AttributesManager.NS_GROUP_ATTR_DEF);
    parameters.addValue("startPartOfName", startPartOfName + "%");
    try {
        return namedParameterJdbcTemplate.query("select " + getAttributeMappingSelectQuery("grt") + " from attr_names " + "left join group_attr_values grt on id=grt.attr_id and group_id=:gId " + "where namespace in ( :nSC,:nSO,:nSD ) and attr_names.attr_name LIKE :startPartOfName", parameters, new AttributeRowMapper(sess, this, group));
    } catch (EmptyResultDataAccessException ex) {
        return new ArrayList<Attribute>();
    } catch (RuntimeException ex) {
        throw new InternalErrorException(ex);
    }
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) ConsistencyErrorRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.ConsistencyErrorRuntimeException) InternalErrorRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.InternalErrorRuntimeException) Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 12 with MapSqlParameterSource

use of org.springframework.jdbc.core.namedparam.MapSqlParameterSource in project perun by CESNET.

the class AttributesManagerImpl method getAttributes.

@Override
public List<Attribute> getAttributes(PerunSession sess, Member member, Group group, List<String> attrNames) throws InternalErrorException {
    MapSqlParameterSource parameters = new MapSqlParameterSource();
    parameters.addValue("mId", member.getId());
    parameters.addValue("gId", group.getId());
    parameters.addValue("nSO", AttributesManager.NS_MEMBER_GROUP_ATTR_OPT);
    parameters.addValue("nSD", AttributesManager.NS_MEMBER_GROUP_ATTR_DEF);
    parameters.addValue("nSV", AttributesManager.NS_MEMBER_GROUP_ATTR_VIRT);
    parameters.addValue("attrNames", attrNames);
    try {
        return namedParameterJdbcTemplate.query("select " + getAttributeMappingSelectQuery("mem_gr") + " from attr_names " + "left join member_group_attr_values mem_gr on id=mem_gr.attr_id and member_id=:mId and group_id=:gId " + "where namespace in ( :nSO,:nSD,:nSV ) and attr_names.attr_name in ( :attrNames )", parameters, new AttributeRowMapper(sess, this, member, group));
    } catch (EmptyResultDataAccessException ex) {
        return new ArrayList<Attribute>();
    } catch (RuntimeException ex) {
        throw new InternalErrorException(ex);
    }
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) ConsistencyErrorRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.ConsistencyErrorRuntimeException) InternalErrorRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.InternalErrorRuntimeException) Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 13 with MapSqlParameterSource

use of org.springframework.jdbc.core.namedparam.MapSqlParameterSource in project perun by CESNET.

the class AttributesManagerImpl method getAttributes.

public List<Attribute> getAttributes(PerunSession sess, Group group, List<String> attrNames) throws InternalErrorException {
    MapSqlParameterSource parameters = new MapSqlParameterSource();
    parameters.addValue("gId", group.getId());
    parameters.addValue("nSC", AttributesManager.NS_GROUP_ATTR_CORE);
    parameters.addValue("nSO", AttributesManager.NS_GROUP_ATTR_OPT);
    parameters.addValue("nSD", AttributesManager.NS_GROUP_ATTR_DEF);
    parameters.addValue("nSV", AttributesManager.NS_GROUP_ATTR_VIRT);
    parameters.addValue("attrNames", attrNames);
    try {
        return namedParameterJdbcTemplate.query("select " + getAttributeMappingSelectQuery("groupattr") + " from attr_names " + "left join group_attr_values groupattr on id=groupattr.attr_id and group_id=:gId " + "where namespace in ( :nSC,:nSO,:nSD,:nSV ) and attr_names.attr_name in ( :attrNames )", parameters, new AttributeRowMapper(sess, this, group));
    } catch (EmptyResultDataAccessException ex) {
        return new ArrayList<Attribute>();
    } catch (RuntimeException ex) {
        throw new InternalErrorException(ex);
    }
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) ConsistencyErrorRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.ConsistencyErrorRuntimeException) InternalErrorRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.InternalErrorRuntimeException) Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 14 with MapSqlParameterSource

use of org.springframework.jdbc.core.namedparam.MapSqlParameterSource in project perun by CESNET.

the class AttributesManagerImpl method getAttributes.

public List<Attribute> getAttributes(PerunSession sess, User user, List<String> attrNames) throws InternalErrorException {
    MapSqlParameterSource parameters = new MapSqlParameterSource();
    parameters.addValue("uId", user.getId());
    parameters.addValue("nSC", AttributesManager.NS_USER_ATTR_CORE);
    parameters.addValue("nSO", AttributesManager.NS_USER_ATTR_OPT);
    parameters.addValue("nSD", AttributesManager.NS_USER_ATTR_DEF);
    parameters.addValue("nSV", AttributesManager.NS_USER_ATTR_VIRT);
    parameters.addValue("attrNames", attrNames);
    try {
        return namedParameterJdbcTemplate.query("select " + getAttributeMappingSelectQuery("usr") + " from attr_names " + "left join user_attr_values usr on id=usr.attr_id and user_id=:uId " + "where namespace in ( :nSC,:nSO,:nSD,:nSV ) and attr_names.attr_name in ( :attrNames )", parameters, new AttributeRowMapper(sess, this, user));
    } catch (EmptyResultDataAccessException ex) {
        return new ArrayList<Attribute>();
    } catch (RuntimeException ex) {
        throw new InternalErrorException(ex);
    }
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) ConsistencyErrorRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.ConsistencyErrorRuntimeException) InternalErrorRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.InternalErrorRuntimeException) Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 15 with MapSqlParameterSource

use of org.springframework.jdbc.core.namedparam.MapSqlParameterSource in project perun by CESNET.

the class AttributesManagerImpl method getAttributes.

public List<Attribute> getAttributes(PerunSession sess, Member member, List<String> attrNames) throws InternalErrorException {
    MapSqlParameterSource parameters = new MapSqlParameterSource();
    parameters.addValue("mId", member.getId());
    parameters.addValue("nSC", AttributesManager.NS_MEMBER_ATTR_CORE);
    parameters.addValue("nSO", AttributesManager.NS_MEMBER_ATTR_OPT);
    parameters.addValue("nSD", AttributesManager.NS_MEMBER_ATTR_DEF);
    parameters.addValue("nSV", AttributesManager.NS_MEMBER_ATTR_VIRT);
    parameters.addValue("attrNames", attrNames);
    try {
        return namedParameterJdbcTemplate.query("select " + getAttributeMappingSelectQuery("mem") + " from attr_names " + "left join member_attr_values mem on id=mem.attr_id and member_id=:mId " + "where namespace in ( :nSC,:nSO,:nSD,:nSV ) and attr_names.attr_name in ( :attrNames )", parameters, new AttributeRowMapper(sess, this, member));
    } catch (EmptyResultDataAccessException ex) {
        return new ArrayList<Attribute>();
    } catch (RuntimeException ex) {
        throw new InternalErrorException(ex);
    }
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) ConsistencyErrorRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.ConsistencyErrorRuntimeException) InternalErrorRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.InternalErrorRuntimeException) Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Aggregations

MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)42 EmptyResultDataAccessException (org.springframework.dao.EmptyResultDataAccessException)17 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)15 Attribute (cz.metacentrum.perun.core.api.Attribute)10 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)9 ConsistencyErrorRuntimeException (cz.metacentrum.perun.core.api.exceptions.rt.ConsistencyErrorRuntimeException)9 InternalErrorRuntimeException (cz.metacentrum.perun.core.api.exceptions.rt.InternalErrorRuntimeException)9 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)6 SimpleJdbcInsert (org.springframework.jdbc.core.simple.SimpleJdbcInsert)4 Member (cz.metacentrum.perun.core.api.Member)3 SqlOutParameter (org.springframework.jdbc.core.SqlOutParameter)3 SqlParameter (org.springframework.jdbc.core.SqlParameter)3 ParsedSql (org.springframework.jdbc.core.namedparam.ParsedSql)3 User (cz.metacentrum.perun.core.api.User)2 IOException (java.io.IOException)2 ResultSet (java.sql.ResultSet)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 GargoyleException (com.kyj.fx.voeditor.visual.exceptions.GargoyleException)1