【Java开源代码栏目提醒】:网学会员为需要Java开源代码的朋友们搜集整理了CustomerDaoHibernate.java相关资料,希望对各位网友有所帮助!
package com.myad.dao.hibernate;
import java.util.List;
import org.springframework.orm.ObjectRetrievalFailureException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.myad.dao.CustomerDao;
import com.myad.model.Customer;
public class CustomerDaoHibernate extends HibernateDaoSupport implements CustomerDao {
/**
* @see com.myad.dao.CustomerDao#getCustomers(com.myad.model.Customer)
*/
public List getCustomers( Customer customer) {
return getHibernateTemplate().find("from Customer");
}
/**
* @see com.myad.dao.CustomerDao#getCustomer(String customerid)
*/
public Customer getCustomer( String customerid) {
Customer customer = (Customer) getHibernateTemplate().get(Customer.class, customerid);
if (customer == null) {
logger.warn("uh oh, customer with customerid '" + customerid + "' not found...");
throw new ObjectRetrievalFailureException(Customer.class, customerid);
}
return customer;
}
/**
* @see com.myad.dao.CustomerDao#saveCustomer(Customer customer)
*/
public void saveCustomer( Customer customer) {
getHibernateTemplate().saveOrUpdate(customer);
}
/**
* @see com.myad.dao.CustomerDao#removeCustomer(String customerid)
*/
public void removeCustomer( String customerid) {
getHibernateTemplate().delete(getCustomer(customerid));
}
}