@Transactional
@Override
public void create(final TaxRate taxRate) {
KeyHolder keyHolder = new GeneratedKeyHolder();
getJdbcOperations().update(new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection con)
throws SQLException {
String sql = "INSERT INTO "+quoteTable("tax_rate")+"(name, rate, type, geo_zone_id, date_added, date_modified) VALUES(?,?,?,?,?,?)";
PreparedStatement ps = con.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
ps.setString(1, taxRate.getName());
ps.setBigDecimal(2, taxRate.getRate());
ps.setString(3, taxRate.getType());
ps.setInt(4, taxRate.getGeoZoneId());
Timestamp timestamp = new Timestamp(new Date().getTime());
ps.setTimestamp(5, timestamp);
ps.setTimestamp(6, timestamp);
return ps;
}
}, keyHolder);
int taxRateId = keyHolder.getKey().intValue();
addCustomerGroupIds(taxRateId, taxRate.getCustomerGroupIds());
}