use of org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate in project nextprot-api by calipho-sib.
the class UserDaoImpl method deleteUser.
@Override
public void deleteUser(User user) {
final String DELETE_SQL = sqlDictionary.getSQLQuery("delete-user");
Map<String, Object> params = new HashMap<String, Object>();
params.put("user_id", user.getId());
int affectedRows = new NamedParameterJdbcTemplate(dsLocator.getUserDataSource()).update(DELETE_SQL, params);
if (affectedRows != 1) {
String msg = "oops something wrong occurred" + affectedRows + " rows were affected instead of only 1.";
Logger.error(msg);
throw new NextProtException(msg);
}
}
use of org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate in project nextprot-api by calipho-sib.
the class UserDaoImpl method createUser.
@Override
public long createUser(User user) {
final String INSERT_USER_SQL = sqlDictionary.getSQLQuery("create-user");
MapSqlParameterSource namedParameters = new MapSqlParameterSource();
namedParameters.addValue("user_name", user.getUsername());
namedParameters.addValue("first_name", user.getFirstName());
namedParameters.addValue("last_name", user.getLastName());
long key = JdbcUtils.insertAndGetKey(INSERT_USER_SQL, "user_id", namedParameters, new NamedParameterJdbcTemplate(dsLocator.getUserDataSource())).longValue();
if (user.getAuthorities() != null && !user.getAuthorities().isEmpty()) {
insertUserAuthorities(key, user.getAuthorities());
}
return key;
}
use of org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate in project nextprot-api by calipho-sib.
the class UserQueryDaoImpl method deleteUserQuery.
@Override
public int deleteUserQuery(final long queryId) {
final String DELETE_SQL = sqlDictionary.getSQLQuery("delete-user-query");
Map<String, Object> params = new HashMap<String, Object>();
params.put("query_id", queryId);
return new NamedParameterJdbcTemplate(dsLocator.getUserDataSource()).update(DELETE_SQL, params);
}
use of org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate in project nextprot-api by calipho-sib.
the class UserQueryDaoImpl method getUserQueryById.
@Override
public UserQuery getUserQueryById(long queryId) {
String sql = sqlDictionary.getSQLQuery("read-user-query-by-id");
MapSqlParameterSource namedParameters = new MapSqlParameterSource();
namedParameters.addValue("query_id", queryId);
UserQuery query = new NamedParameterJdbcTemplate(dsLocator.getUserDataSource()).queryForObject(sql, namedParameters, new UserQueryRowMapper());
Map<Long, Set<String>> tags = getQueryTags(Arrays.asList(query.getUserQueryId()));
query.setTags(tags.get(queryId));
return query;
}
use of org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate in project SSM by Intel-bigdata.
the class ActionDao method getByIds.
public List<ActionInfo> getByIds(List<Long> aids) {
NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
MapSqlParameterSource parameterSource = new MapSqlParameterSource();
parameterSource.addValue("aids", aids);
return namedParameterJdbcTemplate.query("SELECT * FROM " + TABLE_NAME + " WHERE aid IN (:aids)", parameterSource, new ActionRowMapper());
}
Aggregations