params.addValue("name", name);
Number newId = insert.executeAndReturnKey(params);
if (newId.longValue() != study.getId()) {
log.error("Expected Study ID doesn't match returned value from database insert: rolling back...");
new NamedParameterJdbcTemplate(template).update(STUDY_DELETE, new MapSqlParameterSource().addValue("studyId", newId.longValue()));
throw new IOException("Something bad happened. Expected Study ID doesn't match returned value from DB insert");
}
}
else {
throw new IOException("Cannot save Study - invalid field:" + study.toString());
}
}
catch (MisoNamingException e) {
throw new IOException("Cannot save Study - issue with naming scheme", e);
}
/*
String name = "STU"+ DbUtils.getAutoIncrement(template, TABLE_NAME);
params.addValue("name", name);
Number newId = insert.executeAndReturnKey(params);
study.setStudyId(newId.longValue());
study.setName(name);
*/
Project p = study.getProject();
SimpleJdbcInsert pInsert = new SimpleJdbcInsert(template)
.withTableName("Project_Study");
MapSqlParameterSource poParams = new MapSqlParameterSource();
poParams.addValue("Project_projectId", p.getProjectId())
.addValue("studies_studyId", study.getId());
try {
pInsert.execute(poParams);
}
catch(DuplicateKeyException dke) {
//ignore
}
}
else {
try {
if (namingScheme.validateField("name", study.getName())) {
params.addValue("studyId", study.getId())
.addValue("name", study.getName());
NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
namedTemplate.update(STUDY_UPDATE, params);
}
else {
throw new IOException("Cannot save Study - invalid field:" + study.toString());
}
}