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