Class AbstractGenericDao<ID,​E extends com.devonfw.module.basic.common.api.entity.PersistenceEntity<ID>>

  • Type Parameters:
    ID - is the generic type if the primary key.
    E - is the generic type of the managed PersistenceEntity.
    All Implemented Interfaces:
    FeatureForceIncrementModificationCounter<E>, GenericDao<ID,​E>
    Direct Known Subclasses:
    AbstractDao

    public abstract class AbstractGenericDao<ID,​E extends com.devonfw.module.basic.common.api.entity.PersistenceEntity<ID>>
    extends QueryHelper
    implements GenericDao<ID,​E>
    This is the abstract base-implementation of the GenericDao interface.
    • Constructor Detail

      • AbstractGenericDao

        public AbstractGenericDao()
        The constructor.
    • Method Detail

      • getEntityClass

        protected abstract Class<E> getEntityClass()
        Returns:
        the Class reflecting the managed entity.
      • getEntityManager

        protected javax.persistence.EntityManager getEntityManager()
        Returns:
        the EntityManager instance.
      • setEntityManager

        public void setEntityManager​(javax.persistence.EntityManager entityManager)
        Parameters:
        entityManager - the EntityManager to inject.
      • getEntityName

        protected String getEntityName()
        Returns:
        the name of the managed entity.
      • save

        public E save​(E entity)
        Description copied from interface: GenericDao
        Saves a given entity. Use the returned instance for further operations as the save operation might have changed the entity instance completely.
        Specified by:
        save in interface GenericDao<ID,​E extends com.devonfw.module.basic.common.api.entity.PersistenceEntity<ID>>
        Parameters:
        entity - the entity to save
        Returns:
        the saved entity
      • isNew

        protected boolean isNew​(E entity)
        Determines if the given PersistenceEntity is new.
        Parameters:
        entity - is the PersistenceEntity to check.
        Returns:
        true if new, false otherwise (e.g. managed or detached).
      • save

        public void save​(Iterable<? extends E> entities)
        Description copied from interface: GenericDao
        Saves all given entities.
        Specified by:
        save in interface GenericDao<ID,​E extends com.devonfw.module.basic.common.api.entity.PersistenceEntity<ID>>
        Parameters:
        entities - the entities to save
      • findOne

        public E findOne​(ID id)
        Description copied from interface: GenericDao
        Retrieves an entity by its id.
        Specified by:
        findOne in interface GenericDao<ID,​E extends com.devonfw.module.basic.common.api.entity.PersistenceEntity<ID>>
        Parameters:
        id - must not be null.
        Returns:
        the entity with the given id or null if none found
      • find

        public E find​(ID id)
        Description copied from interface: GenericDao
        Retrieves an entity by its id.
        Specified by:
        find in interface GenericDao<ID,​E extends com.devonfw.module.basic.common.api.entity.PersistenceEntity<ID>>
        Parameters:
        id - must not be null.
        Returns:
        the entity with the given id or null if none found
      • get

        public E get​(com.devonfw.module.basic.common.api.reference.Ref<ID,​E> reference)
        Specified by:
        get in interface GenericDao<ID,​E extends com.devonfw.module.basic.common.api.entity.PersistenceEntity<ID>>
        Parameters:
        reference - the Ref to the PersistenceEntity to get. Typically an instance of IdRef.
        Returns:
        the PersistenceEntity as reference for the given Ref. Will be null if the given Ref was null.
      • exists

        public boolean exists​(ID id)
        Description copied from interface: GenericDao
        Returns whether an entity with the given id exists.
        Specified by:
        exists in interface GenericDao<ID,​E extends com.devonfw.module.basic.common.api.entity.PersistenceEntity<ID>>
        Parameters:
        id - must not be null.
        Returns:
        true if an entity with the given id exists, false otherwise
      • findAll

        public List<E> findAll()
        Returns:
        an Iterable to find ALL managed entities from the persistent store. Not exposed to API by default as this might not make sense for all kind of entities.
      • findAll

        public List<E> findAll​(Iterable<ID> ids)
        Description copied from interface: GenericDao
        Returns all instances of the type with the given IDs.
        Specified by:
        findAll in interface GenericDao<ID,​E extends com.devonfw.module.basic.common.api.entity.PersistenceEntity<ID>>
        Parameters:
        ids - are the IDs of all entities to retrieve e.g. as List.
        Returns:
        an Iterable with all entites for the given ids.
      • toCollection

        protected Collection<ID> toCollection​(Iterable<ID> ids)
        Parameters:
        ids - sequence of id
        Returns:
        a collection of these ids to use Expression.in(Collection) for instance
      • delete

        public void delete​(ID id)
        Description copied from interface: GenericDao
        Deletes the entity with the given id.
        Specified by:
        delete in interface GenericDao<ID,​E extends com.devonfw.module.basic.common.api.entity.PersistenceEntity<ID>>
        Parameters:
        id - must not be null.
      • delete

        public void delete​(E entity)
        Description copied from interface: GenericDao
        Deletes a given entity.
        Specified by:
        delete in interface GenericDao<ID,​E extends com.devonfw.module.basic.common.api.entity.PersistenceEntity<ID>>
        Parameters:
        entity - the entity to delete
      • delete

        public void delete​(Iterable<? extends E> entities)
        Description copied from interface: GenericDao
        Deletes the given entities.
        Specified by:
        delete in interface GenericDao<ID,​E extends com.devonfw.module.basic.common.api.entity.PersistenceEntity<ID>>
        Parameters:
        entities - the entities to delete