@Component(value="cuba_PersistenceTools")
public class PersistenceTools
extends java.lang.Object
Persistence.getTools()
method.Modifier and Type | Class and Description |
---|---|
static class |
PersistenceTools.RefId
A wrapper for the reference ID value returned by
getReferenceId(BaseGenericIdEntity, String) method. |
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
NAME |
Constructor and Description |
---|
PersistenceTools() |
Modifier and Type | Method and Description |
---|---|
java.util.Set<java.lang.String> |
getDirtyFields(Entity entity)
Returns the set of dirty attributes (changed since the last load from the database).
|
java.lang.Object |
getOldValue(Entity entity,
java.lang.String attribute)
Returns an old value of an attribute changed in the current transaction.
|
PersistenceTools.RefId |
getReferenceId(BaseGenericIdEntity entity,
java.lang.String property)
Returns an ID of directly referenced entity without loading it from DB.
|
boolean |
isDirty(Entity entity)
Returns true if the given entity has dirty attributes (changed since the last load from the database).
|
boolean |
isDirty(Entity entity,
java.lang.String... attributes)
Returns true if at least one of the given attributes is dirty (i.e.
|
boolean |
isLoaded(java.lang.Object entity,
java.lang.String property)
Checks if the property is loaded from DB.
|
public static final java.lang.String NAME
public java.util.Set<java.lang.String> getDirtyFields(Entity entity)
If the entity is new, returns all its attributes.
If the entity is not persistent or not in the Managed state, returns empty set.
entity
- entity instanceisDirty(Entity, String...)
public boolean isDirty(Entity entity)
entity
- entity instancegetDirtyFields(Entity)
,
isDirty(Entity, String...)
public boolean isDirty(Entity entity, java.lang.String... attributes)
If the entity is new, always returns true.
If the entity is not persistent or not in the Managed state, always returns false.
entity
- entity instanceattributes
- attributes to checkgetDirtyFields(Entity)
@Nullable public java.lang.Object getOldValue(Entity entity, java.lang.String attribute)
entity
- entity instanceattribute
- attribute namejava.lang.IllegalArgumentException
- if the entity is not persistent or not in the Managed statepublic boolean isLoaded(java.lang.Object entity, java.lang.String property)
entity
- entityproperty
- name of the propertypublic PersistenceTools.RefId getReferenceId(BaseGenericIdEntity entity, java.lang.String property)
View.loadPartialEntities()
is true,
the returned PersistenceTools.RefId
will have PersistenceTools.RefId.isLoaded()
= false.
Usage example:
PersistenceTools.RefId refId = persistenceTools.getReferenceId(doc, "currency"); if (refId.isLoaded()) { String currencyCode = (String) refId.getValue(); }
entity
- entity instance in managed stateproperty
- name of reference propertyPersistenceTools.RefId
instance which contains the referenced entity IDjava.lang.IllegalArgumentException
- if the specified property is not a referencejava.lang.IllegalStateException
- if the entity is not in Managed statejava.lang.RuntimeException
- if anything goes wrong when retrieving the ID