use of org.eclipse.persistence.internal.sessions.ObjectChangeSet in project cuba by cuba-platform.
the class EntityLog method calculateDirtyFields.
protected Set<String> calculateDirtyFields(Entity entity, EntityAttributeChanges changes) {
if (changes == null) {
if (!(entity instanceof ChangeTracker) || !PersistenceHelper.isManaged(entity))
return Collections.emptySet();
PropertyChangeListener propertyChangeListener = ((ChangeTracker) entity)._persistence_getPropertyChangeListener();
if (propertyChangeListener == null)
throw new IllegalStateException("Entity '" + entity + "' is a ChangeTracker but has no PropertyChangeListener");
changes = new EntityAttributeChanges();
ObjectChangeSet objectChanges = ((AttributeChangeListener) propertyChangeListener).getObjectChangeSet();
if (objectChanges != null) {
changes.addChanges(objectChanges);
}
}
return changes.getAttributes();
}
use of org.eclipse.persistence.internal.sessions.ObjectChangeSet in project cuba by cuba-platform.
the class PersistenceTools method getDirtyFields.
/**
* 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) || !entityStates.isManaged(entity))
return Collections.emptySet();
HashSet<String> result = new HashSet<>();
if (entityStates.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 (// can be null for example in AFTER_DELETE entity listener
objectChanges != null)
result.addAll(objectChanges.getChangedAttributeNames());
}
return result;
}
Aggregations