use of org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate in project nextprot-api by calipho-sib.
the class UserProteinListDaoImpl method deleteProteinListItems.
@Override
public int deleteProteinListItems(long listId, Set<String> accessions) {
if (!accessions.isEmpty()) {
final String DELETE_SQL = sqlDictionary.getSQLQuery("delete-protein_list_items");
Map<String, Object> params = new HashMap<String, Object>();
params.put("accession_numbers", accessions);
params.put("list_id", listId);
return new NamedParameterJdbcTemplate(dsLocator.getUserDataSource()).update(DELETE_SQL, params);
}
return 0;
}
use of org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate in project nextprot-api by calipho-sib.
the class UserProteinListDaoImpl method getAccessionsByListId.
/**
* Get the accession numbers that belongs to the list {@code listId}
*
* @param listId the list identifier
* @return a set of proteins
*/
@Override
public Set<String> getAccessionsByListId(long listId) {
SqlParameterSource namedParameters = new MapSqlParameterSource("list_id", listId);
List<String> accs = new NamedParameterJdbcTemplate(dsLocator.getUserDataSource()).queryForList(sqlDictionary.getSQLQuery("read-protein-list-items-by-listid"), namedParameters, String.class);
return new HashSet<String>(accs);
}
use of org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate in project nextprot-api by calipho-sib.
the class UserProteinListDaoImpl method getUserProteinListByPublicId.
@Override
public UserProteinList getUserProteinListByPublicId(String publicId) throws DataAccessException {
String sql = sqlDictionary.getSQLQuery("read-user-protein-list-by-pubid");
SqlParameterSource namedParams = new MapSqlParameterSource("public_id", publicId);
NamedParameterJdbcTemplate template = new NamedParameterJdbcTemplate(dsLocator.getUserDataSource());
UserProteinList userProteinList = template.queryForObject(sql, namedParams, new ProteinListRowMapper());
userProteinList.setAccessions(getAccessionsByListId(userProteinList.getId()));
return userProteinList;
}
use of org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate in project nextprot-api by calipho-sib.
the class UserProteinListDaoImpl method deleteUserProteinList.
@Override
public int deleteUserProteinList(long listId) {
final String DELETE_SQL = sqlDictionary.getSQLQuery("delete-user-protein-list");
Map<String, Object> params = new HashMap<String, Object>();
params.put("list_id", listId);
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 UserProteinListDaoImpl method updateUserProteinListMetadata.
@Override
public void updateUserProteinListMetadata(UserProteinList src) {
final String UPDATE_SQL = sqlDictionary.getSQLQuery("update-user-protein-list");
MapSqlParameterSource namedParameters = new MapSqlParameterSource();
// key to identify application to be updated
namedParameters.addValue("list_id", src.getId());
// values to update
namedParameters.addValue("description", src.getDescription());
namedParameters.addValue("list_name", src.getName());
NamedParameterJdbcTemplate jdbcTemplate = new NamedParameterJdbcTemplate(dsLocator.getUserDataSource());
int affectedRows = jdbcTemplate.update(UPDATE_SQL, namedParameters);
if (affectedRows != 1) {
String msg = "oops something wrong occurred" + affectedRows + " rows were affected instead of only 1.";
Logger.error(msg);
throw new NextProtException(msg);
}
}
Aggregations