.#businessdaohibernate.java.1.6

来自「这个是完整的wap项目的源码 开发语言 Java 系统架构 Struts +」· 6 代码 · 共 60 行

6
60
字号
package com.longtime.wap.module.information.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.model.Business;
import com.longtime.wap.module.information.dao.BusinessDao;

/**
 * 定义对business的持久化类进行操作的接口
 * 
 * @author Bulc
 * @date Nov 19, 2007
 */
public class BusinessDaoHibernate extends BaseDao implements BusinessDao {
	
	/**
	 * 根据信息发布商id,查询业务列表
	 * 
	 * @param cpId
	 *            信息发布商id
	 * @return 查询业务列表
	 */
	public List getBusinesses(final Long cpId) {
		return this.getHibernateTemplate().executeFind(new HibernateCallback() {
			public Object doInHibernate(Session session)
					throws HibernateException, SQLException {
				StringBuilder hql = new StringBuilder();
				hql.append("from Business business");
				if (null != cpId) {
					hql.append(" where business.cp.cpId=? order by business.businessId asc");
				}
				Query query = session.createQuery(hql.toString());
				if (null != cpId) {
					query.setLong(0, cpId);
				}
				return query.list();
			}
		});
	}

	/**
	 * 根据业务id,查询业务
	 * 
	 * @param id
	 *            业务id
	 * @return 业务对象
	 */
	public Business getBusinessById(Long id) {
		return (Business) this.getHibernateTemplate().get(Business.class, id);
	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?