Package io.jmix.core
Class EntityStates
java.lang.Object
io.jmix.core.EntityStates
Provides information about entities states.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classVisit record for an entity graph node while the current fetch plan is being built.protected static classKey for a visited entity graph node.static enumDescribes whether the property is loaded from the data store.protected static enumState of an entity graph node while constructing a current fetch plan. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected PersistentAttributesLoadCheckerprotected FetchPlanRepositoryprotected FetchPlansprotected Metadataprotected MetadataTools -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcheckLoaded(Object entity, String... properties) Check that entity has all specified properties loaded from the data store.voidcheckLoadedWithFetchPlan(Object entity, FetchPlan fetchPlan) Check that all properties of the fetch plan are loaded from the data store for the passed entity.protected voidcheckLoadedWithFetchPlan(Object entity, FetchPlan fetchPlan, Set<Object> visited) voidcheckLoadedWithFetchPlan(Object entity, String fetchPlanName) Check that all properties of the fetch plan are loaded from the data store for the passed entity.protected FetchPlanconstructCurrentFetchPlan(Entity entity, Class<?> declaredEntityClass, Map<EntityStates.FetchPlanVisitKey, EntityStates.FetchPlanVisit> fetchPlanVisits) 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 the data store.isLoadedSafe(Object entity, String property) Checks whether the property is loaded from the data store without risking fetching it.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<Object> 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.voidManages the New state of the entity instance.
-
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 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
-
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 JPA 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 JPA entity - Throws:
IllegalArgumentException- if entity instance is null
-
isLoaded
Checks if the property is loaded from the data store.Non-stored 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
-
isLoadedSafe
Checks whether the property is loaded from the data store without risking fetching it.Non-stored attributes are considered loaded if they do not have related properties, or if all related properties are loaded.
- Parameters:
entity- entityproperty- name of the property. Only immediate attributes of the entity are supported.- Returns:
EntityStates.PropertyLoadedState.YESif loaded,EntityStates.PropertyLoadedState.NOif not loaded,EntityStates.PropertyLoadedState.UNKNOWNif the loaded state cannot be determined without fetching the property
-
checkLoaded
Check that entity has all specified properties loaded from the data store. 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 the data store 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 the data store 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
-
constructCurrentFetchPlan
protected FetchPlan constructCurrentFetchPlan(Entity entity, Class<?> declaredEntityClass, Map<EntityStates.FetchPlanVisitKey, EntityStates.FetchPlanVisit> fetchPlanVisits) -
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
-
setNew
Manages the New state of the entity instance.- See Also:
-
makeDetached
Makes 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:
-
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:
-