HibernateDaoSupport

package com.dao.impl;

import java.sql.SQLException;
import java.util.List;






import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.dao.LabDao;
import com.model.Lab;












public class LabDaoImpl extends HibernateDaoSupport implements  LabDao{


	public void deleteBean(Lab bean) {
		this.getHibernateTemplate().delete(bean);
		
	}

	public void insertBean(Lab bean) {
		this.getHibernateTemplate().save(bean);
		
	}

	@SuppressWarnings("unchecked")
	public Lab selectBean(String where) {
		List list = this.getHibernateTemplate().find("from Lab " +where);
		if(list.size()==0){
			return null;
		}
		return list.get(0);
	}

	public int selectBeanCount(String where) {
		long count = (Long)this.getHibernateTemplate().find("select count(*) from Lab "+where).get(0);
		return (int)count;
	}

	@SuppressWarnings("unchecked")
	public List selectBeanList(final int start,final int limit,final String where) {
		return (List)this.getHibernateTemplate().executeFind(new HibernateCallback() {
			public Object doInHibernate(final Session session)throws HibernateException, SQLException {				
				List list = session.createQuery("from Lab "+where)
				.setFirstResult(start)
				.setMaxResults(limit)
				.list();
				return list;
			}
		});
	}

	public void updateBean(Lab bean) {
		this.getHibernateTemplate().update(bean);
		
	}

	@SuppressWarnings("unchecked")
	public List selectStuLab() {
		List list = this.getHibernateTemplate().find("from Lab where deletestatus=0 and fenlei='学生钢琴房'");
		return list;
	}


	@SuppressWarnings("unchecked")
	public List selectTeaLab() {
		List list = this.getHibernateTemplate().find("from Lab where  deletestatus=0 and fenlei='教师钢琴房'");
		return list;
	
	}
	
	
}

 

你可能感兴趣的:(hibernate)