package ma.library; import java.util.List; import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hibernate.LockMode; import org.hibernate.Query; import org.hibernate.criterion.Example; /** * Data access object (DAO) for domain model class Dept. * @see ma.library.Dept * @author MyEclipse - Hibernate Tools */ public class DeptDAO extends BaseHibernateDAO { private static final Log log = LogFactory.getLog(DeptDAO.class); //property constants public static final String LIBELLE = "libelle"; public void save(Dept transientInstance) { log.debug("saving Dept instance"); try { getSession().save(transientInstance); log.debug("save successful"); } catch (RuntimeException re) { log.error("save failed", re); throw re; } } public void delete(Dept persistentInstance) { log.debug("deleting Dept instance"); try { getSession().delete(persistentInstance); log.debug("delete successful"); } catch (RuntimeException re) { log.error("delete failed", re); throw re; } } public Dept findById( java.lang.Integer id) { log.debug("getting Dept instance with id: " + id); try { Dept instance = (Dept) getSession() .get("ma.library.Dept", id); return instance; } catch (RuntimeException re) { log.error("get failed", re); throw re; } } public List findByExample(Dept instance) { log.debug("finding Dept instance by example"); try { List results = getSession() .createCriteria("ma.library.Dept") .add(Example.create(instance)) .list(); log.debug("find by example successful, result size: " + results.size()); return results; } catch (RuntimeException re) { log.error("find by example failed", re); throw re; } } public List findByProperty(String propertyName, Object value) { log.debug("finding Dept instance with property: " + propertyName + ", value: " + value); try { String queryString = "from Dept as model where model." + propertyName + "= ?"; Query queryObject = getSession().createQuery(queryString); queryObject.setParameter(0, value); return queryObject.list(); } catch (RuntimeException re) { log.error("find by property name failed", re); throw re; } } public List findByLibelle(Object libelle) { return findByProperty(LIBELLE, libelle); } public Dept merge(Dept detachedInstance) { log.debug("merging Dept instance"); try { Dept result = (Dept) getSession() .merge(detachedInstance); log.debug("merge successful"); return result; } catch (RuntimeException re) { log.error("merge failed", re); throw re; } } public void attachDirty(Dept instance) { log.debug("attaching dirty Dept instance"); try { getSession().saveOrUpdate(instance); log.debug("attach successful"); } catch (RuntimeException re) { log.error("attach failed", re); throw re; } } public void attachClean(Dept instance) { log.debug("attaching clean Dept instance"); try { getSession().lock(instance, LockMode.NONE); log.debug("attach successful"); } catch (RuntimeException re) { log.error("attach failed", re); throw re; } } }