Class EntityViewSetting<T,​Q extends FullQueryBuilder<T,​Q>>

java.lang.Object
com.blazebit.persistence.view.EntityViewSetting<T,​Q>
Type Parameters:
T - The type of the entity view
Q - PaginatedCriteriaBuilder if paginated, CriteriaBuilder otherwise
All Implemented Interfaces:
SubGraph<T>

public final class EntityViewSetting<T,​Q extends FullQueryBuilder<T,​Q>>
extends Object
implements SubGraph<T>
A EntityViewSetting is a set of filters and sorters that can be applied to a CriteriaBuilder. Filters and sorters are added for entity view attribute names. It also supports pagination and optional parameters. Optional parameters are only set on a criteria builder if they are needed but not satisfied.
Since:
1.0.0
Author:
Christian Beikov, Moritz Becker
  • Method Details

    • create

      public static <T> EntityViewSetting<T,​CriteriaBuilder<T>> create​(Class<T> entityViewClass)
      Like create(java.lang.Class, java.lang.String) but with the viewConstructorName set to null.
      Type Parameters:
      T - The type of the entity view
      Parameters:
      entityViewClass - The entity view class that should be used for the object builder
      Returns:
      A new entity view setting
    • create

      public static <T> EntityViewSetting<T,​CriteriaBuilder<T>> create​(Class<T> entityViewClass, String viewConstructorName)
      Creates a new EntityViewSetting that can be applied on criteria builders.
      Type Parameters:
      T - The type of the entity view
      Parameters:
      entityViewClass - The entity view class that should be used for the object builder
      viewConstructorName - The name of the view constructor
      Returns:
      A new entity view setting
    • create

      public static <T> EntityViewSetting<T,​PaginatedCriteriaBuilder<T>> create​(Class<T> entityViewClass, int firstResult, int maxResults)
      Like create(java.lang.Class, int, int, java.lang.String) but with the viewConstructorName set to null.
      Type Parameters:
      T - The type of the entity view
      Parameters:
      entityViewClass - The entity view class that should be used for the object builder
      firstResult - The position of the first result to retrieve, numbered from 0
      maxResults - The maximum number of results to retrieve
      Returns:
      A new entity view setting
    • create

      public static <T> EntityViewSetting<T,​PaginatedCriteriaBuilder<T>> create​(Class<T> entityViewClass, Object entityId, int maxResults)
      Like create(java.lang.Class, java.lang.Object, int, java.lang.String) but with the viewConstructorName set to null.
      Type Parameters:
      T - The type of the entity view
      Parameters:
      entityViewClass - The entity view class that should be used for the object builder
      entityId - The id of the entity which should be located on a page
      maxResults - The maximum number of results to retrieve
      Returns:
      A new entity view setting
    • create

      public static <T> EntityViewSetting<T,​PaginatedCriteriaBuilder<T>> create​(Class<T> entityViewClass, int firstResult, int maxResults, String viewConstructorName)
      Creates a new EntityViewSetting that can be applied on criteria builders.
      Type Parameters:
      T - The type of the entity view
      Parameters:
      entityViewClass - The entity view class that should be used for the object builder
      firstResult - The position of the first result to retrieve, numbered from 0
      maxResults - The maximum number of results to retrieve
      viewConstructorName - The name of the view constructor
      Returns:
      A new entity view setting
    • create

      public static <T> EntityViewSetting<T,​PaginatedCriteriaBuilder<T>> create​(Class<T> entityViewClass, Object entityId, int maxResults, String viewConstructorName)
      Creates a new EntityViewSetting that can be applied on criteria builders.
      Type Parameters:
      T - The type of the entity view
      Parameters:
      entityViewClass - The entity view class that should be used for the object builder
      entityId - The id of the entity which should be located on a page
      maxResults - The maximum number of results to retrieve
      viewConstructorName - The name of the view constructor
      Returns:
      A new entity view setting
    • forSubtype

      public <X extends T,​ Y extends FullQueryBuilder<X,​ Y>> EntityViewSetting<X,​Y> forSubtype​(Class<X> subtype)
      Creates a copy of this EntityViewSetting for the given entity view subtype.
      Type Parameters:
      X - Entity view subtype
      Y - The query builder type
      Parameters:
      subtype - The entity view subtype
      Returns:
      A copy for the given subtype
    • getEntityViewClass

      public Class<T> getEntityViewClass()
      Returns the entity view class.
      Returns:
      The entity view class
    • getViewConstructorName

      public String getViewConstructorName()
      Returns the entity view constructor name.
      Returns:
      The entity view constructor name
    • getEntityId

      public Object getEntityId()
      The id of the entity which should be located on the page returned result. Returns null if no pagination or a absolute first result will be applied.
      Returns:
      The id of the entity which should be located on a page
      See Also:
      FullQueryBuilder.pageAndNavigate(java.lang.Object, int)
    • getFirstResult

      public int getFirstResult()
      The first result that the criteria builder should return. Returns 0 if no pagination will be applied. Returns -1 if an entity id was supplied.
      Returns:
      The first result
      See Also:
      FullQueryBuilder.page(int, int)
    • getMaxResults

      public int getMaxResults()
      The maximum number of results that the criteria builder should return. Returns Integer.MAX_VALUE if no pagination will be applied.
      Returns:
      The maximum number of results
      See Also:
      FullQueryBuilder.page(int, int)
    • isPaginated

      public boolean isPaginated()
      Returns true if this entiy view setting applies pagination, false otherwise.
      Returns:
      True if this entiy view setting applies pagination, false otherwise
    • getKeysetPage

      public KeysetPage getKeysetPage()
      Returns the key set of this setting.
      Returns:
      The key set of this setting
    • withKeysetPage

      public EntityViewSetting<T,​Q> withKeysetPage​(KeysetPage keysetPage)
      Sets the key set of this setting.
      Parameters:
      keysetPage - the new key set
      Returns:
      this setting for chaining
    • isKeysetPaginated

      public boolean isKeysetPaginated()
      Returns true if this setting is key set paginated.
      Returns:
      true if this setting is key set paginated
    • addAttributeSorters

      public void addAttributeSorters​(Map<String,​Sorter> attributeSorters)
      Adds the given attribute sorters to the attribute sorters of this setting. Note that the attribute sorter order is retained.
      Parameters:
      attributeSorters - The attribute sorters to add
    • addAttributeSorter

      public void addAttributeSorter​(String attributeName, Sorter sorter)
      Adds the given attribute sorter to the attribute sorters of this setting. Note that the attribute sorter order is retained.
      Parameters:
      attributeName - The name of the attribute sorter
      sorter - The sorter for the attribute sorter
    • withAttributeSorter

      public EntityViewSetting<T,​Q> withAttributeSorter​(String attributeName, Sorter sorter)
      Adds the given attribute sorter to the attribute sorters of this setting. Note that the attribute sorter order is retained.
      Parameters:
      attributeName - The name of the attribute sorter
      sorter - The sorter for the attribute sorter
      Returns:
      this for method chaining
      Since:
      1.3.0
    • addAttributeSorter

      public void addAttributeSorter​(MethodAttribute<T,​?> attribute, Sorter sorter)
      Adds the given attribute sorter to the attribute sorters of this setting. Note that the attribute sorter order is retained.
      Parameters:
      attribute - The attribute for the attribute sorter
      sorter - The sorter for the attribute sorter
      Since:
      1.5.0
    • withAttributeSorter

      public EntityViewSetting<T,​Q> withAttributeSorter​(MethodAttribute<T,​?> attribute, Sorter sorter)
      Adds the given attribute sorter to the attribute sorters of this setting. Note that the attribute sorter order is retained.
      Parameters:
      attribute - The attribute for the attribute sorter
      sorter - The sorter for the attribute sorter
      Returns:
      this for method chaining
      Since:
      1.5.0
    • addAttributeSorter

      public void addAttributeSorter​(AttributePath<T,​?,​?> attributePath, Sorter sorter)
      Adds the given attribute sorter to the attribute sorters of this setting. Note that the attribute sorter order is retained.
      Parameters:
      attributePath - The attribute path for the attribute sorter
      sorter - The sorter for the attribute sorter
      Since:
      1.5.0
    • withAttributeSorter

      public EntityViewSetting<T,​Q> withAttributeSorter​(AttributePath<T,​?,​?> attributePath, Sorter sorter)
      Adds the given attribute sorter to the attribute sorters of this setting. Note that the attribute sorter order is retained.
      Parameters:
      attributePath - The attribute path for the attribute sorter
      sorter - The sorter for the attribute sorter
      Returns:
      this for method chaining
      Since:
      1.5.0
    • hasAttributeSorters

      public boolean hasAttributeSorters()
      Returns true if sorters have been added, otherwise false.
      Returns:
      true if sorters have been added, otherwise false
    • getAttributeSorters

      public Map<String,​Sorter> getAttributeSorters()
      Returns a copy of the attribute sorters that have been added.
      Returns:
      The attribute sorters
    • addAttributeFilters

      public void addAttributeFilters​(Map<String,​Object> attributeFilters)
      Adds the given attribute filters to the attribute filters of this setting.
      Parameters:
      attributeFilters - The attribute filters to add
    • addAttributeFilter

      public void addAttributeFilter​(String attributeName, Object filterValue)
      Adds the attribute's default attribute filter to the attribute filters of this setting or overwrites the filter value of an existing default attribute filter.
      Parameters:
      attributeName - The name of the attribute filter
      filterValue - The filter value for the attribute filter
    • withAttributeFilter

      public EntityViewSetting<T,​Q> withAttributeFilter​(String attributeName, Object filterValue)
      Adds the attribute's default attribute filter to the attribute filters of this setting or overwrites the filter value of an existing default attribute filter.
      Parameters:
      attributeName - The name of the attribute filter
      filterValue - The filter value for the attribute filter
      Returns:
      this for method chaining
      Since:
      1.3.0
    • addAttributeFilter

      public void addAttributeFilter​(String attributeName, String filterName, Object filterValue)
      Adds the attribute's attribute filter with the given name to the attribute filters of this setting or overwrites the filter value of an existing attribute filter with the same attribute name and filter name.
      Parameters:
      attributeName - The attribute name
      filterName - The filter name
      filterValue - The filter value for the attribute filter
    • withAttributeFilter

      public EntityViewSetting<T,​Q> withAttributeFilter​(String attributeName, String filterName, Object filterValue)
      Adds the attribute's attribute filter with the given name to the attribute filters of this setting or overwrites the filter value of an existing attribute filter with the same attribute name and filter name.
      Parameters:
      attributeName - The attribute name
      filterName - The filter name
      filterValue - The filter value for the attribute filter
      Returns:
      this for method chaining
      Since:
      1.3.0
    • addAttributeFilter

      public <FilterValue> void addAttributeFilter​(AttributeFilterMapping<T,​FilterValue> attributeFilter, FilterValue filterValue)
      Adds the attribute's default attribute filter to the attribute filters of this setting or overwrites the filter value of an existing default attribute filter.
      Type Parameters:
      FilterValue - The filter value type
      Parameters:
      attributeFilter - The attribute filter
      filterValue - The filter value for the attribute filter
      Since:
      1.5.0
    • withAttributeFilter

      public <FilterValue> EntityViewSetting<T,​Q> withAttributeFilter​(AttributeFilterMapping<T,​FilterValue> attributeFilter, FilterValue filterValue)
      Adds the attribute's default attribute filter to the attribute filters of this setting or overwrites the filter value of an existing default attribute filter.
      Type Parameters:
      FilterValue - The filter value type
      Parameters:
      attributeFilter - The attribute filter
      filterValue - The filter value for the attribute filter
      Returns:
      this for method chaining
      Since:
      1.5.0
    • addAttributeFilter

      public <FilterValue> void addAttributeFilter​(AttributeFilterMappingPath<T,​FilterValue> attributeFilter, FilterValue filterValue)
      Adds the attribute's default attribute filter to the attribute filters of this setting or overwrites the filter value of an existing default attribute filter.
      Type Parameters:
      FilterValue - The filter value type
      Parameters:
      attributeFilter - The attribute filter mapping path
      filterValue - The filter value for the attribute filter
      Since:
      1.5.0
    • withAttributeFilter

      public <FilterValue> EntityViewSetting<T,​Q> withAttributeFilter​(AttributeFilterMappingPath<T,​FilterValue> attributeFilter, FilterValue filterValue)
      Adds the attribute's default attribute filter to the attribute filters of this setting or overwrites the filter value of an existing default attribute filter.
      Type Parameters:
      FilterValue - The filter value type
      Parameters:
      attributeFilter - The attribute filter mapping path
      filterValue - The filter value for the attribute filter
      Returns:
      this for method chaining
      Since:
      1.5.0
    • hasAttributeFilters

      public boolean hasAttributeFilters()
      Returns true if filters have been added, otherwise false.
      Returns:
      true if filters have been added, otherwise false
    • getAttributeFilters

      public Map<String,​EntityViewSetting.AttributeFilterActivation> getAttributeFilters()
      Returns a copy of the attribute filters that have been added.
      Returns:
      The attribute filters
    • getAttributeFilterActivations

      public Map<String,​List<EntityViewSetting.AttributeFilterActivation>> getAttributeFilterActivations()
      Returns a copy of the attribute filters that have been added.
      Returns:
      The attribute filters
      Since:
      1.5.0
    • addViewFilter

      public void addViewFilter​(String filterName)
      Enables and adds the view filter with the given name in this setting.
      Parameters:
      filterName - The name of the view filter
    • withViewFilter

      public EntityViewSetting<T,​Q> withViewFilter​(String filterName)
      Enables and adds the view filter with the given name in this setting.
      Parameters:
      filterName - The name of the view filter
      Returns:
      this for method chaining
      Since:
      1.3.0
    • hasViewFilters

      public boolean hasViewFilters()
      Returns true if named filters for the view have been added, otherwise false.
      Returns:
      true if named filters for the view have been added, otherwise false
    • getViewFilters

      public Set<String> getViewFilters()
      Returns a copy of the named filters for the view that have been added.
      Returns:
      The named filters for the view
    • addOptionalParameters

      public void addOptionalParameters​(Map<String,​Object> optionalParameters)
      Adds the given optional parameters to the optional parameters of this setting.
      Parameters:
      optionalParameters - The optional parameters to add
    • addOptionalParameter

      public void addOptionalParameter​(String parameterName, Object value)
      Adds the given optional parameter to the optional parameters of this setting.
      Parameters:
      parameterName - The name of the optional parameter
      value - The value of the optional parameter
    • withOptionalParameter

      public EntityViewSetting<T,​Q> withOptionalParameter​(String parameterName, Object value)
      Adds the given optional parameter to the optional parameters of this setting.
      Parameters:
      parameterName - The name of the optional parameter
      value - The value of the optional parameter
      Returns:
      this for method chaining
      Since:
      1.3.0
    • hasOptionalParameters

      public boolean hasOptionalParameters()
      Returns true if optional parameters have been added, otherwise false.
      Returns:
      true if optional parameters have been added, otherwise false
    • getOptionalParameters

      public Map<String,​Object> getOptionalParameters()
      Returns a copy of the optional parameters that have been added.
      Returns:
      The optional parameters
    • setProperty

      public void setProperty​(String propertyName, Object value)
      Set a entity view property or hint. If a property or hint is not recognized, it is silently ignored.
      Parameters:
      propertyName - name of property or hint
      value - value for property or hint
      Since:
      1.2.0
    • withProperty

      public EntityViewSetting<T,​Q> withProperty​(String propertyName, Object value)
      Set a entity view property or hint. If a property or hint is not recognized, it is silently ignored.
      Parameters:
      propertyName - name of property or hint
      value - value for property or hint
      Returns:
      this for method chaining
      Since:
      1.3.0
    • getProperties

      public Map<String,​Object> getProperties()
      Get the properties and hints and associated values that are in effect for the entity view setting.
      Returns:
      map of properties and hints in effect for entity view setting
      Since:
      1.2.0
    • fetch

      public <X> SubGraph<X> fetch​(String path)
      Description copied from interface: SubGraph
      Adds a fetch for the given path and returns the SubGraph for it. Careful, calling this method will cause that only the attribute paths that are added and reachable object ids will be fetched. Other attributes will be fetched with their default value.
      Specified by:
      fetch in interface SubGraph<T>
      Type Parameters:
      X - The type of the fetched path
      Parameters:
      path - The path to fetch
      Returns:
      The sub graph for the path
    • fetch

      public <X> SubGraph<X> fetch​(MethodSingularAttribute<T,​X> attribute)
      Description copied from interface: SubGraph
      Adds a fetch for the given attribute and returns the SubGraph for it. Careful, calling this method will cause that only the attribute paths that are added and reachable object ids will be fetched. Other attributes will be fetched with their default value.
      Specified by:
      fetch in interface SubGraph<T>
      Type Parameters:
      X - The type of the fetched path
      Parameters:
      attribute - The attribute to fetch
      Returns:
      The sub graph for the path
    • fetch

      public <X> SubGraph<X> fetch​(MethodPluralAttribute<T,​?,​X> attribute)
      Description copied from interface: SubGraph
      Adds a fetch for the given attribute and returns the SubGraph for it. Careful, calling this method will cause that only the attribute paths that are added and reachable object ids will be fetched. Other attributes will be fetched with their default value.
      Specified by:
      fetch in interface SubGraph<T>
      Type Parameters:
      X - The type of the fetched path
      Parameters:
      attribute - The attribute to fetch
      Returns:
      The sub graph for the path
    • getFetches

      public Collection<String> getFetches()
      Returns the attributes that should be fetched or an empty collection if all should be fetched.
      Returns:
      the attributes that should be fetched or an empty collection if all should be fetched
      Since:
      1.4.0