params.addValue("name", name);
Number newId = insert.executeAndReturnKey(params);
if (newId.longValue() != project.getId()) {
log.error("Expected Project ID ('"+project.getId()+"') doesn't match returned value ('"+newId.longValue()+"') from database insert: rolling back...");
new NamedParameterJdbcTemplate(template).update(PROJECT_DELETE, new MapSqlParameterSource().addValue("projectId", newId.longValue()));
throw new IOException("Something bad happened. Expected Project ID doesn't match returned value from DB insert");
}
}
else {
throw new IOException("Cannot save Project - invalid field:" + project.toString());
}
}
catch (MisoNamingException e) {
throw new IOException("Cannot save Project - issue with naming scheme", e);
}
/*
String name = "PRO" + DbUtils.getAutoIncrement(template, TABLE_NAME);
params.addValue("name", name);
Number newId = insert.executeAndReturnKey(params);
project.setProjectId(newId.longValue());
project.setName(name);
*/
}
else {
try {
if (namingScheme.validateField("name", project.getName())) {
params.addValue("projectId", project.getId())
.addValue("name", project.getName());
NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
namedTemplate.update(PROJECT_UPDATE, params);
}
else {
throw new IOException("Cannot save Project - invalid field:" + project.toString());
}
}
catch (MisoNamingException e) {
throw new IOException("Cannot save Project - issue with naming scheme", e);
}
/*
params.addValue("projectId", project.getProjectId());
params.addValue("name", project.getName());
NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
namedTemplate.update(PROJECT_UPDATE, params);
*/
}
if (this.cascadeType != null) {
if (this.cascadeType.equals(CascadeType.PERSIST)) {
MapSqlParameterSource eParams = new MapSqlParameterSource();
eParams.addValue("project_projectId", project.getProjectId());
NamedParameterJdbcTemplate eNamedTemplate = new NamedParameterJdbcTemplate(template);
eNamedTemplate.update(PROJECT_ISSUES_DELETE_BY_PROJECT_ID, eParams);
if (project.getIssueKeys() != null && !project.getIssueKeys().isEmpty()) {
for (String s : project.getIssueKeys()) {
SimpleJdbcInsert fInsert = new SimpleJdbcInsert(template).withTableName("Project_Issues");
MapSqlParameterSource fcParams = new MapSqlParameterSource();