本文整理汇总了Java中com.haulmont.cuba.core.global.PersistenceHelper.isManaged方法的典型用法代码示例。如果您正苦于以下问题:Java PersistenceHelper.isManaged方法的具体用法?Java PersistenceHelper.isManaged怎么用?Java PersistenceHelper.isManaged使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.haulmont.cuba.core.global.PersistenceHelper
的用法示例。
在下文中一共展示了PersistenceHelper.isManaged方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDirtyFields
import com.haulmont.cuba.core.global.PersistenceHelper; //导入方法依赖的package包/类
/**
* Returns the set of dirty attributes (changed since the last load from the database).
* <p> If the entity is new, returns all its attributes.
* <p> If the entity is not persistent or not in the Managed state, returns empty set.
*
* @param entity entity instance
* @return dirty attribute names
* @see #isDirty(Entity, String...)
*/
public Set<String> getDirtyFields(Entity entity) {
Preconditions.checkNotNullArgument(entity, "entity is null");
if (!(entity instanceof ChangeTracker) || !PersistenceHelper.isManaged(entity))
return Collections.emptySet();
HashSet<String> result = new HashSet<>();
if (PersistenceHelper.isNew(entity)) {
for (MetaProperty property : metadata.getClassNN(entity.getClass()).getProperties()) {
if (metadata.getTools().isPersistent(property))
result.add(property.getName());
}
} else {
PropertyChangeListener propertyChangeListener = ((ChangeTracker) entity)._persistence_getPropertyChangeListener();
if (propertyChangeListener == null)
throw new IllegalStateException("Entity '" + entity + "' is a ChangeTracker but has no PropertyChangeListener");
ObjectChangeSet objectChanges = ((AttributeChangeListener) propertyChangeListener).getObjectChangeSet();
if (objectChanges != null) // can be null for example in AFTER_DELETE entity listener
result.addAll(objectChanges.getChangedAttributeNames());
}
return result;
}
示例2: getOldValue
import com.haulmont.cuba.core.global.PersistenceHelper; //导入方法依赖的package包/类
/**
* Returns an old value of an attribute changed in the current transaction. The entity must be in the Managed state.
* @param entity entity instance
* @param attribute attribute name
* @return an old value stored in the database. For a new entity returns null.
* @throws IllegalArgumentException if the entity is not persistent or not in the Managed state
*/
@Nullable
public Object getOldValue(Entity entity, String attribute) {
Preconditions.checkNotNullArgument(entity, "entity is null");
if (!(entity instanceof ChangeTracker) || !PersistenceHelper.isManaged(entity))
throw new IllegalArgumentException("The entity " + entity + " is not a ChangeTracker");
if (!PersistenceHelper.isManaged(entity))
throw new IllegalArgumentException("The entity " + entity + " is not in the Managed state");
if (PersistenceHelper.isNew(entity)) {
return null;
} else {
ObjectChangeSet objectChanges =
((AttributeChangeListener)((ChangeTracker) entity)._persistence_getPropertyChangeListener()).getObjectChangeSet();
if (objectChanges != null) { // can be null for example in AFTER_DELETE entity listener
ChangeRecord changeRecord = objectChanges.getChangesForAttributeNamed(attribute);
if (changeRecord != null)
return changeRecord.getOldValue();
}
}
return null;
}
示例3: isDirty
import com.haulmont.cuba.core.global.PersistenceHelper; //导入方法依赖的package包/类
/**
* Returns true if the given entity has dirty attributes (changed since the last load from the database).
* <br> If the entity is new, returns true.
* <br> If the entity is not persistent or not in the Managed state, returns false.
*
* @param entity entity instance
*
* @see #getDirtyFields(Entity)
* @see #isDirty(Entity, String...)
*/
public boolean isDirty(Entity entity) {
Preconditions.checkNotNullArgument(entity, "entity is null");
if (!(entity instanceof ChangeTracker) || !PersistenceHelper.isManaged(entity))
return false;
if (PersistenceHelper.isNew(entity))
return true;
AttributeChangeListener attributeChangeListener = (AttributeChangeListener) ((ChangeTracker) entity)._persistence_getPropertyChangeListener();
return attributeChangeListener != null && attributeChangeListener.hasChanges();
}