Class AbstractDao<T extends Identifiable>

    • Field Detail

      • log

        protected static final org.apache.commons.logging.Log log
    • Constructor Detail

      • AbstractDao

        protected AbstractDao​(Class<? extends T> elementClass,
                              SessionFactory sessionFactory)
      • AbstractDao

        protected AbstractDao​(Class<? extends T> elementClass,
                              SessionFactory sessionFactory,
                              ClassMetadata classMetadata)
        Parameters:
        classMetadata - the class metadata to use to retrieve information about AbstractDao
    • Method Detail

      • create

        public Collection<T> create​(Collection<T> entities)
        Description copied from interface: BaseDao
        Crates all the given entities in the persistent storage.
        Specified by:
        create in interface BaseDao<T extends Identifiable>
        Parameters:
        entities - the entities to be crated.
        Returns:
        collection of entities representing the instances in the persistent storage that were created.
      • create

        @OverridingMethodsMustInvokeSuper
        public T create​(T entity)
        Description copied from interface: BaseDao
        Create an object. If the entity type is immutable, this may also remove any existing entities identified by an appropriate 'find' method.
        Specified by:
        create in interface BaseDao<T extends Identifiable>
        Parameters:
        entity - the entity to create
        Returns:
        the persistent version of the entity
      • load

        public Collection<T> load​(Collection<Long> ids)
        This implementation is temporary and attempts to best replicate the behaviour of loading entities by multiple IDs introduced in Hibernate 5. Read more about this.
        Specified by:
        load in interface BaseDao<T extends Identifiable>
        Parameters:
        ids - the IDs of entities to be loaded. If some IDs are not found or null, they are skipped.
        Returns:
        collection of entities with given ids.
      • load

        public T load​(Long id)
        Description copied from interface: BaseDao
        Loads the entity with given id from the persistent storage.
        Specified by:
        load in interface BaseDao<T extends Identifiable>
        Parameters:
        id - the id of entity to load.
        Returns:
        the entity with given ID, or null if such entity does not exist or if the passed ID was null
        See Also:
        Session.get(Class, Serializable)
      • loadAll

        public Collection<T> loadAll()
        Description copied from interface: BaseDao
        Loads all instanced of specific class from the persistent storage.
        Specified by:
        loadAll in interface BaseDao<T extends Identifiable>
        Returns:
        a collection containing all instances that are currently accessible.
      • countAll

        public long countAll()
        Description copied from interface: BaseDao
        Counts all instances of specific class in the persitent storage.
        Specified by:
        countAll in interface BaseDao<T extends Identifiable>
        Returns:
        number that is the amount of instances currently accessible.
      • remove

        public void remove​(Long id)
        Description copied from interface: BaseDao
        Remove a persistent instance based on its ID. The implementer is trusted to know what type of object to remove. Note that this method is to be avoided for Securable, because it will leave cruft in the ACL tables. We may fix this by having this method return the removed object.
        Specified by:
        remove in interface BaseDao<T extends Identifiable>
        Parameters:
        id - the ID of the entity to be removed
      • update

        public void update​(Collection<T> entities)
        Specified by:
        update in interface BaseDao<T extends Identifiable>
        Parameters:
        entities - Update the entities. Not supported if the entities are immutable.
      • find

        public T find​(T entity)
        Description copied from interface: BaseDao
        Does a look up for the given entity in the persistent storage, usually looking for a specific identifier ( either id or a string property).
        Specified by:
        find in interface BaseDao<T extends Identifiable>
        Parameters:
        entity - the entity to look for.
        Returns:
        an entity that was found in the persistent storage, or null if no such entity was found.
      • findOrCreate

        public T findOrCreate​(T entity)
        Description copied from interface: BaseDao
        Calls the find method, and if this method returns null, creates a new instance in the persistent storage.
        Specified by:
        findOrCreate in interface BaseDao<T extends Identifiable>
        Parameters:
        entity - the entity to look for and persist if not found.
        Returns:
        the given entity, guaranteed to be representing an entity present in the persistent storage.
      • getSessionFactory

        protected final SessionFactory getSessionFactory()
      • getBatchSize

        protected final int getBatchSize()
      • findOneByProperty

        protected T findOneByProperty​(String propertyName,
                                      Object propertyValue)
        Retrieve one entity whose given property matches the given value.

        Note: the property should have a unique index, otherwise a NonUniqueResultException will be raised.

        Parameters:
        propertyName - the name of property to be matched.
        propertyValue - the value to look for.
        Returns:
        an entity whose property matched the given value
      • findByProperty

        protected List<T> findByProperty​(String propertyName,
                                         Object propertyValue)
        Does a search on given property and its value.
        Parameters:
        propertyName - the name of property to be matched.
        propertyValue - the value to look for.
        Returns:
        an entity whose property first matched the given value.
      • findByPropertyIn

        protected List<T> findByPropertyIn​(String propertyName,
                                           Collection<?> propertyValues)
        Perform a search on a given property and all its possible values.