use of org.springframework.jdbc.core.namedparam.MapSqlParameterSource in project Gargoyle by callakrsos.
the class VelocityTest method test.
@Test
public void test() throws SQLException, Exception {
String sql = "SELECT table_name FROM information_schema.tables WHERE 1=1 AND table_name in (:tableName) limit 50";
MapSqlParameterSource source = new MapSqlParameterSource();
List<String> asList = Arrays.asList("tables", "columns");
source.addValue("tableName", asList);
List<HashMap<String, Object>> select = DbUtil.select(sql, source, (rs, r) -> {
HashMap<String, Object> hashMap = new HashMap<String, Object>();
hashMap.put("table_name", rs.getString("table_name"));
return hashMap;
});
System.out.println(select);
}
use of org.springframework.jdbc.core.namedparam.MapSqlParameterSource in project spring-framework by spring-projects.
the class SimpleJdbcCallTests method testAddInvoiceFuncWithMetaDataUsingMapParamSource.
@Test
public void testAddInvoiceFuncWithMetaDataUsingMapParamSource() throws Exception {
initializeAddInvoiceWithMetaData(true);
SimpleJdbcCall adder = new SimpleJdbcCall(dataSource).withFunctionName("add_invoice");
Number newId = adder.executeFunction(Number.class, new MapSqlParameterSource().addValue("amount", 1103).addValue("custid", 3));
assertEquals(4, newId.intValue());
verifyAddInvoiceWithMetaData(true);
verify(connection, atLeastOnce()).close();
}
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 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);
}
}
Aggregations