params.addValue("identificationBarcode", barcode);
Number newId = insert.executeAndReturnKey(params);
if (newId.longValue() != dilution.getId()) {
log.error("Expected LibraryDilution ID doesn't match returned value from database insert: rolling back...");
new NamedParameterJdbcTemplate(template).update(LIBRARY_DILUTION_DELETE, new MapSqlParameterSource().addValue("dilutionId", newId.longValue()));
throw new IOException("Something bad happened. Expected LibraryDilution ID doesn't match returned value from DB insert");
}
}
else {
throw new IOException("Cannot save LibraryDilution - invalid field:" + dilution.toString());
}
}
catch (MisoNamingException e) {
throw new IOException("Cannot save LibraryDilution - issue with naming scheme", e);
}
/*
String name = "LDI"+ DbUtils.getAutoIncrement(template, "LibraryDilution");
params.addValue("name", name);
params.addValue("identificationBarcode", name + "::" + dilution.getLibrary().getAlias());
Number newId = insert.executeAndReturnKey(params);
dilution.setDilutionId(newId.longValue());
dilution.setName(name);
*/
}
else {
try {
if (namingScheme.validateField("name", dilution.getName())) {
params.addValue("dilutionId", dilution.getId())
.addValue("name", dilution.getName())
.addValue("identificationBarcode", dilution.getName() + "::" + dilution.getLibrary().getAlias());
NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
namedTemplate.update(LIBRARY_DILUTION_UPDATE, params);
}
else {
throw new IOException("Cannot save LibraryDilution - invalid field:" + dilution.toString());
}
}