Search in sources :

Example 41 with NamedParameterJdbcTemplate

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

the class SchemaDaoImpl method findAllOntology.

@Override
public List<OWLOntology> findAllOntology() {
    SqlParameterSource params = new MapSqlParameterSource();
    List<OWLOntology> ontologies = new NamedParameterJdbcTemplate(dsLocator.getDataSource()).query(sqlDictionary.getSQLQuery("schema-ontology-list"), params, new ParameterizedRowMapper<OWLOntology>() {

        @Override
        public OWLOntology mapRow(ResultSet resultSet, int row) throws SQLException {
            OWLOntology ontology = new OWLOntology();
            ontology.setOntology(resultSet.getString("ontology"));
            ontology.setDescription(resultSet.getString("description"));
            ontology.setName(resultSet.getString("name"));
            return ontology;
        }
    });
    return ontologies;
}
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) SQLException(java.sql.SQLException) OWLOntology(org.nextprot.api.rdf.domain.OWLOntology) ResultSet(java.sql.ResultSet)

Example 42 with NamedParameterJdbcTemplate

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

the class SchemaDaoImpl method findAllAnnotation.

@Override
public List<OWLAnnotation> findAllAnnotation() {
    // get description for annotations that exist in db
    AnnotationCategory[] cats = AnnotationCategory.values();
    List<Long> typeIds = new ArrayList<Long>();
    for (AnnotationCategory cat : cats) typeIds.add(new Long(cat.getDbId()));
    SqlParameterSource params = new MapSqlParameterSource("typeIds", typeIds);
    List<NameDescr> nds = new NamedParameterJdbcTemplate(dsLocator.getDataSource()).query(sqlDictionary.getSQLQuery("schema-instantiated-annotation-list"), params, new ParameterizedRowMapper<NameDescr>() {

        @Override
        public NameDescr mapRow(ResultSet rs, int row) throws SQLException {
            NameDescr nd = new NameDescr(rs.getString("cv_name"), rs.getString("description"));
            // System.out.println("rs.cv_name=" + nd.name + " description="+ nd.descr);
            return nd;
        }
    });
    // inject descriptions found in db into the OWLAnnotationCategory enum values
    for (NameDescr nd : nds) {
        AnnotationCategory m = AnnotationCategory.getByDbAnnotationTypeName(nd.name);
        // System.out.println("before descr: " + m.toString());
        m.setDescription(nd.descr);
    // System.out.println("after descr: " + m.toString());
    // AnnotationCategory.getByDbAnnotationTypeName(nd.name).setDescription(nd.descr);
    }
    // encapsulate OWLAnnotationCategory into OWLAnnotation to be compatible with the rest
    List<OWLAnnotation> annotations = new ArrayList<OWLAnnotation>();
    for (AnnotationCategory cat : AnnotationCategory.values()) {
        annotations.add(new OWLAnnotation(cat));
    }
    return annotations;
}
Also used : NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) SQLException(java.sql.SQLException) OWLAnnotation(org.nextprot.api.rdf.domain.OWLAnnotation) ArrayList(java.util.ArrayList) AnnotationCategory(org.nextprot.api.commons.constants.AnnotationCategory) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) SqlParameterSource(org.springframework.jdbc.core.namedparam.SqlParameterSource) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) ResultSet(java.sql.ResultSet)

Example 43 with NamedParameterJdbcTemplate

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

the class UserApplicationDaoImpl method createUserApplication.

@Override
public long createUserApplication(final UserApplication userApplication) {
    final String INSERT_SQL = sqlDictionary.getSQLQuery("create-user-application");
    MapSqlParameterSource namedParameters = new MapSqlParameterSource();
    namedParameters.addValue("application_name", userApplication.getName());
    namedParameters.addValue("description", userApplication.getDescription());
    namedParameters.addValue("organisation", userApplication.getOrganisation());
    namedParameters.addValue("responsible_name", userApplication.getResponsibleName());
    namedParameters.addValue("responsible_email", userApplication.getResponsibleEmail());
    namedParameters.addValue("website", userApplication.getWebsite());
    namedParameters.addValue("owner_id", userApplication.getOwnerId());
    namedParameters.addValue("token", userApplication.getToken());
    namedParameters.addValue("status", userApplication.getStatus());
    namedParameters.addValue("user_data_access", userApplication.getUserDataAccess());
    namedParameters.addValue("origins", userApplication.getOrigins());
    NamedParameterJdbcTemplate jdbcTemplate = new NamedParameterJdbcTemplate(dsLocator.getUserDataSource());
    KeyHolder keyHolder = new GeneratedKeyHolder();
    jdbcTemplate.update(INSERT_SQL, namedParameters, keyHolder, new String[] { "application_id" });
    return keyHolder.getKey().longValue();
}
Also used : GeneratedKeyHolder(org.springframework.jdbc.support.GeneratedKeyHolder) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) KeyHolder(org.springframework.jdbc.support.KeyHolder) GeneratedKeyHolder(org.springframework.jdbc.support.GeneratedKeyHolder)

Example 44 with NamedParameterJdbcTemplate

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

the class UserApplicationDaoImpl method deleteUserApplication.

@Override
public void deleteUserApplication(final UserApplication userApplication) {
    final String DELETE_SQL = sqlDictionary.getSQLQuery("delete-user-application");
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("application_id", userApplication.getId());
    int affectedRows = new NamedParameterJdbcTemplate(dsLocator.getUserDataSource()).update(DELETE_SQL, params);
    if (affectedRows != 1) {
        String msg = "oops something wrong occured" + affectedRows + " rows were affected instead of only 1.";
        Logger.error(msg);
        throw new NextProtException(msg);
    }
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) HashMap(java.util.HashMap) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)

Example 45 with NamedParameterJdbcTemplate

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

the class UserProteinListDaoImpl method getUserProteinListByName.

@Override
public UserProteinList getUserProteinListByName(String userIdentifier, String listName) throws DataAccessException {
    String sql = sqlDictionary.getSQLQuery("read-user-protein-list-by-username-listname");
    Map<String, String> namedParams = new HashMap<String, String>();
    namedParams.put("user_name", userIdentifier);
    namedParams.put("list_name", listName);
    UserProteinList userProteinList = new NamedParameterJdbcTemplate(dsLocator.getUserDataSource()).queryForObject(sql, namedParams, new ProteinListRowMapper());
    userProteinList.setAccessions(getAccessionsByListId(userProteinList.getId()));
    return userProteinList;
}
Also used : NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) UserProteinList(org.nextprot.api.user.domain.UserProteinList)

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