⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 .#paymentdaohibernate.java.1.5

📁 这个是完整的wap项目的源码 开发语言 Java 系统架构 Struts + hibernate + spring 数据库 Mysql5.0 应用服务器Tomcat5.0 开发工具 MyEc
💻 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层代码实现
 * 
 * @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);
	}

	/**
	 * 统计消费记录信息数
	 * 
	 * @param userId
	 * 			用户编号
	 * @return 消费记录信息数
	 */
	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 + -