Class JPAGenericDAO<K,​E>

  • Type Parameters:
    K - Type of the entity's key
    E - Type of the entity
    All Implemented Interfaces:
    IGenericDAO<K,​E>
    Direct Known Subclasses:
    JPALuteceDAO

    public abstract class JPAGenericDAO<K,​E>
    extends java.lang.Object
    implements IGenericDAO<K,​E>
    Class JPAGenericDAO
    • Constructor Summary

      Constructors 
      Constructor Description
      JPAGenericDAO()
      Constructor
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void create​(E entity)
      Create an entity
      void detach​(E entity)
      Remove the given entity from the persistence context, causing a managed entity to become detached.
      java.util.List<E> findAll()
      Find all entities
      E findById​(K key)
      Find an entity by its Id
      void flush()
      Synchronize the persistence context to the underlying database.
      javax.persistence.EntityManager getEM()
      Return the Entity Manager
      java.lang.Class<E> getEntityClass()
      Gets the entity class
      java.lang.String getEntityClassName()
      Returns the entity class name
      abstract javax.persistence.EntityManagerFactory getEntityManagerFactory()
      Inherit classes should provide their Entity Manager Factory
      void remove​(K key)
      Remove an entity
      void update​(E entity)
      Update an entity
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • JPAGenericDAO

        public JPAGenericDAO()
        Constructor
    • Method Detail

      • getEntityManagerFactory

        public abstract javax.persistence.EntityManagerFactory getEntityManagerFactory()
        Inherit classes should provide their Entity Manager Factory
        Returns:
        The Entity Manager Factory that will create Entity Manager for this DAO
      • getEntityClassName

        public java.lang.String getEntityClassName()
        Returns the entity class name
        Returns:
        The entity class name
      • getEntityClass

        public java.lang.Class<E> getEntityClass()
        Gets the entity class
        Returns:
        the entity class
      • getEM

        public javax.persistence.EntityManager getEM()
        Return the Entity Manager
        Returns:
        The Entity Manager
      • create

        public void create​(E entity)
        Create an entity
        Specified by:
        create in interface IGenericDAO<K,​E>
        Parameters:
        entity - The entity to create
      • remove

        public void remove​(K key)
        Remove an entity
        Specified by:
        remove in interface IGenericDAO<K,​E>
        Parameters:
        key - The key of the entity to remove
      • update

        public void update​(E entity)
        Update an entity
        Specified by:
        update in interface IGenericDAO<K,​E>
        Parameters:
        entity - An entity that contains new values
      • findById

        public E findById​(K key)
        Find an entity by its Id
        Specified by:
        findById in interface IGenericDAO<K,​E>
        Parameters:
        key - The entity key
        Returns:
        The entity object
      • findAll

        public java.util.List<E> findAll()
        Find all entities
        Specified by:
        findAll in interface IGenericDAO<K,​E>
        Returns:
        A list of entities
      • flush

        public void flush()
        Synchronize the persistence context to the underlying database.
        Specified by:
        flush in interface IGenericDAO<K,​E>
      • detach

        public void detach​(E entity)
        Remove the given entity from the persistence context, causing a managed entity to become detached.
        Specified by:
        detach in interface IGenericDAO<K,​E>
        Parameters:
        entity - the entity