params.addValue("identificationBarcode", barcode);
Number newId = insert.executeAndReturnKey(params);
if (newId.longValue() != plate.getId()) {
log.error("Expected Plate ID doesn't match returned value from database insert: rolling back...");
new NamedParameterJdbcTemplate(template).update(PLATE_DELETE, new MapSqlParameterSource().addValue("plateId", newId.longValue()));
throw new IOException("Something bad happened. Expected Plate ID doesn't match returned value from DB insert");
}
}
else {
throw new IOException("Cannot save Plate - invalid field:" + plate.toString());
}
}
catch (MisoNamingException e) {
throw new IOException("Cannot save Plate - issue with naming scheme", e);
}
/*
String name = "PLA"+ DbUtils.getAutoIncrement(template, TABLE_NAME);
params.addValue("name", name);
params.addValue("identificationBarcode", name + "::" + plate.getTagBarcode());
Number newId = insert.executeAndReturnKey(params);
plate.setPlateId(newId.longValue());
plate.setName(name);
*/
}
else {
try {
String plateBarcode = "";
if (plate.getTagBarcode() != null) {
plateBarcode = plate.getName() + "::" + plate.getTagBarcode();
}
else {
//TODO this should be alias
plateBarcode = plate.getName() + "::" + plate.getDescription();
}
if (namingScheme.validateField("name", plate.getName())) {
params.addValue("plateId", plate.getId())
.addValue("name", plate.getName())
.addValue("identificationBarcode", plateBarcode);
NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
namedTemplate.update(PLATE_UPDATE, params);
}
else {
throw new IOException("Cannot save Plate - invalid field:" + plate.toString());
}
}
catch (MisoNamingException e) {
throw new IOException("Cannot save Plate - issue with naming scheme", e);
}
/*
params.addValue("plateId", plate.getPlateId());
params.addValue("name", plate.getName());
params.addValue("identificationBarcode", plate.getName() + "::" + plate.getTagBarcode());
NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
namedTemplate.update(PLATE_UPDATE, params);
*/
}
if (this.cascadeType != null && this.cascadeType.equals(CascadeType.PERSIST)) {
if (!plate.getElements().isEmpty()) {
String eType = plate.getElementType().getName();
MapSqlParameterSource eparams = new MapSqlParameterSource();
eparams.addValue("plate_plateId", plate.getId());
NamedParameterJdbcTemplate nt = new NamedParameterJdbcTemplate(template);
nt.update(PLATE_ELEMENT_DELETE_BY_PLATE_ID, eparams);
SimpleJdbcInsert eInsert = new SimpleJdbcInsert(template)
.withTableName("Plate_Elements");
int pos = 1;