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;
}
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;
}
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();
}
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);
}
}
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;
}
Aggregations