@Component(value="cuba_EntityStates")
public class EntityStates
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected PersistentAttributesLoadChecker |
checker |
protected MetadataTools |
metadataTools |
static java.lang.String |
NAME |
protected ViewRepository |
viewRepository |
Constructor and Description |
---|
EntityStates() |
Modifier and Type | Method and Description |
---|---|
void |
checkLoaded(java.lang.Object entity,
java.lang.String... properties)
Check that entity has all specified properties loaded from DB.
|
void |
checkLoadedWithView(Entity entity,
java.lang.String viewName)
Check that all properties of the view are loaded from DB for the passed entity.
|
void |
checkLoadedWithView(Entity entity,
View view)
Check that all properties of the view are loaded from DB for the passed entity.
|
protected void |
checkLoadedWithView(Entity entity,
View view,
java.util.Set<Entity> visited) |
java.lang.String |
getEntityName(java.lang.Class<?> entityClass)
Deprecated.
|
boolean |
isDeleted(java.lang.Object entity)
Determines whether the entity instance was deleted.
|
boolean |
isDetached(java.lang.Object entity)
Determines whether the instance is Detached, i.e.
|
boolean |
isLoaded(java.lang.Object entity,
java.lang.String property)
Checks if the property is loaded from DB.
|
boolean |
isLoadedWithView(Entity entity,
java.lang.String viewName)
Check that all properties of the view are loaded from DB for the passed entity.
|
boolean |
isLoadedWithView(Entity entity,
View view)
Check that all properties of the view are loaded from DB for the passed entity.
|
protected boolean |
isLoadedWithView(Entity entity,
View view,
java.util.Set<Entity> visited) |
boolean |
isManaged(java.lang.Object entity)
Determines whether the instance is Managed, i.e.
|
boolean |
isNew(java.lang.Object entity)
Determines whether the instance is New, i.e.
|
boolean |
isSoftDeleted(java.lang.Class entityClass)
Deprecated.
|
void |
makeDetached(BaseGenericIdEntity entity)
Makes a newly constructed object detached.
|
void |
makePatch(BaseGenericIdEntity entity)
Makes a newly constructed object a patch object.
|
public static final java.lang.String NAME
@Inject protected PersistentAttributesLoadChecker checker
@Inject protected ViewRepository viewRepository
@Inject protected MetadataTools metadataTools
public boolean isNew(java.lang.Object entity)
entity
- entity instancejava.lang.IllegalArgumentException
- if entity instance is nullpublic boolean isManaged(java.lang.Object entity)
entity
- entity instancejava.lang.IllegalArgumentException
- if entity instance is nullpublic boolean isDetached(java.lang.Object entity)
entity
- entity instancejava.lang.IllegalArgumentException
- if entity instance is null@Deprecated public java.lang.String getEntityName(java.lang.Class<?> entityClass)
MetadataTools.getEntityName(Class)
instead.@Deprecated public boolean isSoftDeleted(java.lang.Class entityClass)
MetadataTools.isSoftDeleted(java.lang.Class)
instead.public boolean isLoaded(java.lang.Object entity, java.lang.String property)
Non-persistent attributes are considered loaded if they do not have related properties, or all related properties are loaded.
entity
- entityproperty
- name of the property. Only immediate attributes of the entity are supported.public void checkLoaded(java.lang.Object entity, java.lang.String... properties)
entity
- entityproperties
- property namesjava.lang.IllegalArgumentException
- if at least one of properties is not loadedprotected void checkLoadedWithView(Entity entity, View view, java.util.Set<Entity> visited)
public void checkLoadedWithView(Entity entity, View view)
entity
- entityview
- viewjava.lang.IllegalArgumentException
- if at least one of properties is not loadedpublic void checkLoadedWithView(Entity entity, java.lang.String viewName)
entity
- entityviewName
- view namejava.lang.IllegalArgumentException
- if at least one of properties is not loadedprotected boolean isLoadedWithView(Entity entity, View view, java.util.Set<Entity> visited)
public boolean isLoadedWithView(Entity entity, View view)
entity
- entityview
- view namepublic boolean isLoadedWithView(Entity entity, java.lang.String viewName)
entity
- entityviewName
- view namepublic boolean isDeleted(java.lang.Object entity)
entity
- entity instancejava.lang.IllegalArgumentException
- if entity instance is nullpublic void makeDetached(BaseGenericIdEntity entity)
DataManager.commit()
or
to EntityManager.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.
entity
- entity in the New statejava.lang.IllegalStateException
- if the entity is ManagedisDetached(Object)
,
makePatch(BaseGenericIdEntity)
public void makePatch(BaseGenericIdEntity entity)
!isNew() && !isDetached() && !isManaged()
.
The patch object can be passed to DataManager.commit()
or
to EntityManager.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.
entity
- entity in the New or Detached statejava.lang.IllegalStateException
- if the entity is ManagedisDetached(Object)
,
makeDetached(BaseGenericIdEntity)