Package io.jmix.core

Class SaveContext

java.lang.Object
io.jmix.core.SaveContext
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
JpaSaveContext

public class SaveContext extends Object implements Serializable
Defines collections of entities to be saved or removed, as well as parameters of saving.
See Also:
  • Field Details

    • entitiesToSave

      protected Set<Object> entitiesToSave
    • entitiesToRemove

      protected Set<Object> entitiesToRemove
    • fetchPlans

      protected Map<Object,FetchPlan> fetchPlans
    • discardSaved

      protected boolean discardSaved
    • joinTransaction

      protected boolean joinTransaction
    • accessConstraints

      protected List<AccessConstraint<?>> accessConstraints
    • hints

      protected Map<String,Serializable> hints
  • Constructor Details

    • SaveContext

      public SaveContext()
  • Method Details

    • saving

      public SaveContext saving(Object... entities)
      Adds an entity to be committed to the database.

      This method accepts entity instances and collections.

      Parameters:
      entities - entity instances
      Returns:
      this instance for chaining
    • saving

      public SaveContext saving(Object entity, @Nullable FetchPlan fetchPlan)
      Adds an entity to be committed to the database.
      Parameters:
      entity - entity instance
      fetchPlan - fetch plan which is used in merge operation to ensure all required attributes are loaded in the returned instance
      Returns:
      this instance for chaining
    • removing

      public SaveContext removing(Object... entities)
      Adds an entity to be removed from the database.

      This method accepts entity instances and collections.

      Parameters:
      entities - entity instances
      Returns:
      this instance for chaining
    • getEntitiesToSave

      public EntitySet getEntitiesToSave()
      Returns:
      collection of changed entities that will be saved to the database. The collection is modifiable.
    • getEntitiesToRemove

      public EntitySet getEntitiesToRemove()
      Returns:
      collection of entities that will be removed from the database. The collection is modifiable.
    • getFetchPlans

      public Map<Object,FetchPlan> getFetchPlans()
      Enables defining a fetchPlan for each committed entity. These fetchPlans are used in merge operation to ensure all required attributes are loaded in returned instances.
      Returns:
      mutable map of entities to their fetchPlans
    • getHints

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

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

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

      public boolean isDiscardSaved()
      Returns:
      true if calling code does not need committed instances, which allows for performance optimization
    • setDiscardSaved

      public SaveContext setDiscardSaved(boolean discardSaved)
      Set to true if calling code does not need saved instances, which allows for performance optimization.
    • getAccessConstraints

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

      public SaveContext setAccessConstraints(List<AccessConstraint<?>> accessConstraints)
      Sets the list of access constraints.
    • isJoinTransaction

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

      public SaveContext setJoinTransaction(boolean joinTransaction)
      Sets whether to join existing transaction or always start a new one.