Package io.jmix.core

Class LoadContext<E>

java.lang.Object
io.jmix.core.LoadContext<E>
All Implemented Interfaces:
DataLoadContext, Serializable

public class LoadContext<E> extends Object implements DataLoadContext, Serializable
Class that defines parameters for loading entities from the database via DataManager.

Typical usage:

 LoadContext<User> context = new LoadContext(userMetaClass).setQuery(
 new LoadContext.Query("select u from sec$User u where u.login like :login")
 .setParameter("login", "a%")
 .setMaxResults(10))
 .setFetchPlan("user.browse");
 List<User> users = dataManager.loadList(context);
 

Instead of using this class directly, consider fluent interface with the entry point in UnconstrainedDataManager.load(Class).

See Also:
  • Field Details

    • metaClass

      protected MetaClass metaClass
    • query

      protected LoadContext.Query query
    • fetchPlan

      protected FetchPlan fetchPlan
    • id

      protected Object id
    • idList

      protected List<Object> idList
    • prevQueries

      protected List<LoadContext.Query> prevQueries
    • accessConstraints

      protected List<AccessConstraint<?>> accessConstraints
    • queryKey

      protected int queryKey
    • loadPartialEntities

      protected boolean loadPartialEntities
    • joinTransaction

      protected boolean joinTransaction
    • hints

      protected Map<String,Serializable> hints
    • lockMode

      protected javax.persistence.LockModeType lockMode
  • Constructor Details

    • LoadContext

      public LoadContext(MetaClass metaClass)
      Parameters:
      metaClass - metaclass of the loaded entities
    • LoadContext

      protected LoadContext()
  • Method Details

    • getEntityMetaClass

      public MetaClass getEntityMetaClass()
      Returns:
      metaclass of the loaded entities
    • getQuery

      @Nullable public LoadContext.Query getQuery()
      Returns:
      query definition
    • setQuery

      public LoadContext<E> setQuery(LoadContext.Query query)
      Parameters:
      query - query definition
      Returns:
      this instance for chaining
    • setQueryString

      public LoadContext.Query setQueryString(String queryString)
      Specified by:
      setQueryString in interface DataLoadContext
      Parameters:
      queryString - query string. Only named parameters are supported.
      Returns:
      query definition object
    • setLockMode

      public void setLockMode(javax.persistence.LockModeType lockMode)
      Specified by:
      setLockMode in interface DataLoadContext
      Parameters:
      lockMode - lock mode to be used when executing query
    • getLockMode

      @Nullable public javax.persistence.LockModeType getLockMode()
      Specified by:
      getLockMode in interface DataLoadContext
      Returns:
      lock mode to be used when executing query
    • getFetchPlan

      @Nullable public FetchPlan getFetchPlan()
      Returns:
      fetchPlan that is used for loading entities
    • setFetchPlan

      public LoadContext<E> setFetchPlan(FetchPlan fetchPlan)
      Parameters:
      fetchPlan - fetchPlan that is used for loading entities
      Returns:
      this instance for chaining
    • getId

      @Nullable public Object getId()
      Returns:
      id of an entity to be loaded
    • setId

      public LoadContext<E> setId(Object id)
      Parameters:
      id - id of an entity to be loaded
      Returns:
      this instance for chaining
    • getIds

      public List<?> getIds()
      Returns:
      identifiers of entities to be loaded
    • setIds

      public LoadContext<E> setIds(Collection<?> ids)
      Parameters:
      ids - identifiers of entities to be loaded
      Returns:
      this instance for chaining
    • getPreviousQueries

      public List<LoadContext.Query> getPreviousQueries()
      Allows to execute query on a previous query result.
      Returns:
      editable list of previous queries
    • getQueryKey

      public int getQueryKey()
      Returns:
      key of the current stack of sequential queries, which is unique for the current user session
    • setQueryKey

      public LoadContext<E> setQueryKey(int queryKey)
      Parameters:
      queryKey - key of the current stack of sequential queries, which is unique for the current user session
    • getHints

      public Map<String,Object> getHints()
      Returns:
      custom hints which are used by the query
    • setHint

      public LoadContext<E> setHint(String hintName, Serializable value)
      Sets custom hint that should be used by the query.
    • setHints

      public LoadContext<E> setHints(Map<String,Serializable> hints)
      Sets custom hints that should be used by the query.
    • isLoadPartialEntities

      public boolean isLoadPartialEntities()
      Returns:
      whether to load partial entities. When true (which is by default), some local attributes can be unfetched according to setFetchPlan(FetchPlan).

      The state of FetchPlan.loadPartialEntities() is ignored when the fetchPlan is passed to DataManager.

    • setLoadPartialEntities

      public LoadContext<E> setLoadPartialEntities(boolean loadPartialEntities)
      Whether to load partial entities. When true (which is by default), some local attributes can be unfetched according to setFetchPlan(FetchPlan).

      The state of FetchPlan.loadPartialEntities() is ignored when the fetchPlan is passed to DataManager.

    • getAccessConstraints

      public List<AccessConstraint<?>> getAccessConstraints()
      Returns directly accessible list of access constraints.
    • setAccessConstraints

      public LoadContext<E> setAccessConstraints(@Nullable Collection<AccessConstraint<?>> accessConstraints)
      Sets list of access constraints.
    • isJoinTransaction

      public boolean isJoinTransaction()
      Returns:
      whether to join existing transaction or always start a new one
    • setJoinTransaction

      public LoadContext<E> setJoinTransaction(boolean joinTransaction)
      Sets whether to join existing transaction or always start a new one.
    • copy

      public LoadContext<?> copy()
      Creates a copy of this LoadContext instance.
    • toString

      public String toString()
      Overrides:
      toString in class Object