else {
log.warn("No status available to save for run: " + run.getAlias());
}
try {
MapSqlParameterSource params = new MapSqlParameterSource();
params.addValue("accession", run.getAccession())
.addValue("alias", run.getAlias())
.addValue("description", run.getDescription())
.addValue("platformRunId", run.getPlatformRunId())
.addValue("pairedEnd", run.getPairedEnd())
.addValue("cycles", run.getCycles())
.addValue("filePath", run.getFilePath())
.addValue("platformType", run.getPlatformType().getKey())
.addValue("securityProfile_profileId", securityProfileId)
.addValue("status_statusId", statusId)
.addValue("sequencerReference_sequencerReferenceId", run.getSequencerReference().getId());
if (run.getId() == AbstractRun.UNSAVED_ID) {
SimpleJdbcInsert insert = new SimpleJdbcInsert(template)
.withTableName(TABLE_NAME)
.usingGeneratedKeyColumns("runId");
try {
run.setId(autoIncrement);
String name = namingScheme.generateNameFor("name", run);
run.setName(name);
if (namingScheme.validateField("name", run.getName())) {
params.addValue("name", name);
Number newId = insert.executeAndReturnKey(params);
if (newId.longValue() != run.getId()) {
log.error("Expected Run ID doesn't match returned value from database insert: rolling back...");
new NamedParameterJdbcTemplate(template).update(RUN_DELETE, new MapSqlParameterSource().addValue("runId", newId.longValue()));
throw new IOException("Something bad happened. Expected Run ID doesn't match returned value from DB insert");
}
autoIncrement = newId.longValue() + 1;
log.debug(run.getName() + ":: Inserted as ID " + run.getId());
}
else {
throw new IOException("Cannot save Run - invalid field:" + run.toString());
}
}
catch (MisoNamingException e) {
throw new IOException("Cannot save Run - issue with naming scheme", e);
}
/*
String name = "RUN" + autoIncrement;
params.addValue("name", name);
Number newId = insert.executeAndReturnKey(params);
run.setRunId(newId.longValue());
run.setName(name);
autoIncrement = newId.longValue() + 1;
log.debug(run.getName() + ":: Inserted as ID " + run.getRunId());
*/
}
else {
try {
if (namingScheme.validateField("name", run.getName())) {
params.addValue("runId", run.getId())
.addValue("name", run.getName());
log.debug(run.getName() + ":: Updating as ID " + run.getId());
batch.add(params);
}
else {
throw new IOException("Cannot save Run - invalid field:" + run.toString());
}
}
catch (MisoNamingException e) {
throw new IOException("Cannot save Run - issue with naming scheme", e);
}
/*
params.addValue("runId", run.getRunId())
.addValue("name", run.getName());
log.debug(run.getName() + ":: Updating as ID " + run.getRunId());
batch.add(params);
*/
}
if (this.cascadeType != null) {
if (this.cascadeType.equals(CascadeType.PERSIST)) {
for (SequencerPartitionContainer<SequencerPoolPartition> l : ((RunImpl)run).getSequencerPartitionContainers()) {
l.setSecurityProfile(run.getSecurityProfile());
if (l.getPlatformType() == null) {
l.setPlatformType(run.getPlatformType());
}
long containerId = sequencerPartitionContainerDAO.save(l);
SimpleJdbcInsert fInsert = new SimpleJdbcInsert(template).withTableName("Run_SequencerPartitionContainer");
MapSqlParameterSource fcParams = new MapSqlParameterSource();
fcParams.addValue("Run_runId", run.getId())
.addValue("containers_containerId", containerId);
try {
fInsert.execute(fcParams);
}