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;
});
}
}
}
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;
});
}
}
}
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);
}
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);
});
}
}
}
Aggregations