final String shead = section.getShortHeading();
final String heading = section.getHeading();
final int sequence = section.getSectionSequence();
final String headingText = section.getTextHeading();
KeyHolder keyHolder = new GeneratedKeyHolder();
this.getJdbcTemplate().update(new PreparedStatementCreator() {
public PreparedStatement createPreparedStatement(
Connection connection) throws SQLException {
PreparedStatement ps = connection.prepareStatement(
SQL_CREATE_SECTION, new String[] { "id" });
if (parentId == null) {
ps.setNull(1, java.sql.Types.INTEGER);
} else {
ps.setInt(1, parentId);
}
if (codeId == null) {
ps.setNull(2, java.sql.Types.INTEGER);
} else {
ps.setInt(2, codeId);
}
ps.setString(3, heading);
ps.setString(4, shead);
ps.setString(5, ref);
ps.setInt(6, sequence);
ps.setString(7, leveltype);
ps.setString(8, levelpos);
ps.setString(9, headingText);
return ps;
}
}, keyHolder);
int newID = keyHolder.getKey().intValue();
section.setId(newID);
return newID;
} catch (DataIntegrityViolationException e) {
System.out.println("Could not create section: "
+ e.getLocalizedMessage());