首页>代码>SSH架构搭建OA管理系统>/OA项目/学士后三单元项目/src/com/pb/base/impl/BaseDaoImpl.java
package com.pb.base.impl;

import java.lang.reflect.ParameterizedType;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.pb.base.dao.IBaseDao;
import com.pb.entity.Users;

public class BaseDaoImpl<T> extends HibernateDaoSupport implements IBaseDao<T> {
	private Log log = LogFactory.getLog(this.getClass());
	private SessionFactory sessionFactory;
	@SuppressWarnings("unchecked")
	public BaseDaoImpl() {
	}

	public void delete(T instances) {

	}

	public List<T> findAll() {
		return null;
	}

	@SuppressWarnings("unchecked")//返回数据库中对应该业务对象的所有记录的集合
	public List<Object> findAll(Class clazz) throws Exception {
		try {
			return getHibernateTemplate().loadAll(clazz);
		} catch (Exception e) {
			 throw new Exception("加载所有 " + clazz.getName() + " 实例时失败", e);    
		}
		
	}

	public List findByHql(String hql) {

		return null;
	}

	public Object findById(Class clazz, Integer id) {
		return null;
	}

	@SuppressWarnings("unchecked")
	public List<T> findByProperty(String className, String propertyName,
			Object value) {
		log.debug("finding " + className + " instance with property: "
				+ propertyName + ", value: " + value);
		

		try {
			String hql = "FROM " + className + " as o WHERE o." + propertyName
					+ " = " + "'" + value + "'";

			System.out.println(hql);

			 List list= super.getHibernateTemplate().find(hql);
			
			 return list;
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}


	@SuppressWarnings("unchecked")
	public List<Users> queryUserList() {
		log.debug("finding Users");

		try {
			String hql = "FROM Users";
			return super.getHibernateTemplate().find(hql);

		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}

	}
}
最近下载更多
qfch120  LV8 2023年3月28日
tlskmhorse  LV1 2022年5月13日
szy0077  LV4 2022年4月27日
mynewcode  LV5 2022年2月9日
xiezhif  LV2 2021年3月18日
王力创  LV2 2020年10月20日
1196027766  LV1 2020年4月8日
maruisi  LV2 2020年3月10日
915381  LV1 2020年2月8日
19970207  LV1 2020年1月2日
最近浏览更多
jay1992  LV14 3月16日
WBelong  LV7 2023年12月26日
政政123456  LV3 2023年10月22日
molu123456 2023年10月16日
暂无贡献等级
sunhao111111  LV2 2023年8月15日
zhy1989wz  LV6 2023年7月3日
zhaoka 2023年5月30日
暂无贡献等级
lvdong2023  LV10 2023年5月18日
xiongfan  LV6 2023年4月24日
2716804680  LV8 2023年3月20日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友