?? customerhibernatedao.java
字號(hào):
/**
*
*/
package com.ascent.dao.hibernate;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.orm.hibernate.support.HibernateDaoSupport;
import com.ascent.bean.Customer;
import com.ascent.dao.ICustomerDAO;
public class CustomerHibernateDAO extends HibernateDaoSupport implements
ICustomerDAO {
private static final Logger LOGGER = LogManager
.getLogger(CustomerHibernateDAO.class);
private static final String LOAD_ALL = "from Customer cust order by cust.customer_id desc";
private static final String LOAD_BY_NAME = "from Customer cust where cust.cust_name = ? order by cust.customer_id desc";
/**
*
*/
public CustomerHibernateDAO() {
super();
}
/**
*
* @param Customer
* @return Customer
*/
public Customer saveCustomer(Customer customer) {
try {
this.getHibernateTemplate().save(customer);
LOGGER.debug("保存用戶信息到數(shù)據(jù)庫成功!");
return customer;
} catch (Exception ex) {
LOGGER.error("保存用戶信息到數(shù)據(jù)庫失敗!");
ex.printStackTrace();
return null;
}
}
/**
*
* @param id
* Integer
*
* @return Customer
*/
public Customer getCustomer(Integer id) {
LOGGER.debug("根據(jù)用戶ID得到用戶信息!");
return (Customer) this.getHibernateTemplate().get(Customer.class, id);
}
/**
*
* @return List
*/
public List findCustomerAll() {
try {
LOGGER.debug("得到所有用戶列表!");
return this.getHibernateTemplate().find(LOAD_ALL);
} catch (Exception ex) {
LOGGER.error("獲取所有用戶列表失敗!");
return new ArrayList();
}
}
/**
*
* @param type
* String
*
* @return List
*/
public List findCustomerByName(String name) {
try {
LOGGER.debug("根據(jù)用戶姓名得到用戶信息!");
return this.getHibernateTemplate().find(LOAD_BY_NAME, name);
} catch (Exception ex) {
LOGGER.error("根據(jù)用戶姓名獲取用戶信息失敗!");
ex.printStackTrace();
return null;
}
}
public Customer updateCustomer(Customer customer) {
try {
this.getHibernateTemplate().update(customer);
LOGGER.debug("更新用戶信息到數(shù)據(jù)庫成功!");
return customer;
} catch (Exception ex) {
LOGGER.error("更新用戶信息到數(shù)據(jù)庫失敗!");
ex.printStackTrace();
return null;
}
}
/**
*
* @param Customer
*
*/
public void removeCustomer(Customer customer) {
LOGGER.debug("從數(shù)據(jù)庫中刪除指定用戶信息!");
this.getHibernateTemplate().delete(customer);
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -