Search in sources :

Example 11 with AttributeChangeListener

use of org.eclipse.persistence.internal.descriptors.changetracking.AttributeChangeListener in project jmix by jmix-framework.

the class EntityChangedEventManager method internalCollect.

public List<EntityChangedEventInfo> internalCollect(Collection<Object> entities) {
    List<EntityChangedEventInfo> list = new ArrayList<>();
    for (Object entity : entities) {
        EntityChangedEvent.Type type = null;
        AttributeChanges.Builder attributeChangesBuilder = null;
        if (getEntityEntry(entity).isNew()) {
            type = EntityChangedEvent.Type.CREATED;
            attributeChangesBuilder = getEntityAttributeChanges(entity, false);
        } else {
            AttributeChangeListener changeListener = (AttributeChangeListener) ((ChangeTracker) entity)._persistence_getPropertyChangeListener();
            if (changeListener == null) {
                log.debug("Cannot publish EntityChangedEvent for {} because its AttributeChangeListener is null", entity);
                continue;
            }
            if (persistenceSupport.isDeleted(entity, changeListener)) {
                type = EntityChangedEvent.Type.DELETED;
                attributeChangesBuilder = getEntityAttributeChanges(entity, true);
            } else if (changeListener.hasChanges()) {
                type = EntityChangedEvent.Type.UPDATED;
                attributeChangesBuilder = getEntityAttributeChanges(entity, changeListener.getObjectChangeSet());
            }
        }
        if (type != null && attributeChangesBuilder != null) {
            MetaClass originalMetaClass = extendedEntities.getOriginalOrThisMetaClass(metadata.getClass(entity));
            EntityChangedEventInfo eventData = new EntityChangedEventInfo(this, entity, type, attributeChangesBuilder.build(), originalMetaClass);
            list.add(eventData);
        }
    }
    log.trace("collected {}", list);
    return list;
}
Also used : EntityChangedEventInfo(io.jmix.data.impl.EntityChangedEventInfo) AttributeChanges(io.jmix.core.event.AttributeChanges) MetaClass(io.jmix.core.metamodel.model.MetaClass) EntityChangedEvent(io.jmix.core.event.EntityChangedEvent) AttributeChangeListener(org.eclipse.persistence.internal.descriptors.changetracking.AttributeChangeListener)

Example 12 with AttributeChangeListener

use of org.eclipse.persistence.internal.descriptors.changetracking.AttributeChangeListener in project jmix by jmix-framework.

the class EclipselinkAttributeChangesProvider method getChangedAttributeNamesByImplementation.

@Override
protected Set<String> getChangedAttributeNamesByImplementation(Object entity) {
    checkEntityByImplementation(entity);
    PropertyChangeListener propertyChangeListener = ((ChangeTracker) entity)._persistence_getPropertyChangeListener();
    ObjectChangeSet objectChanges = ((AttributeChangeListener) propertyChangeListener).getObjectChangeSet();
    if (objectChanges != null) {
        return new HashSet<>(objectChanges.getChangedAttributeNames());
    }
    return Collections.emptySet();
}
Also used : PropertyChangeListener(java.beans.PropertyChangeListener) AttributeChangeListener(org.eclipse.persistence.internal.descriptors.changetracking.AttributeChangeListener) ObjectChangeSet(org.eclipse.persistence.sessions.changesets.ObjectChangeSet) ChangeTracker(org.eclipse.persistence.descriptors.changetracking.ChangeTracker) HashSet(java.util.HashSet)

Aggregations

AttributeChangeListener (org.eclipse.persistence.internal.descriptors.changetracking.AttributeChangeListener)12 ChangeTracker (org.eclipse.persistence.descriptors.changetracking.ChangeTracker)9 PropertyChangeListener (java.beans.PropertyChangeListener)5 ObjectChangeSet (org.eclipse.persistence.sessions.changesets.ObjectChangeSet)3 MetaClass (com.haulmont.chile.core.model.MetaClass)2 AttributeChanges (com.haulmont.cuba.core.app.events.AttributeChanges)2 ObjectChangeSet (org.eclipse.persistence.internal.sessions.ObjectChangeSet)2 AggregateChangeRecord (org.eclipse.persistence.sessions.changesets.AggregateChangeRecord)2 ChangeRecord (org.eclipse.persistence.sessions.changesets.ChangeRecord)2 MetaProperty (com.haulmont.chile.core.model.MetaProperty)1 EntityChangedEvent (com.haulmont.cuba.core.app.events.EntityChangedEvent)1 AttributeChanges (io.jmix.core.event.AttributeChanges)1 EntityChangedEvent (io.jmix.core.event.EntityChangedEvent)1 MetaClass (io.jmix.core.metamodel.model.MetaClass)1 EntityChangedEventInfo (io.jmix.data.impl.EntityChangedEventInfo)1 HashSet (java.util.HashSet)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Nullable (org.springframework.lang.Nullable)1