?? .#paymentdaohibernate.java.1.5
字號:
package com.longtime.wap.module.front.dao.hibernate;
import java.sql.SQLException;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import com.longtime.wap.common.BaseDao;
import com.longtime.wap.common.web.Page;
import com.longtime.wap.model.Payment;
import com.longtime.wap.module.front.dao.PaymentDao;
/**
* PaymentDao層代碼實現(xiàn)
*
* @author bulc
* @date Nov 23, 2007
*/
public class PaymentDaoHibernate extends BaseDao implements PaymentDao {
/**
* 列表顯示用戶的消費記錄
*
* @param userId
* 用戶編號
* @param infoId
* 信息編號
* @return 用戶的消費記錄列表
*/
public List retrievePaymentByUserIdAndInfoId(final Long userId,
final Long infoId) {
return this.getHibernateTemplate().executeFind(new HibernateCallback() {
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
Query query = session.createQuery(
"from Payment where userId=? and informationId=?");
query.setLong(0, userId);
query.setLong(1, infoId);
return query.list();
}
});
}
/**
* 列表分頁顯示用戶的消費記錄
*
* @param userId
* 用戶編號
* @param page
* 分頁
* @return 用戶消費記錄列表
*/
public List retrievePaymentByUserId(final Long userId, final Page page) {
return this.getHibernateTemplate().executeFind(new HibernateCallback() {
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
Query query = session
.createQuery("from Payment payment " +
"where payment.userId=? ");
query.setLong(0, userId);
return query.setFirstResult(page.getFirstResult())
.setMaxResults(page.getPageSize()).list();
}
});
}
/**
* 保存用戶消費信息
*
* @param payment
* 消費對象
*/
public void savePayment(Payment payment) {
this.getHibernateTemplate().saveOrUpdate(payment);
}
/**
* 統(tǒng)計消費記錄信息數(shù)
*
* @param userId
* 用戶編號
* @return 消費記錄信息數(shù)
*/
public int retrievePaymentCountByUserId(final Long userId) {
return (Integer) getHibernateTemplate().execute(
new HibernateCallback() {
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
Query query = session
.createQuery("select count(*) from Payment "
+ "where userId=?");
query.setLong(0, userId);
return query.uniqueResult();
}
});
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -