Search in sources :

Example 76 with NamedParameterJdbcTemplate

use of org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate in project nextprot-api by calipho-sib.

the class UserQueryDaoImpl method createUserQuery.

@Override
public long createUserQuery(final UserQuery userQuery) {
    final String INSERT_SQL = sqlDictionary.getSQLQuery("create-user-query");
    MapSqlParameterSource namedParameters = new MapSqlParameterSource();
    namedParameters.addValue("title", userQuery.getTitle());
    namedParameters.addValue("description", userQuery.getDescription());
    namedParameters.addValue("sparql", userQuery.getSparql());
    namedParameters.addValue("published", userQuery.getPublished() ? 'Y' : 'N');
    namedParameters.addValue("owner_id", userQuery.getOwnerId());
    namedParameters.addValue("public_id", userQuery.getPublicId());
    return JdbcUtils.insertAndGetKey(INSERT_SQL, "query_id", namedParameters, new NamedParameterJdbcTemplate(dsLocator.getUserDataSource())).longValue();
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)

Example 77 with NamedParameterJdbcTemplate

use of org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate in project nextprot-api by calipho-sib.

the class DiffBaseTest method getCountForSql.

private int getCountForSql() {
    long t0 = System.currentTimeMillis();
    String sql = sqlDictionary.getSQLQuery(qName);
    // SqlParameterSource namedParams = new MapSqlParameterSource("id", id);
    SqlParameterSource namedParams = null;
    List<Integer> counts = new NamedParameterJdbcTemplate(dsLocator.getDataSource()).query(sql, namedParams, new RowMapper<Integer>() {

        @Override
        public Integer mapRow(ResultSet resultSet, int row) throws SQLException {
            return new Integer(resultSet.getInt("cnt"));
        }
    });
    timeSQL = (int) (System.currentTimeMillis() - t0);
    countSQL = counts.get(0);
    return countSQL;
}
Also used : SqlParameterSource(org.springframework.jdbc.core.namedparam.SqlParameterSource) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) SparqlEndpoint(org.nextprot.api.rdf.service.SparqlEndpoint)

Example 78 with NamedParameterJdbcTemplate

use of org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate in project nextprot-api by calipho-sib.

the class UserApplicationDaoImpl method updateUserApplication.

@Override
public void updateUserApplication(final UserApplication src) {
    final String UPDATE_SQL = sqlDictionary.getSQLQuery("update-user-application");
    MapSqlParameterSource namedParameters = new MapSqlParameterSource();
    // key to identify application to be updated
    namedParameters.addValue("application_id", src.getId());
    // values to update
    namedParameters.addValue("application_name", src.getName());
    namedParameters.addValue("description", src.getDescription());
    namedParameters.addValue("organisation", src.getOrganisation());
    namedParameters.addValue("responsible_name", src.getResponsibleName());
    namedParameters.addValue("responsible_email", src.getResponsibleEmail());
    namedParameters.addValue("website", src.getWebsite());
    namedParameters.addValue("token", src.getToken());
    namedParameters.addValue("status", src.getStatus());
    namedParameters.addValue("user_data_access", src.getUserDataAccess());
    namedParameters.addValue("origins", src.getOrigins());
    NamedParameterJdbcTemplate jdbcTemplate = new NamedParameterJdbcTemplate(dsLocator.getUserDataSource());
    int affectedRows = jdbcTemplate.update(UPDATE_SQL, namedParameters);
    if (affectedRows != 1) {
        String msg = "something wrong occurred: " + affectedRows + " rows were affected (expected=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)

Example 79 with NamedParameterJdbcTemplate

use of org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate in project nextprot-api by calipho-sib.

the class UserApplicationDaoImpl method getUserApplicationById.

@Override
public UserApplication getUserApplicationById(long id) throws DataAccessException {
    MapSqlParameterSource namedParameters = new MapSqlParameterSource();
    namedParameters.addValue("application_id", id);
    String sql = sqlDictionary.getSQLQuery("read-user-application-by-id");
    return new NamedParameterJdbcTemplate(dsLocator.getUserDataSource()).queryForObject(sql, namedParameters, new UserApplicationRowMapper());
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)

Example 80 with NamedParameterJdbcTemplate

use of org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate in project nextprot-api by calipho-sib.

the class UserApplicationDaoImpl method getUserApplicationListByOwnerId.

@Override
public List<UserApplication> getUserApplicationListByOwnerId(long userId) {
    MapSqlParameterSource namedParameters = new MapSqlParameterSource();
    namedParameters.addValue("owner_id", userId);
    return new NamedParameterJdbcTemplate(dsLocator.getUserDataSource()).query(sqlDictionary.getSQLQuery("read-user-applications-by-owner-id"), namedParameters, new UserApplicationRowMapper());
}
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