use of org.eclipse.persistence.sessions.changesets.ChangeRecord 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.ChangeRecord in project cuba by cuba-platform.
the class EntityChangedEventManager method addDynamicAttributeChanges.
@SuppressWarnings("unchecked")
private void addDynamicAttributeChanges(@Nullable Entity entity, Set<AttributeChanges.Change> changes, boolean deleted) {
if (entity instanceof BaseGenericIdEntity && ((BaseGenericIdEntity) entity).getDynamicAttributes() != null) {
Map<String, CategoryAttributeValue> dynamicAttributes = ((BaseGenericIdEntity) entity).getDynamicAttributes();
if (dynamicAttributes == null) {
throw new RuntimeException("Entity dynamicAttributes is null");
}
for (CategoryAttributeValue cav : dynamicAttributes.values()) {
if (BaseEntityInternalAccess.isNew(cav)) {
changes.add(new AttributeChanges.Change(DynamicAttributesUtils.encodeAttributeCode(cav.getCode()), null));
} else {
if (deleted) {
Object oldValue;
switch(cav.getCategoryAttribute().getDataType()) {
case STRING:
case ENUMERATION:
oldValue = cav.getStringValue();
break;
case INTEGER:
oldValue = cav.getIntValue();
break;
case DOUBLE:
oldValue = cav.getDoubleValue();
break;
case DECIMAL:
oldValue = cav.getDecimalValue();
break;
case BOOLEAN:
oldValue = cav.getBooleanValue();
break;
case DATE_WITHOUT_TIME:
oldValue = cav.getDateWithoutTimeValue();
break;
case DATE:
oldValue = cav.getDateValue();
break;
case ENTITY:
Object entityId = cav.getEntityValue().getObjectEntityId();
Class entityClass = cav.getCategoryAttribute().getJavaClassForEntity();
oldValue = entityId != null ? Id.of(entityId, entityClass) : null;
break;
default:
log.warn("Unsupported dynamic attribute type: " + cav.getCategoryAttribute().getDataType());
oldValue = null;
}
changes.add(new AttributeChanges.Change(DynamicAttributesUtils.encodeAttributeCode(cav.getCode()), oldValue));
} else {
AttributeChangeListener changeListener = (AttributeChangeListener) ((ChangeTracker) cav)._persistence_getPropertyChangeListener();
if (changeListener != null && changeListener.getObjectChangeSet() != null) {
Object oldValue = null;
boolean changed = false;
for (ChangeRecord changeRecord : changeListener.getObjectChangeSet().getChanges()) {
switch(changeRecord.getAttribute()) {
case "stringValue":
case "intValue":
case "doubleValue":
case "decimalValue":
case "booleanValue":
case "dateWithoutTimeValue":
case "dateValue":
oldValue = changeRecord.getOldValue();
changed = true;
break;
case "entityValue":
Object entityId = ((ReferenceToEntity) changeRecord.getOldValue()).getObjectEntityId();
Class entityClass = cav.getCategoryAttribute().getJavaClassForEntity();
oldValue = entityId != null ? Id.of(entityId, entityClass) : null;
changed = true;
break;
}
if (changed) {
changes.add(new AttributeChanges.Change(DynamicAttributesUtils.encodeAttributeCode(cav.getCode()), oldValue));
break;
}
}
}
}
}
}
}
}
use of org.eclipse.persistence.sessions.changesets.ChangeRecord in project jmix by jmix-framework.
the class EclipselinkAttributeChangesProvider method getOldValueByImplementation.
@Override
@Nullable
protected Object getOldValueByImplementation(Object entity, String attribute) {
checkEntityByImplementation(entity);
PropertyChangeListener propertyChangeListener = ((ChangeTracker) entity)._persistence_getPropertyChangeListener();
ObjectChangeSet objectChanges = ((AttributeChangeListener) propertyChangeListener).getObjectChangeSet();
if (objectChanges != null) {
ChangeRecord changeRecord = objectChanges.getChangesForAttributeNamed(attribute);
if (changeRecord != null) {
return changeRecord.getOldValue();
}
}
return null;
}
use of org.eclipse.persistence.sessions.changesets.ChangeRecord 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.ChangeRecord 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);
}
Aggregations