Package io.jmix.core
Class EntityStates
java.lang.Object
io.jmix.core.EntityStates
Provides information about entities states.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected PersistentAttributesLoadCheckerprotected FetchPlanRepositoryprotected FetchPlansprotected Metadataprotected MetadataTools
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidcheckLoaded(Object entity, String... properties) Check that entity has all specified properties loaded from DB.voidcheckLoadedWithFetchPlan(Object entity, FetchPlan fetchPlan) Check that all properties of the fetch plan are loaded from DB for the passed entity.protected voidcheckLoadedWithFetchPlan(Object entity, FetchPlan fetchPlan, Set visited) voidcheckLoadedWithFetchPlan(Object entity, String fetchPlanName) Check that all properties of the fetch plan are loaded from DB for the passed entity.getCurrentFetchPlan(Object entity) Returns a fetch plan that corresponds to the loaded attributes of the given entity instance.booleanDetermines whether the entity instance was deleted.booleanisDetached(Object entity) Determines whether the instance is Detached, i.e.booleanChecks if the property is loaded from DB.booleanisLoadedWithFetchPlan(Object entity, FetchPlan fetchPlan) Check that all properties of the fetch plan are loaded from DB for the passed entity.protected booleanisLoadedWithFetchPlan(Object entity, FetchPlan fetchPlan, Set visited) booleanisLoadedWithFetchPlan(Object entity, String fetchPlanName) Check that all properties of the fetch plan are loaded from DB for the passed entity.booleanDetermines whether the instance is Managed, i.e.booleanDetermines whether the instance is New, i.e.voidmakeDetached(Object entity) Makes a newly constructed object detached.voidMakes a newly constructed object a patch object.protected voidrecursivelyConstructCurrentFetchPlan(Entity entity, FetchPlanBuilder builder, HashSet<Object> visited) voidManages the New state of the entity instance.
- 
Field Details- 
checker
- 
fetchPlanRepository
- 
metadataTools
- 
metadata
- 
fetchPlans
 
- 
- 
Constructor Details- 
EntityStatespublic EntityStates()
 
- 
- 
Method Details- 
isNewDetermines whether the instance is New, i.e. just created and not stored in database yet.- Parameters:
- entity- entity instance
- Returns:
- - true if the instance is a new JPA entity, or if it is actually in Managed state
 but newly-persisted in this transaction 
 - true if the instance is not a JPA entity
 - false otherwise
- Throws:
- IllegalArgumentException- if entity instance is null
 
- 
isManagedDetermines whether the instance is Managed, i.e. attached to a persistence context.- Parameters:
- entity- entity instance
- Returns:
- - true if the instance is managed,
 - false if it is New (and not yet persisted) or Detached, or if it is not a JPA entity
- Throws:
- IllegalArgumentException- if entity instance is null
 
- 
isDetachedDetermines whether the instance is Detached, i.e. stored in database but not attached to a persistence context at the moment.- Parameters:
- entity- entity instance
- Returns:
- - true if the instance is detached,
 - false if it is New or Managed, or if it is not a JPA entity
- Throws:
- IllegalArgumentException- if entity instance is null
 
- 
isLoadedChecks if the property is loaded from DB.Non-persistent attributes are considered loaded if they do not have related properties, or all related properties are loaded. - Parameters:
- entity- entity
- property- name of the property. Only immediate attributes of the entity are supported.
- Returns:
- true if loaded
 
- 
checkLoadedCheck that entity has all specified properties loaded from DB. Throw exception if property is not loaded.- Parameters:
- entity- entity
- properties- property names
- Throws:
- IllegalArgumentException- if at least one of properties is not loaded
 
- 
checkLoadedWithFetchPlan
- 
checkLoadedWithFetchPlanCheck that all properties of the fetch plan are loaded from DB for the passed entity. Throws exception if some property is not loaded.- Parameters:
- entity- entity
- fetchPlan- fetch plan
- Throws:
- IllegalArgumentException- if at least one of properties is not loaded
 
- 
checkLoadedWithFetchPlanCheck that all properties of the fetch plan are loaded from DB for the passed entity. Throws exception if some property is not loaded.- Parameters:
- entity- entity
- fetchPlanName- fetch plan name
- Throws:
- IllegalArgumentException- if at least one of properties is not loaded
 
- 
isLoadedWithFetchPlan
- 
isLoadedWithFetchPlanCheck that all properties of the fetch plan are loaded from DB for the passed entity.- Parameters:
- entity- entity
- fetchPlan- fetch plan
- Returns:
- false if at least one of properties is not loaded
 
- 
isLoadedWithFetchPlanCheck that all properties of the fetch plan are loaded from DB for the passed entity.- Parameters:
- entity- entity
- fetchPlanName- fetch plan name
- Returns:
- false if at least one of properties is not loaded
 
- 
getCurrentFetchPlanReturns a fetch plan that corresponds to the loaded attributes of the given entity instance.- Parameters:
- entity- entity instance
- Returns:
- fetch plan
 
- 
recursivelyConstructCurrentFetchPlanprotected void recursivelyConstructCurrentFetchPlan(Entity entity, FetchPlanBuilder builder, HashSet<Object> visited) 
- 
isDeletedDetermines whether the entity instance was deleted.- Parameters:
- entity- entity instance
- Returns:
- - true if the instance was deleted - false otherwise
- Throws:
- IllegalArgumentException- if entity instance is null
 
- 
setNewManages the New state of the entity instance.- See Also:
 
- 
makeDetachedMakes a newly constructed object detached. The detached object can be passed toDataManager.save()or toEntityManager.merge()to save its state to the database.If an object with such ID does not exist in the database, a new object will be inserted. If the entity is Versioned, the version attribute should be equal to the latest version existing in the database, or null for a new object.- Parameters:
- entity- entity in the New state
- Throws:
- IllegalStateException- if the entity is Managed
- See Also:
 
- 
makePatchMakes a newly constructed object a patch object. The patch object is!isNew() && !isDetached() && !isManaged(). The patch object can be passed toDataManager.commit()or toEntityManager.merge()to save its state to the database. Only non-null values of attributes are updated.If an object with such ID does not exist in the database, a new object will be inserted. If the entity is Versioned, the version attribute should be null or equal to the latest version existing in the database.- Parameters:
- entity- entity in the New or Detached state
- Throws:
- IllegalStateException- if the entity is Managed
- See Also:
 
 
-