@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 |
|---|---|
protected EntityStates |
entityStates |
protected Metadata |
metadata |
static java.lang.String |
NAME |
protected Persistence |
persistence |
| 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).
|
com.haulmont.chile.core.datatypes.impl.EnumClass |
getOldEnumValue(Entity entity,
java.lang.String attribute)
Returns an old value of an enum attribute changed in the current transaction.
|
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
@Inject protected Persistence persistence
@Inject protected Metadata metadata
@Inject protected EntityStates entityStates
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)
isDirty(Entity, String...) method.entity - entity instanceattribute - attribute namejava.lang.IllegalArgumentException - if the entity is not persistent or not in the Managed stategetOldEnumValue(Entity, String),
isDirty(Entity, String...),
getDirtyFields(Entity)@Nullable public com.haulmont.chile.core.datatypes.impl.EnumClass getOldEnumValue(Entity entity, java.lang.String attribute)
Unlike getOldValue(Entity, String), returns enum value and not its id.
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)
If the view does not contain the reference and 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