Search in sources :

Example 41 with MapSqlParameterSource

use of org.springframework.jdbc.core.namedparam.MapSqlParameterSource in project sakuli by ConSol.

the class DaoTestSuiteImpl method insertInitialTestSuiteData.

/**
     * {@inheritDoc}
     */
@Override
public int insertInitialTestSuiteData() {
    LOGGER.debug("Build SQL query for new primary key in table 'sakuli_suites'");
    testSuite.refreshState();
    MapSqlParameterSource tcParameters = getInitialDataParameters();
    LOGGER.debug("write the following values to 'sakuli_suites': " + tcParameters.getValues() + " ==>  now execute ....");
    SimpleJdbcInsert insertInitialSuiteData = new SimpleJdbcInsert(getDataSource()).withTableName("sakuli_suites").usingGeneratedKeyColumns("id");
    int dbPrimaryKey = insertInitialSuiteData.executeAndReturnKey(tcParameters).intValue();
    LOGGER.info("test suite \"" + testSuite.getId() + "\" has been written to 'sakuli_suites' with  primaryKey=" + dbPrimaryKey);
    return dbPrimaryKey;
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) SimpleJdbcInsert(org.springframework.jdbc.core.simple.SimpleJdbcInsert)

Example 42 with MapSqlParameterSource

use of org.springframework.jdbc.core.namedparam.MapSqlParameterSource in project sakuli by ConSol.

the class DaoTestSuiteImpl method saveTestSuiteToSahiJobs.

@Override
public int saveTestSuiteToSahiJobs() {
    LOGGER.debug("save the guid to the table 'sakuli_jobs'");
    //build up the statement
    MapSqlParameterSource tcParameters = getGuidParameter();
    LOGGER.debug("write the following values to 'sakuli_jobs': " + tcParameters.getValues() + " ==>  now execute ....");
    SimpleJdbcInsert insertTS = new SimpleJdbcInsert(getDataSource()).withTableName("sakuli_jobs").usingGeneratedKeyColumns("id");
    testSuite.setDbJobPrimaryKey(insertTS.executeAndReturnKey(tcParameters).intValue());
    LOGGER.info("the test suite \"" + testSuite.getId() + "\"" + "with the guid \"" + testSuite.getGuid() + "\" has been written to 'sakuli_jobs' with  primaryKey=" + testSuite.getDbJobPrimaryKey());
    return testSuite.getDbJobPrimaryKey();
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) SimpleJdbcInsert(org.springframework.jdbc.core.simple.SimpleJdbcInsert)

Example 43 with MapSqlParameterSource

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

the class MembersManagerImpl method getMembersByUsers.

public List<Member> getMembersByUsers(PerunSession sess, List<User> users, Vo vo) throws InternalErrorException {
    // If usersIds is empty, we can immediatelly return empty results
    if (users.size() == 0) {
        return new ArrayList<Member>();
    }
    MapSqlParameterSource parameters = new MapSqlParameterSource();
    Set<Integer> usersIds = new HashSet<Integer>();
    for (User user : users) {
        usersIds.add(user.getId());
    }
    parameters.addValue("ids", usersIds);
    parameters.addValue("vo", vo.getId());
    try {
        return this.namedParameterJdbcTemplate.query("select " + memberMappingSelectQuery + " from members where members.user_id in ( :ids ) and members.vo_id=:vo", parameters, MEMBER_MAPPER);
    } catch (EmptyResultDataAccessException ex) {
        return new ArrayList<Member>();
    } catch (RuntimeException ex) {
        throw new InternalErrorException(ex);
    }
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) User(cz.metacentrum.perun.core.api.User) ArrayList(java.util.ArrayList) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) Member(cz.metacentrum.perun.core.api.Member) HashSet(java.util.HashSet)

Example 44 with MapSqlParameterSource

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

the class GroupsManagerImpl method getGroupMembers.

public List<Member> getGroupMembers(PerunSession sess, Group group, List<Status> statuses, boolean excludeStatus) throws InternalErrorException {
    try {
        MapSqlParameterSource parameters = new MapSqlParameterSource();
        List<Integer> statusesCodes = new ArrayList<Integer>();
        for (Status status : statuses) {
            statusesCodes.add(status.getCode());
        }
        parameters.addValue("statuses", statusesCodes);
        parameters.addValue("group_id", group.getId());
        if (excludeStatus) {
            // Exclude members with one of the status
            return this.namedParameterJdbcTemplate.query("select " + MembersManagerImpl.groupsMembersMappingSelectQuery + " from groups_members join members on members.id=groups_members.member_id " + "where groups_members.group_id=:group_id and members.status" + Compatibility.castToInteger() + " not in (:statuses)", parameters, MembersManagerImpl.MEMBER_MAPPER);
        } else {
            // Include members with one of the status
            return this.namedParameterJdbcTemplate.query("select " + MembersManagerImpl.groupsMembersMappingSelectQuery + " from groups_members join members on members.id=groups_members.member_id " + "where groups_members.group_id=:group_id and members.status" + Compatibility.castToInteger() + " in (:statuses)", parameters, MembersManagerImpl.MEMBER_MAPPER);
        }
    } catch (EmptyResultDataAccessException e) {
        return new ArrayList<Member>();
    } catch (RuntimeException e) {
        throw new InternalErrorException(e);
    }
}
Also used : Status(cz.metacentrum.perun.core.api.Status) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) ArrayList(java.util.ArrayList) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Member(cz.metacentrum.perun.core.api.Member)

Example 45 with MapSqlParameterSource

use of org.springframework.jdbc.core.namedparam.MapSqlParameterSource in project Gargoyle by callakrsos.

the class DbUtil method select.

public static <T> List<T> select(DataSource dataSource, final String sql, Map<String, Object> paramMap, RowMapper<T> rowMapper) throws Exception {
    List<T> query = null;
    try {
        noticeQuery(sql);
        NamedParameterJdbcTemplate jdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
        // String _sql = ValueUtil.getVelocityToText(sql, paramMap);
        // LOGGER.debug(_sql);
        query = jdbcTemplate.query(sql, new MapSqlParameterSource(paramMap), rowMapper);
    } catch (Exception e) {
        throw e;
    }
    return query;
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) SQLException(java.sql.SQLException) GargoyleException(com.kyj.fx.voeditor.visual.exceptions.GargoyleException) NotSupportException(com.kyj.fx.voeditor.visual.exceptions.NotSupportException)

Aggregations

MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)51 EmptyResultDataAccessException (org.springframework.dao.EmptyResultDataAccessException)20 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 HashMap (java.util.HashMap)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 HashSet (java.util.HashSet)2 Map (java.util.Map)2