Class GenericHibernateDAO<T,​PK extends Serializable>

  • Type Parameters:
    T - The type of the persistent entity.
    PK - The type of the primary key for the entity.
    All Implemented Interfaces:
    GenericDAO<T,​PK>
    Direct Known Subclasses:
    ArchiveFileDAO

    public class GenericHibernateDAO<T,​PK extends Serializable>
    extends Object
    implements GenericDAO<T,​PK>
    An implementation of Generic DAO which is specialised for hibernate object stores.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      PK create​(T o)
      Persist the newInstance object into database.
      void delete​(T o)
      Remove an object from persistent storage in the database.
      protected List<T> findByCriteria​(org.hibernate.criterion.Criterion... criterion)
      Use this inside subclasses as a convenience method to find objects matching a given criterion.
      protected org.hibernate.Session getSession()
      Return a session object for managing instances of this class.
      T read​(PK id)
      Retrieve an object that was previously persisted to the database using the indicated id as primary key.
      void update​(T o)
      Save changes made to a persistent object.
    • Constructor Detail

      • GenericHibernateDAO

        public GenericHibernateDAO​(Class<T> type)
        Constructor for the class.
        Parameters:
        type - the type of the persistent entity managed by this class.
    • Method Detail

      • create

        public PK create​(T o)
        Description copied from interface: GenericDAO
        Persist the newInstance object into database.
        Specified by:
        create in interface GenericDAO<T,​PK extends Serializable>
        Parameters:
        o - the object to persist.
        Returns:
        the key assigned to the object.
      • read

        public T read​(PK id)
        Description copied from interface: GenericDAO
        Retrieve an object that was previously persisted to the database using the indicated id as primary key.
        Specified by:
        read in interface GenericDAO<T,​PK extends Serializable>
        Parameters:
        id - the key of the object to be retrieved.
        Returns:
        the retrieved object.
      • update

        public void update​(T o)
        Description copied from interface: GenericDAO
        Save changes made to a persistent object.
        Specified by:
        update in interface GenericDAO<T,​PK extends Serializable>
        Parameters:
        o - the object to be updated.
      • delete

        public void delete​(T o)
        Description copied from interface: GenericDAO
        Remove an object from persistent storage in the database.
        Specified by:
        delete in interface GenericDAO<T,​PK extends Serializable>
        Parameters:
        o - the object to be deleted.
      • getSession

        protected org.hibernate.Session getSession()
        Return a session object for managing instances of this class.
        Returns:
        the session.
      • findByCriteria

        protected List<T> findByCriteria​(org.hibernate.criterion.Criterion... criterion)
        Use this inside subclasses as a convenience method to find objects matching a given criterion.
        Parameters:
        criterion - the criteria to be matched.
        Returns:
        a list of objects matching the criterion.