Class OBCriteria<E extends BaseOBObject>

  • All Implemented Interfaces:
    Serializable, org.hibernate.Criteria, org.hibernate.criterion.CriteriaSpecification

    public class OBCriteria<E extends BaseOBObject>
    extends org.hibernate.internal.CriteriaImpl
    This object is an implementation of the Hibernate Criteria interface. It adds transparent client and organization filtering to the Hibernate Criteria. Internally the OBCriteria keeps a Hibernate Criteria object as a delegate. Most calls are delegated to the Hibernate Criteria object after first setting the additional filters.

    This class also offers a convenience method to set orderby, the entities refered to from the order by are automatically joined in the query.

    Author:
    mtaal
    See Also:
    OBContext.getReadableClients(), OBContext.getReadableOrganizations(), Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class org.hibernate.internal.CriteriaImpl

        org.hibernate.internal.CriteriaImpl.CriterionEntry, org.hibernate.internal.CriteriaImpl.OrderEntry, org.hibernate.internal.CriteriaImpl.Subcriteria
    • Field Summary

      • Fields inherited from interface org.hibernate.criterion.CriteriaSpecification

        ALIAS_TO_ENTITY_MAP, DISTINCT_ROOT_ENTITY, FULL_JOIN, INNER_JOIN, LEFT_JOIN, PROJECTION, ROOT_ALIAS, ROOT_ENTITY
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      OBCriteria<E> add​(org.hibernate.criterion.Criterion expression)
      Add a restriction to constrain the results to be retrieved.
      OBCriteria<E> addOrderBy​(String orderOn, boolean ascending)
      Convenience method not present in the standard Hibernate Criteria object.
      int count()
      A convenience method which is not present in the standard Hibernate Criteria object.
      Entity getEntity()  
      String getEntityOrClassName()  
      boolean isFilterOnActive()
      Filter the results on the active property.
      boolean isFilterOnReadableClients()
      Filter the results on readable clients (@see OBContext#getReadableClients()).
      boolean isFilterOnReadableOrganization()  
      List<E> list()
      See the list() method of the Hibernate Criteria class.
      org.hibernate.ScrollableResults scroll()
      See the scroll method on the Hibernate Criteria class.
      org.hibernate.ScrollableResults scroll​(org.hibernate.ScrollMode scrollMode)
      See the scroll method on the Hibernate Criteria class.
      OBCriteria<E> setFilterOnActive​(boolean filterOnActive)
      Filter the results on the active property.
      OBCriteria<E> setFilterOnReadableClients​(boolean filterOnReadableClients)
      Filter the results on readable clients (@see OBContext#getReadableClients()).
      OBCriteria<E> setFilterOnReadableOrganization​(boolean filterOnReadableOrganization)
      Makes it possible to control if a filter on readable organizations should be added to the Criteria automatically.
      OBCriteria<E> setFirstResult​(int firstResult)
      Set the first result to be retrieved.
      OBCriteria<E> setMaxResults​(int maxResults)
      Set a limit upon the number of objects to be retrieved.
      Object uniqueResult()
      See the uniqueResult() method on the Hibernate Criteria class.
      • Methods inherited from class org.hibernate.internal.CriteriaImpl

        add, addOrder, addQueryHint, after, before, createAlias, createAlias, createAlias, createAlias, createAlias, createCriteria, createCriteria, createCriteria, createCriteria, createCriteria, createCriteria, createCriteria, createCriteria, getAlias, getCacheable, getCacheRegion, getComment, getFetchMode, getFetchSize, getFirstResult, getLockModes, getMaxResults, getProjection, getProjectionCriteria, getQueryHints, getResultTransformer, getSession, getTimeout, isLookupByNaturalKey, isReadOnly, isReadOnlyInitialized, iterateExpressionEntries, iterateOrderings, iterateSubcriteria, setCacheable, setCacheMode, setCacheRegion, setComment, setFetchMode, setFetchSize, setFlushMode, setLockMode, setLockMode, setProjection, setReadOnly, setResultTransformer, setSession, setTimeout, toString
    • Constructor Detail

      • OBCriteria

        public OBCriteria​(String entityOrClassName)
      • OBCriteria

        public OBCriteria​(String entityOrClassName,
                          org.hibernate.engine.spi.SessionImplementor session)
      • OBCriteria

        public OBCriteria​(String entityOrClassName,
                          String alias)
      • OBCriteria

        public OBCriteria​(String entityOrClassName,
                          String alias,
                          org.hibernate.engine.spi.SessionImplementor session)
    • Method Detail

      • list

        public List<E> list()
                     throws org.hibernate.HibernateException
        See the list() method of the Hibernate Criteria class.
        Specified by:
        list in interface org.hibernate.Criteria
        Overrides:
        list in class org.hibernate.internal.CriteriaImpl
        Returns:
        the list of Objects retrieved through this Criteria object
        Throws:
        org.hibernate.HibernateException
      • count

        public int count()
        A convenience method which is not present in the standard Hibernate Criteria object. The count of objects is returned.
        Returns:
        the count of the objects using the filter set in this Criteria
      • scroll

        public org.hibernate.ScrollableResults scroll()
                                               throws org.hibernate.HibernateException
        See the scroll method on the Hibernate Criteria class.
        Specified by:
        scroll in interface org.hibernate.Criteria
        Overrides:
        scroll in class org.hibernate.internal.CriteriaImpl
        Throws:
        org.hibernate.HibernateException
      • scroll

        public org.hibernate.ScrollableResults scroll​(org.hibernate.ScrollMode scrollMode)
                                               throws org.hibernate.HibernateException
        See the scroll method on the Hibernate Criteria class.
        Specified by:
        scroll in interface org.hibernate.Criteria
        Overrides:
        scroll in class org.hibernate.internal.CriteriaImpl
        Throws:
        org.hibernate.HibernateException
      • getEntityOrClassName

        public String getEntityOrClassName()
        Overrides:
        getEntityOrClassName in class org.hibernate.internal.CriteriaImpl
      • uniqueResult

        public Object uniqueResult()
                            throws org.hibernate.HibernateException
        See the uniqueResult() method on the Hibernate Criteria class.
        Specified by:
        uniqueResult in interface org.hibernate.Criteria
        Overrides:
        uniqueResult in class org.hibernate.internal.CriteriaImpl
        Throws:
        org.hibernate.HibernateException
      • addOrderBy

        public OBCriteria<E> addOrderBy​(String orderOn,
                                        boolean ascending)
        Convenience method not present in the standard Hibernate Criteria object.
        Parameters:
        orderOn - the property on which to order, can also be a property of an associated entity (etc.)
        ascending - if true then order ascending, false order descending
        Returns:
        this OBCriteria instance, for method chaining
      • getEntity

        public Entity getEntity()
        Returns:
        the Entity for which is queried
        See Also:
        Entity
      • isFilterOnReadableOrganization

        public boolean isFilterOnReadableOrganization()
        Returns:
        true then when querying (for example call list()) a filter on readable organizations is added to the query, if false then this is not done
        See Also:
        OBContext.getReadableOrganizations()
      • setFilterOnReadableOrganization

        public OBCriteria<E> setFilterOnReadableOrganization​(boolean filterOnReadableOrganization)
        Makes it possible to control if a filter on readable organizations should be added to the Criteria automatically. The default is true.
        Parameters:
        filterOnReadableOrganization - if true then when querying (for example call list()) a filter on readable organizations is added to the query, if false then this is not done
        Returns:
        this OBCriteria instance, for method chaining
        See Also:
        OBContext.getReadableOrganizations()
      • isFilterOnActive

        public boolean isFilterOnActive()
        Filter the results on the active property. Default is true. If set then only objects with isActive true are returned by the Criteria object.
        Returns:
        true if objects are filtered on isActive='Y', false otherwise
      • setFilterOnActive

        public OBCriteria<E> setFilterOnActive​(boolean filterOnActive)
        Filter the results on the active property. Default is true. If set then only objects with isActive true are returned by the Criteria object.
        Parameters:
        filterOnActive - if true then only objects with isActive='Y' are returned, false otherwise
        Returns:
        this OBCriteria instance, for method chaining
      • isFilterOnReadableClients

        public boolean isFilterOnReadableClients()
        Filter the results on readable clients (@see OBContext#getReadableClients()). The default is true.
        Returns:
        if true then only objects from readable clients are returned, if false then objects from all clients are returned
      • setFilterOnReadableClients

        public OBCriteria<E> setFilterOnReadableClients​(boolean filterOnReadableClients)
        Filter the results on readable clients (@see OBContext#getReadableClients()). The default is true.
        Parameters:
        filterOnReadableClients - if true then only objects from readable clients are returned, if false then objects from all clients are returned
        Returns:
        this OBCriteria instance, for method chaining
      • add

        public OBCriteria<E> add​(org.hibernate.criterion.Criterion expression)
        Add a restriction to constrain the results to be retrieved.
        Specified by:
        add in interface org.hibernate.Criteria
        Overrides:
        add in class org.hibernate.internal.CriteriaImpl
        Parameters:
        expression - The criterion object representing the restriction to be applied
        Returns:
        this OBCriteria instance, for method chaining
      • setMaxResults

        public OBCriteria<E> setMaxResults​(int maxResults)
        Set a limit upon the number of objects to be retrieved.
        Specified by:
        setMaxResults in interface org.hibernate.Criteria
        Overrides:
        setMaxResults in class org.hibernate.internal.CriteriaImpl
        Parameters:
        maxResults - The maximum number of results
        Returns:
        this OBCriteria instance, for method chaining
      • setFirstResult

        public OBCriteria<E> setFirstResult​(int firstResult)
        Set the first result to be retrieved.
        Specified by:
        setFirstResult in interface org.hibernate.Criteria
        Overrides:
        setFirstResult in class org.hibernate.internal.CriteriaImpl
        Parameters:
        firstResult - The first result to retrieve, numbered from 0
        Returns:
        this OBCriteria instance, for method chaining