Search in sources :

Example 46 with NamedParameterJdbcTemplate

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;
}
Also used : NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)

Example 47 with NamedParameterJdbcTemplate

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);
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) SqlParameterSource(org.springframework.jdbc.core.namedparam.SqlParameterSource) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)

Example 48 with NamedParameterJdbcTemplate

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;
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) SqlParameterSource(org.springframework.jdbc.core.namedparam.SqlParameterSource) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) UserProteinList(org.nextprot.api.user.domain.UserProteinList)

Example 49 with NamedParameterJdbcTemplate

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);
}
Also used : NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)

Example 50 with NamedParameterJdbcTemplate

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);
    }
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)

Aggregations

NamedParameterJdbcTemplate (org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)119 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)66 SqlParameterSource (org.springframework.jdbc.core.namedparam.SqlParameterSource)42 HashMap (java.util.HashMap)30 ResultSet (java.sql.ResultSet)16 SQLException (java.sql.SQLException)16 DbXref (org.nextprot.api.core.domain.DbXref)8 NextProtException (org.nextprot.api.commons.exception.NextProtException)7 PublicationDbXref (org.nextprot.api.core.domain.PublicationDbXref)7 ArrayList (java.util.ArrayList)5 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)5 List (java.util.List)4 Map (java.util.Map)4 CvTerm (org.nextprot.api.core.domain.CvTerm)4 GargoyleException (com.kyj.fx.voeditor.visual.exceptions.GargoyleException)3 NotSupportException (com.kyj.fx.voeditor.visual.exceptions.NotSupportException)3 DataSource (javax.sql.DataSource)3 UserProteinList (org.nextprot.api.user.domain.UserProteinList)3 ServiceException (com.netsteadfast.greenstep.base.exception.ServiceException)2 Date (java.util.Date)2