publicclassCustomerDaoImplextendsJdbcDaoSupportimplementsCustomerDAO {privateDataSource dataSource;
pirvate TransactionManager transactionManager;publicvoidsetDataSource(DataSource dataSource) {this.dataSource=dataSource;
}publicvoidsetTransactionManager(DataSourceTransactionManager transactionManager) {this.transactionManager=transactionManager;
}publicMap get(Integer id)throwsException {
String querySql="select * from customer where id = ?";returngetJdbcTemplate().queryForMap(querySql,newObject[] { id });
}publicvoidinsert(finalMap customer)throwsException {
String seqSql="select customer_seql.nextval from dual";
String insertSql="insert into customer (id, code, name, status) values (?, ?, ?, ?)";
TransactionTemplate transactionTemplate=newTransactionTemplate(transactionManager);
transactionTemplate.execute(newTransactionCallbackWithoutResult() {protectedvoiddoInTransactionWithoutResult(TransactionStatus status) {
JdbcTemplate jdbcTemplate=getJdbcTemplate();intid=jdbcTemplate.queryForInt(seqSql);
Object[] params=newObject[] {newInteger(id), customer.get("code"), customer.get("name"), map.get("status") };
jdbcTemplate.update(insertSql, params);
}
}
}publicvoidupdate(finalMap customer)throwsException {//}publicvoiddelete(Integer id)throwsException {
String deleteSql="delete from customer where id = ?";
TransactionTemplate transactionTemplate=newTransactionTemplate(transactionManager);
transactionTemplate.execute(newTransactionCallbackWithoutResult() {protectedvoiddoInTransactionWithoutResult(TransactionStatus status) {
getJdbcTemplate().update(deleteSql,newObject[] { id });
}
}
}publicList findValidCustomers()throwsException {
String querySql="select * from customer where status = 'valid' order by code";returngetJdbcTemplate().query(querySql,newOracleColumnMapRowMapper());
}
}