Package io.jmix.core
Class EntityStates
java.lang.Object
io.jmix.core.EntityStates
Provides information about entities states.
-
Field Summary
Modifier and TypeFieldDescriptionprotected PersistentAttributesLoadChecker
protected FetchPlanRepository
protected FetchPlans
protected Metadata
protected MetadataTools
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
checkLoaded
(Object entity, String... properties) Check that entity has all specified properties loaded from DB.void
checkLoadedWithFetchPlan
(Object entity, FetchPlan fetchPlan) Check that all properties of the fetch plan are loaded from DB for the passed entity.protected void
checkLoadedWithFetchPlan
(Object entity, FetchPlan fetchPlan, Set visited) void
checkLoadedWithFetchPlan
(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.boolean
Determines whether the entity instance was deleted.boolean
isDetached
(Object entity) Determines whether the instance is Detached, i.e.boolean
Checks if the property is loaded from DB.boolean
isLoadedWithFetchPlan
(Object entity, FetchPlan fetchPlan) Check that all properties of the fetch plan are loaded from DB for the passed entity.protected boolean
isLoadedWithFetchPlan
(Object entity, FetchPlan fetchPlan, Set visited) boolean
isLoadedWithFetchPlan
(Object entity, String fetchPlanName) Check that all properties of the fetch plan are loaded from DB for the passed entity.boolean
Determines whether the instance is Managed, i.e.boolean
Determines whether the instance is New, i.e.void
makeDetached
(Object entity) Makes a newly constructed object detached.void
Makes a newly constructed object a patch object.protected void
recursivelyConstructCurrentFetchPlan
(Entity entity, FetchPlanBuilder builder, HashSet<Object> visited)
-
Field Details
-
checker
-
fetchPlanRepository
-
metadataTools
-
metadata
-
fetchPlans
-
-
Constructor Details
-
EntityStates
public EntityStates()
-
-
Method Details
-
isNew
Determines 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 persistent entity, or if it is actually in Managed state
but newly-persisted in this transaction
- true if the instance is a new non-persistent entity never returned from DataManager
- false otherwise - Throws:
IllegalArgumentException
- if entity instance is null
-
isManaged
Determines 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 persistent entity - Throws:
IllegalArgumentException
- if entity instance is null
-
isDetached
Determines 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 persistent entity - Throws:
IllegalArgumentException
- if entity instance is null
-
isLoaded
Checks 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
- entityproperty
- name of the property. Only immediate attributes of the entity are supported.- Returns:
- true if loaded
-
checkLoaded
Check that entity has all specified properties loaded from DB. Throw exception if property is not loaded.- Parameters:
entity
- entityproperties
- property names- Throws:
IllegalArgumentException
- if at least one of properties is not loaded
-
checkLoadedWithFetchPlan
-
checkLoadedWithFetchPlan
Check 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
- entityfetchPlan
- fetch plan- Throws:
IllegalArgumentException
- if at least one of properties is not loaded
-
checkLoadedWithFetchPlan
Check 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
- entityfetchPlanName
- fetch plan name- Throws:
IllegalArgumentException
- if at least one of properties is not loaded
-
isLoadedWithFetchPlan
-
isLoadedWithFetchPlan
Check that all properties of the fetch plan are loaded from DB for the passed entity.- Parameters:
entity
- entityfetchPlan
- fetch plan- Returns:
- false if at least one of properties is not loaded
-
isLoadedWithFetchPlan
Check that all properties of the fetch plan are loaded from DB for the passed entity.- Parameters:
entity
- entityfetchPlanName
- fetch plan name- Returns:
- false if at least one of properties is not loaded
-
getCurrentFetchPlan
Returns a fetch plan that corresponds to the loaded attributes of the given entity instance.- Parameters:
entity
- entity instance- Returns:
- fetch plan
-
recursivelyConstructCurrentFetchPlan
protected void recursivelyConstructCurrentFetchPlan(Entity entity, FetchPlanBuilder builder, HashSet<Object> visited) -
isDeleted
Determines 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
-
makeDetached
Makes a newly constructed object detached. The detached object can be passed toDataManager.commit()
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:
-
makePatch
Makes 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:
-