new BeanPropertyRowMapper<SingleRowEntity>(SingleRowEntity.class));
}
public SingleRowEntity salvar(final SingleRowEntity entity) {
if (entity.getId() == null) {
KeyHolder keyHolder = new GeneratedKeyHolder();
getJdbcTemplate().update(new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection cnctn) throws SQLException {
PreparedStatement ps = cnctn.prepareStatement(
"insert into SingleRowEntity (texto1, combo1, autocomplete, dateDate, dateTime) values (?, ?, ?, ?, ?)",
Statement.RETURN_GENERATED_KEYS);
ps.setString(1, entity.getTexto1());
ps.setString(2, entity.getCombo1());
if(entity.getAutocomplete() != null){
ps.setLong(3, entity.getAutocomplete());
}else{
ps.setNull(3, Types.INTEGER);
}
if(entity.getDateDate() != null){
ps.setDate(4, new Date(entity.getDateDate().getTime()));
}else{
ps.setNull(4, Types.DATE);
}
if(entity.getDateTime() != null){
ps.setTimestamp(5, new Timestamp(entity.getDateTime().getTime()));
}else{
ps.setNull(5, Types.TIMESTAMP);
}
return ps;
}
}, keyHolder);
entity.setId(keyHolder.getKey().longValue());
}else{
getJdbcTemplate().update("update SingleRowEntity set texto1 = ?, combo1 = ?, autocomplete = ?, dateDate = ?, dateTime = ? where id = ?",
entity.getTexto1(), entity.getCombo1(), entity.getAutocomplete(), entity.getDateDate(), entity.getDateTime(), entity.getId());
}