Class AbstractHibernateDAO<T>

    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected AbstractHibernateDAO()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int count​(javax.persistence.Query query)
      This method will return the count of items for this query as an integer This query needs to already be in a formate that'll return one record that contains the amount
      int count​(Context context, javax.persistence.criteria.CriteriaQuery criteriaQuery, javax.persistence.criteria.CriteriaBuilder criteriaBuilder, javax.persistence.criteria.Root<T> root)
      This method will return the amount of results that would be generated for this CriteriaQuery as an integer
      long countLong​(Context context, javax.persistence.criteria.CriteriaQuery criteriaQuery, javax.persistence.criteria.CriteriaBuilder criteriaBuilder, javax.persistence.criteria.Root<T> root)
      This method will return the count of items for this query as a long
      T create​(Context context, T t)
      Create a new instance of this type in the database.
      javax.persistence.Query createQuery​(Context context, String query)
      Create a parsed query from a query expression.
      void delete​(Context context, T t)
      Remove an instance from the database.
      List<T> executeCriteriaQuery​(Context context, javax.persistence.criteria.CriteriaQuery<T> criteriaQuery, boolean cacheable, int maxResults, int offset)
      This method will return a list of objects to be returned that match the given criteriaQuery and parameters.
      List<T> findAll​(Context context, Class<T> clazz)
      Fetch all persisted instances of a given object type.
      List<T> findAll​(Context context, Class<T> clazz, Integer limit, Integer offset)
      Fetch all persisted instances of a given object type.
      T findByID​(Context context, Class clazz, int id)
      Fetch the entity identified by its legacy database identifier.
      T findByID​(Context context, Class clazz, UUID id)
      Fetch the entity identified by its UUID primary key.
      List<T> findByX​(Context context, Class clazz, Map<String,​Object> equals, boolean cacheable, int maxResults, int offset)
      This method can be used to construct a query for which there needs to be a bunch of equal properties These properties can be passed along in the equals hashmap
      List<T> findMany​(Context context, String query)
      Execute a JPQL query and return a collection of results.
      List<T> findMany​(Context context, javax.persistence.Query query)
      Execute a JPA Criteria query and return a collection of results.
      T findUnique​(Context context, String query)
      Execute a JPQL query returning a unique result.
      javax.persistence.criteria.CriteriaBuilder getCriteriaBuilder​(Context context)
      This method should always be used in order to retrieve a CriteriaBuilder for the given context
      javax.persistence.criteria.CriteriaQuery<T> getCriteriaQuery​(javax.persistence.criteria.CriteriaBuilder criteriaBuilder, Class<T> clazz)
      This method should always be used in order to retrieve the CriteriaQuery in order to start creating a query that has to be executed
      protected org.hibernate.Session getHibernateSession​(Context context)
      The Session used to manipulate entities of this type.
      Iterator<T> iterate​(javax.persistence.Query query)
      This method will return an Iterator for the given Query
      List<T> list​(javax.persistence.Query query)
      This method will be used to return a list of results for the given query
      List<T> list​(javax.persistence.Query query, int limit, int offset)
      This method will return a list of results for the given Query and parameters
      List<T> list​(Context context, javax.persistence.criteria.CriteriaQuery criteriaQuery, boolean cacheable, Class<T> clazz, int maxResults, int offset)
      This method will return a list with unique results, no duplicates, made by the given CriteriaQuery and parameters
      List<T> list​(Context context, javax.persistence.criteria.CriteriaQuery criteriaQuery, boolean cacheable, Class<T> clazz, int maxResults, int offset, boolean distinct)
      This method will return a list of results for the given CriteriaQuery and parameters
      void save​(Context context, T t)
      Persist this instance in the database.
      T singleResult​(javax.persistence.Query query)
      This method will return the first result from the given query or null if no results were found
      T singleResult​(Context context, javax.persistence.criteria.CriteriaQuery criteriaQuery)
      Retrieve a single result from the query.
      T uniqueResult​(javax.persistence.Query query)
      This method will return a singular result for the given query
      T uniqueResult​(Context context, javax.persistence.criteria.CriteriaQuery criteriaQuery, boolean cacheable, Class<T> clazz)
      Retrieve a unique result from the query.
    • Constructor Detail

      • AbstractHibernateDAO

        protected AbstractHibernateDAO()
    • Method Detail

      • create

        public T create​(Context context,
                        T t)
                 throws SQLException
        Description copied from interface: GenericDAO
        Create a new instance of this type in the database.
        Specified by:
        create in interface GenericDAO<T>
        Parameters:
        context - current DSpace context.
        t - type to be created.
        Returns:
        entity tracking the created instance.
        Throws:
        SQLException
      • save

        public void save​(Context context,
                         T t)
                  throws SQLException
        Description copied from interface: GenericDAO
        Persist this instance in the database.
        Specified by:
        save in interface GenericDAO<T>
        Parameters:
        context - current DSpace context.
        t - type created here.
        Throws:
        SQLException - passed through.
      • getHibernateSession

        protected org.hibernate.Session getHibernateSession​(Context context)
                                                     throws SQLException
        The Session used to manipulate entities of this type.
        Parameters:
        context - current DSpace context.
        Returns:
        the current Session.
        Throws:
        SQLException
      • delete

        public void delete​(Context context,
                           T t)
                    throws SQLException
        Description copied from interface: GenericDAO
        Remove an instance from the database.
        Specified by:
        delete in interface GenericDAO<T>
        Parameters:
        context - current DSpace context.
        t - type of the instance to be removed.
        Throws:
        SQLException - passed through.
      • findAll

        public List<T> findAll​(Context context,
                               Class<T> clazz)
                        throws SQLException
        Description copied from interface: GenericDAO
        Fetch all persisted instances of a given object type.
        Specified by:
        findAll in interface GenericDAO<T>
        Parameters:
        context - The relevant DSpace Context.
        clazz - the desired type.
        Returns:
        list of DAOs of the same type as clazz
        Throws:
        SQLException - if database error
      • findAll

        public List<T> findAll​(Context context,
                               Class<T> clazz,
                               Integer limit,
                               Integer offset)
                        throws SQLException
        Description copied from interface: GenericDAO
        Fetch all persisted instances of a given object type.
        Specified by:
        findAll in interface GenericDAO<T>
        Parameters:
        context - The relevant DSpace Context.
        clazz - the desired type.
        limit - paging limit
        offset - paging offset
        Returns:
        list of DAOs of the same type as clazz
        Throws:
        SQLException - if database error
      • findUnique

        public T findUnique​(Context context,
                            String query)
                     throws SQLException
        Description copied from interface: GenericDAO
        Execute a JPQL query returning a unique result.
        Specified by:
        findUnique in interface GenericDAO<T>
        Parameters:
        context - The relevant DSpace Context.
        query - JPQL query string
        Returns:
        a DAO specified by the query string
        Throws:
        SQLException - if database error
      • findByID

        public T findByID​(Context context,
                          Class clazz,
                          UUID id)
                   throws SQLException
        Description copied from interface: GenericDAO
        Fetch the entity identified by its UUID primary key.
        Specified by:
        findByID in interface GenericDAO<T>
        Parameters:
        context - current DSpace context.
        clazz - class of entity to be found.
        id - primary key of the database record.
        Returns:
        the found entity.
        Throws:
        SQLException
      • findByID

        public T findByID​(Context context,
                          Class clazz,
                          int id)
                   throws SQLException
        Description copied from interface: GenericDAO
        Fetch the entity identified by its legacy database identifier.
        Specified by:
        findByID in interface GenericDAO<T>
        Parameters:
        context - current DSpace context.
        clazz - class of entity to be found.
        id - legacy database record ID.
        Returns:
        the found entity.
        Throws:
        SQLException - passed through.
      • findMany

        public List<T> findMany​(Context context,
                                String query)
                         throws SQLException
        Description copied from interface: GenericDAO
        Execute a JPQL query and return a collection of results.
        Specified by:
        findMany in interface GenericDAO<T>
        Parameters:
        context - The relevant DSpace Context.
        query - JPQL query string
        Returns:
        list of DAOs specified by the query string
        Throws:
        SQLException - if database error
      • findMany

        public List<T> findMany​(Context context,
                                javax.persistence.Query query)
                         throws SQLException
        Execute a JPA Criteria query and return a collection of results.
        Parameters:
        context - The relevant DSpace Context.
        query - JPQL query string
        Returns:
        list of DAOs specified by the query string
        Throws:
        SQLException - if database error
      • createQuery

        public javax.persistence.Query createQuery​(Context context,
                                                   String query)
                                            throws SQLException
        Create a parsed query from a query expression.
        Parameters:
        context - current DSpace context.
        query - textual form of the query.
        Returns:
        parsed form of the query.
        Throws:
        SQLException
      • list

        public List<T> list​(Context context,
                            javax.persistence.criteria.CriteriaQuery criteriaQuery,
                            boolean cacheable,
                            Class<T> clazz,
                            int maxResults,
                            int offset)
                     throws SQLException
        This method will return a list with unique results, no duplicates, made by the given CriteriaQuery and parameters
        Parameters:
        context - The standard DSpace context object
        criteriaQuery - The CriteriaQuery for which this list will be retrieved
        cacheable - Whether or not this query should be cacheable
        clazz - The class for which this CriteriaQuery will be executed on
        maxResults - The maximum amount of results that will be returned for this CriteriaQuery
        offset - The offset to be used for the CriteriaQuery
        Returns:
        A list of distinct results as depicted by the CriteriaQuery and parameters
        Throws:
        SQLException
      • list

        public List<T> list​(Context context,
                            javax.persistence.criteria.CriteriaQuery criteriaQuery,
                            boolean cacheable,
                            Class<T> clazz,
                            int maxResults,
                            int offset,
                            boolean distinct)
                     throws SQLException
        This method will return a list of results for the given CriteriaQuery and parameters
        Parameters:
        context - The standard DSpace context object
        criteriaQuery - The CriteriaQuery to be used to find the list of results
        cacheable - A boolean value indicating whether this query should be cached or not
        clazz - The class on which the CriteriaQuery will search
        maxResults - The maximum amount of results to be returned
        offset - The offset to be used for the CriteriaQuery
        distinct - A boolean value indicating whether this list should be distinct or not
        Returns:
        A list of results determined by the CriteriaQuery and parameters
        Throws:
        SQLException
      • list

        public List<T> list​(javax.persistence.Query query)
        This method will be used to return a list of results for the given query
        Parameters:
        query - The query for which the resulting list will be returned
        Returns:
        The list of results for the given query
      • list

        public List<T> list​(javax.persistence.Query query,
                            int limit,
                            int offset)
        This method will return a list of results for the given Query and parameters
        Parameters:
        query - The query for which the resulting list will be returned
        limit - The maximum amount of results to be returned
        offset - The offset to be used for the Query
        Returns:
        A list of results determined by the Query and parameters
      • uniqueResult

        public T uniqueResult​(Context context,
                              javax.persistence.criteria.CriteriaQuery criteriaQuery,
                              boolean cacheable,
                              Class<T> clazz)
                       throws SQLException
        Retrieve a unique result from the query. If multiple results CAN be retrieved an exception will be thrown, so only use when the criteria state uniqueness in the database.
        Parameters:
        context - current DSpace session.
        criteriaQuery - JPA criteria
        cacheable - whether or not this query should be cacheable.
        clazz - type of object that should match the query.
        Returns:
        the single model object specified by the criteria, or null if none match.
        Throws:
        SQLException - passed through.
        IllegalArgumentException - if multiple objects match.
      • singleResult

        public T singleResult​(Context context,
                              javax.persistence.criteria.CriteriaQuery criteriaQuery)
                       throws SQLException
        Retrieve a single result from the query. Best used if you expect a single result, but this isn't enforced on the database.
        Parameters:
        context - current DSpace session
        criteriaQuery - JPA criteria
        Returns:
        a DAO specified by the criteria
        Throws:
        SQLException - passed through.
      • singleResult

        public T singleResult​(javax.persistence.Query query)
        This method will return the first result from the given query or null if no results were found
        Parameters:
        query - The query that is to be executed
        Returns:
        One result from the given query or null if none was found
      • uniqueResult

        public T uniqueResult​(javax.persistence.Query query)
        This method will return a singular result for the given query
        Parameters:
        query - The query for which a single result will be given
        Returns:
        The single result for this query
      • iterate

        public Iterator<T> iterate​(javax.persistence.Query query)
        This method will return an Iterator for the given Query
        Parameters:
        query - The query for which an Iterator will be made
        Returns:
        The Iterator for the results of this query
      • count

        public int count​(Context context,
                         javax.persistence.criteria.CriteriaQuery criteriaQuery,
                         javax.persistence.criteria.CriteriaBuilder criteriaBuilder,
                         javax.persistence.criteria.Root<T> root)
                  throws SQLException
        This method will return the amount of results that would be generated for this CriteriaQuery as an integer
        Parameters:
        context - The standard DSpace Context object
        criteriaQuery - The CriteriaQuery for which this result will be retrieved
        criteriaBuilder - The CriteriaBuilder that accompanies the CriteriaQuery
        root - The root that'll determine on which class object we need to calculate the result
        Returns:
        The amount of results that would be found by this CriteriaQuery as an integer value
        Throws:
        SQLException
      • count

        public int count​(javax.persistence.Query query)
        This method will return the count of items for this query as an integer This query needs to already be in a formate that'll return one record that contains the amount
        Parameters:
        query - The query for which the amount of results will be returned.
        Returns:
        The amount of results
      • countLong

        public long countLong​(Context context,
                              javax.persistence.criteria.CriteriaQuery criteriaQuery,
                              javax.persistence.criteria.CriteriaBuilder criteriaBuilder,
                              javax.persistence.criteria.Root<T> root)
                       throws SQLException
        This method will return the count of items for this query as a long
        Parameters:
        context - The standard DSpace Context object
        criteriaQuery - The CriteriaQuery for which the amount of results will be retrieved
        criteriaBuilder - The CriteriaBuilder that goes along with this CriteriaQuery
        root - The root created for a DSpace class on which this query will search
        Returns:
        A long value that depicts the amount of results this query has found
        Throws:
        SQLException
      • getCriteriaQuery

        public javax.persistence.criteria.CriteriaQuery<T> getCriteriaQuery​(javax.persistence.criteria.CriteriaBuilder criteriaBuilder,
                                                                            Class<T> clazz)
        This method should always be used in order to retrieve the CriteriaQuery in order to start creating a query that has to be executed
        Parameters:
        criteriaBuilder - The CriteriaBuilder for which this CriteriaQuery will be constructed
        clazz - The class that this CriteriaQuery will be constructed for
        Returns:
        A CriteriaQuery on which a query can be built
      • getCriteriaBuilder

        public javax.persistence.criteria.CriteriaBuilder getCriteriaBuilder​(Context context)
                                                                      throws SQLException
        This method should always be used in order to retrieve a CriteriaBuilder for the given context
        Parameters:
        context - The standard DSpace Context class for which a CriteriaBuilder will be made
        Returns:
        A CriteriaBuilder that can be used to create the query
        Throws:
        SQLException
      • executeCriteriaQuery

        public List<T> executeCriteriaQuery​(Context context,
                                            javax.persistence.criteria.CriteriaQuery<T> criteriaQuery,
                                            boolean cacheable,
                                            int maxResults,
                                            int offset)
                                     throws SQLException
        This method will return a list of objects to be returned that match the given criteriaQuery and parameters. The maxResults and offSet can be circumvented by entering the value -1 for them.
        Parameters:
        context - The standard context DSpace object
        criteriaQuery - The CriteriaQuery that will be used for executing the query
        cacheable - Whether or not this query is able to be cached
        maxResults - The maximum amount of results that this query will return This can be circumvented by passing along -1 as the value
        offset - The offset to be used in this query This can be circumvented by passing along -1 as the value
        Returns:
        This will return a list of objects that conform to the made query
        Throws:
        SQLException
      • findByX

        public List<T> findByX​(Context context,
                               Class clazz,
                               Map<String,​Object> equals,
                               boolean cacheable,
                               int maxResults,
                               int offset)
                        throws SQLException
        This method can be used to construct a query for which there needs to be a bunch of equal properties These properties can be passed along in the equals hashmap
        Parameters:
        context - The standard DSpace context object
        clazz - The class on which the criteriaQuery will be built
        equals - A hashmap that can be used to store the String representation of the column and the value that should match that in the DB
        cacheable - A boolean indicating whether this query should be cacheable or not
        maxResults - The max amount of results to be returned by this query
        offset - The offset to be used in this query
        Returns:
        Will return a list of objects that correspond with the constructed query and parameters
        Throws:
        SQLException