www.pudn.com > Desktop.rar > TeacherDAO.java, change:2012-12-27,size:5583b


package dao;

import java.util.List; 
import java.util.Set; 

import models.Teacher;

import org.hibernate.LockMode; 
import org.slf4j.Logger; 
import org.slf4j.LoggerFactory; 
import org.springframework.context.ApplicationContext; 
import org.springframework.orm.hibernate3.support.HibernateDaoSupport; 

/**
 	* A data access object (DAO) providing persistence and search support for Teacher entities.
 			* Transaction control of the save(), update() and delete() operations 
		can directly support Spring container-managed transactions or they can be augmented	to handle user-managed Spring transactions. 
		Each of these methods provides additional information for how to configure it for the desired type of transaction control. 	
	 * @see models.Teacher
  * @author MyEclipse Persistence Tools 
 */

public class TeacherDAO extends HibernateDaoSupport implements ITeacherDAO  {
	     private static final Logger log = LoggerFactory.getLogger(TeacherDAO.class);
		protected void initDao() {
		//do nothing
	}
    
    /* (non-Javadoc)
	 * @see dao.ITeacherDAO#save(models.Teacher)
	 */
    public void save(Teacher transientInstance) {
        log.debug("saving Teacher instance");
        try {
            getHibernateTemplate().save(transientInstance);
            log.debug("save successful");
        } catch (RuntimeException re) {
            log.error("save failed", re);
            throw re;
        }
    }
    
	/* (non-Javadoc)
	 * @see dao.ITeacherDAO#delete(models.Teacher)
	 */
	public void delete(Teacher persistentInstance) {
        log.debug("deleting Teacher instance");
        try {
            getHibernateTemplate().delete(persistentInstance);
            log.debug("delete successful");
        } catch (RuntimeException re) {
            log.error("delete failed", re);
            throw re;
        }
    }
    
    /* (non-Javadoc)
	 * @see dao.ITeacherDAO#findById(java.lang.Integer)
	 */
    public Teacher findById( java.lang.Integer id) {
        log.debug("getting Teacher instance with id: " + id);
        try {
            Teacher instance = (Teacher) getHibernateTemplate()
                    .get("models.Teacher", id);
            return instance;
        } catch (RuntimeException re) {
            log.error("get failed", re);
            throw re;
        }
    }
    
    
    /* (non-Javadoc)
	 * @see dao.ITeacherDAO#findByExample(models.Teacher)
	 */
    public List findByExample(Teacher instance) {
        log.debug("finding Teacher instance by example");
        try {
            List results = getHibernateTemplate().findByExample(instance);
            log.debug("find by example successful, result size: " + results.size());
            return results;
        } catch (RuntimeException re) {
            log.error("find by example failed", re);
            throw re;
        }
    }    
    
    /* (non-Javadoc)
	 * @see dao.ITeacherDAO#findByProperty(java.lang.String, java.lang.Object)
	 */
    public List findByProperty(String propertyName, Object value) {
      log.debug("finding Teacher instance with property: " + propertyName
            + ", value: " + value);
      try {
         String queryString = "from Teacher as model where model." 
         						+ propertyName + "= ?";
		 return getHibernateTemplate().find(queryString, value);
      } catch (RuntimeException re) {
         log.error("find by property name failed", re);
         throw re;
      }
	}

	/* (non-Javadoc)
	 * @see dao.ITeacherDAO#findByTName(java.lang.Object)
	 */
	public List findByTName(Object TName
	) {
		return findByProperty(_TNAME, TName
		);
	}
	
	/* (non-Javadoc)
	 * @see dao.ITeacherDAO#findByTPhone(java.lang.Object)
	 */
	public List findByTPhone(Object TPhone
	) {
		return findByProperty(_TPHONE, TPhone
		);
	}
	

	/* (non-Javadoc)
	 * @see dao.ITeacherDAO#findAll()
	 */
	public List findAll() {
		log.debug("finding all Teacher instances");
		try {
			String queryString = "from Teacher";
		 	return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}
	
    /* (non-Javadoc)
	 * @see dao.ITeacherDAO#merge(models.Teacher)
	 */
    public Teacher merge(Teacher detachedInstance) {
        log.debug("merging Teacher instance");
        try {
            Teacher result = (Teacher) getHibernateTemplate()
                    .merge(detachedInstance);
            log.debug("merge successful");
            return result;
        } catch (RuntimeException re) {
            log.error("merge failed", re);
            throw re;
        }
    }

    /* (non-Javadoc)
	 * @see dao.ITeacherDAO#attachDirty(models.Teacher)
	 */
    public void attachDirty(Teacher instance) {
        log.debug("attaching dirty Teacher instance");
        try {
            getHibernateTemplate().saveOrUpdate(instance);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }
    
    /* (non-Javadoc)
	 * @see dao.ITeacherDAO#attachClean(models.Teacher)
	 */
    public void attachClean(Teacher instance) {
        log.debug("attaching clean Teacher instance");
        try {
            getHibernateTemplate().lock(instance, LockMode.NONE);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }

	public static ITeacherDAO getFromApplicationContext(ApplicationContext ctx) {
    	return (ITeacherDAO) ctx.getBean("TeacherDAO");
	}
}