Search in sources :

Example 1 with AggregateChangeRecord

use of org.eclipse.persistence.sessions.changesets.AggregateChangeRecord in project cuba by cuba-platform.

the class EntityAttributeChanges method addChanges.

public void addChanges(ObjectChangeSet changeSet) {
    if (changeSet == null)
        return;
    for (ChangeRecord changeRecord : changeSet.getChanges()) {
        changes.add(new Change(changeRecord.getAttribute(), changeRecord.getOldValue()));
        if (changeRecord instanceof AggregateChangeRecord) {
            embeddedChanges.computeIfAbsent(changeRecord.getAttribute(), s -> {
                EntityAttributeChanges embeddedChanges = new EntityAttributeChanges();
                embeddedChanges.addChanges(((AggregateChangeRecord) changeRecord).getChangedObject());
                return embeddedChanges;
            });
        }
    }
}
Also used : AggregateChangeRecord(org.eclipse.persistence.sessions.changesets.AggregateChangeRecord) AggregateChangeRecord(org.eclipse.persistence.sessions.changesets.AggregateChangeRecord) ChangeRecord(org.eclipse.persistence.sessions.changesets.ChangeRecord)

Example 2 with AggregateChangeRecord

use of org.eclipse.persistence.sessions.changesets.AggregateChangeRecord in project cuba by cuba-platform.

the class EntityAttributeChanges method addChanges.

protected void addChanges(ObjectChangeSet changeSet) {
    if (changeSet == null)
        return;
    for (ChangeRecord changeRecord : changeSet.getChanges()) {
        addChange(changeRecord.getAttribute(), changeRecord.getOldValue());
        if (changeRecord instanceof AggregateChangeRecord) {
            embeddedChanges.computeIfAbsent(changeRecord.getAttribute(), s -> {
                EntityAttributeChanges embeddedChanges = new EntityAttributeChanges();
                embeddedChanges.addChanges(((AggregateChangeRecord) changeRecord).getChangedObject());
                return embeddedChanges;
            });
        }
    }
}
Also used : AggregateChangeRecord(org.eclipse.persistence.sessions.changesets.AggregateChangeRecord) AggregateChangeRecord(org.eclipse.persistence.sessions.changesets.AggregateChangeRecord) ChangeRecord(org.eclipse.persistence.sessions.changesets.ChangeRecord)

Example 3 with AggregateChangeRecord

use of org.eclipse.persistence.sessions.changesets.AggregateChangeRecord in project cuba by cuba-platform.

the class EntityChangedEventManager method getEntityAttributeChanges.

@SuppressWarnings("unchecked")
private AttributeChanges getEntityAttributeChanges(@Nullable Entity entity, ObjectChangeSet changeSet) {
    if (changeSet == null)
        return null;
    Set<AttributeChanges.Change> changes = new HashSet<>();
    Map<String, AttributeChanges> embeddedChanges = new HashMap<>();
    for (ChangeRecord changeRecord : changeSet.getChanges()) {
        if (changeRecord instanceof AggregateChangeRecord) {
            embeddedChanges.computeIfAbsent(changeRecord.getAttribute(), s -> getEntityAttributeChanges(null, ((AggregateChangeRecord) changeRecord).getChangedObject()));
        } else {
            Object oldValue = changeRecord.getOldValue();
            if (oldValue instanceof Entity) {
                changes.add(new AttributeChanges.Change(changeRecord.getAttribute(), Id.of((Entity) oldValue)));
            } else if (oldValue instanceof Collection) {
                Collection<Entity> coll = (Collection<Entity>) oldValue;
                Collection<Id> idColl = oldValue instanceof List ? new ArrayList<>() : new LinkedHashSet<>();
                for (Entity item : coll) {
                    idColl.add(Id.of(item));
                }
                changes.add(new AttributeChanges.Change(changeRecord.getAttribute(), idColl));
            } else {
                changes.add(new AttributeChanges.Change(changeRecord.getAttribute(), oldValue));
            }
        }
    }
    addDynamicAttributeChanges(entity, changes, false);
    return new AttributeChanges(changes, embeddedChanges);
}
Also used : AttributeChanges(com.haulmont.cuba.core.app.events.AttributeChanges) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) AggregateChangeRecord(org.eclipse.persistence.sessions.changesets.AggregateChangeRecord) AggregateChangeRecord(org.eclipse.persistence.sessions.changesets.AggregateChangeRecord) ChangeRecord(org.eclipse.persistence.sessions.changesets.ChangeRecord)

Example 4 with AggregateChangeRecord

use of org.eclipse.persistence.sessions.changesets.AggregateChangeRecord in project jmix by jmix-framework.

the class EclipselinkAttributeChangesProvider method buildChanges.

protected void buildChanges(AttributeChanges.Builder builder, @Nullable ObjectChangeSet objectChangeSet, MetaClass metaClass, BiFunction<Object, MetaProperty, Object> transformer) {
    if (objectChangeSet == null)
        return;
    for (ChangeRecord changeRecord : objectChangeSet.getChanges()) {
        String propertyName = changeRecord.getAttribute();
        MetaProperty metaProperty = metaClass.getProperty(propertyName);
        builder.withChange(propertyName, transformer.apply(changeRecord.getOldValue(), metaProperty));
        if (changeRecord instanceof AggregateChangeRecord) {
            builder.withEmbedded(propertyName, embeddedBuilder -> {
                buildChanges(embeddedBuilder, ((AggregateChangeRecord) changeRecord).getChangedObject(), metaProperty.getRange().asClass(), transformer);
            });
        }
    }
}
Also used : MetaProperty(io.jmix.core.metamodel.model.MetaProperty) AggregateChangeRecord(org.eclipse.persistence.sessions.changesets.AggregateChangeRecord) AggregateChangeRecord(org.eclipse.persistence.sessions.changesets.AggregateChangeRecord) ChangeRecord(org.eclipse.persistence.sessions.changesets.ChangeRecord)

Aggregations

AggregateChangeRecord (org.eclipse.persistence.sessions.changesets.AggregateChangeRecord)4 ChangeRecord (org.eclipse.persistence.sessions.changesets.ChangeRecord)4 AttributeChanges (com.haulmont.cuba.core.app.events.AttributeChanges)1 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1