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;
}
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();
}
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);
}
}
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);
}
}
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;
}
Aggregations