Search in sources :

Example 51 with NamedParameterJdbcTemplate

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

Example 52 with NamedParameterJdbcTemplate

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

Example 53 with NamedParameterJdbcTemplate

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

Example 54 with NamedParameterJdbcTemplate

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

Example 55 with NamedParameterJdbcTemplate

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());
}
Also used : 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