use of org.eclipse.persistence.internal.descriptors.changetracking.AttributeChangeListener in project jmix by jmix-framework.
the class EclipselinkAttributeChangesProvider method buildChangesByImplementation.
@Override
protected void buildChangesByImplementation(AttributeChanges.Builder builder, Object entity, BiFunction<Object, MetaProperty, Object> transformer) {
checkEntityByImplementation(entity);
PropertyChangeListener propertyChangeListener = ((ChangeTracker) entity)._persistence_getPropertyChangeListener();
ObjectChangeSet objectChanges = ((AttributeChangeListener) propertyChangeListener).getObjectChangeSet();
if (objectChanges != null) {
buildChanges(builder, objectChanges, metadata.getClass(entity), transformer);
}
}
use of org.eclipse.persistence.internal.descriptors.changetracking.AttributeChangeListener in project jmix by jmix-framework.
the class EclipselinkPersistenceSupport method beforeStore.
protected void beforeStore(ContainerResourceHolder container, EntityVisitor visitor, Collection<Object> instances, Set<Object> processed, boolean warnAboutImplicitFlush) {
boolean possiblyChanged = false;
Set<Object> withoutPossibleChanges = createEntitySet();
for (Object entity : instances) {
processed.add(entity);
if (!(entity instanceof ChangeTracker))
continue;
boolean result = visitor.visit(entity);
if (!result) {
withoutPossibleChanges.add(entity);
}
possiblyChanged = result || possiblyChanged;
}
if (!possiblyChanged)
return;
if (warnAboutImplicitFlush) {
if (implicitFlushLog.isTraceEnabled()) {
implicitFlushLog.trace("Implicit flush due to query execution, see stack trace for the cause:\n" + StackTrace.asString());
} else {
implicitFlushLog.debug("Implicit flush due to query execution");
}
}
Collection<Object> afterProcessing = container.getAllInstances();
if (afterProcessing.size() > processed.size()) {
afterProcessing.removeAll(processed);
beforeStore(container, visitor, afterProcessing, processed, false);
}
if (!withoutPossibleChanges.isEmpty()) {
afterProcessing = withoutPossibleChanges.stream().filter(instance -> {
ChangeTracker changeTracker = (ChangeTracker) instance;
AttributeChangeListener changeListener = (AttributeChangeListener) changeTracker._persistence_getPropertyChangeListener();
return changeListener != null && changeListener.hasChanges();
}).collect(Collectors.toList());
if (!afterProcessing.isEmpty()) {
beforeStore(container, visitor, afterProcessing, processed, false);
}
}
}
use of org.eclipse.persistence.internal.descriptors.changetracking.AttributeChangeListener in project cuba by cuba-platform.
the class EntityAttributeChanges method addChanges.
/**
* Accumulates changes for the entity. Stores changed attribute names and old values.
*/
public void addChanges(Entity entity) {
if (!(entity instanceof ChangeTracker))
return;
AttributeChangeListener changeListener = (AttributeChangeListener) ((ChangeTracker) entity)._persistence_getPropertyChangeListener();
if (changeListener == null)
return;
addChanges(changeListener.getObjectChangeSet());
}
use of org.eclipse.persistence.internal.descriptors.changetracking.AttributeChangeListener 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;
}
use of org.eclipse.persistence.internal.descriptors.changetracking.AttributeChangeListener in project cuba by cuba-platform.
the class PersistenceImplSupport method beforeStore.
protected void beforeStore(ContainerResourceHolder container, EntityVisitor visitor, Collection<Entity> instances, Set<Entity> processed, boolean warnAboutImplicitFlush) {
boolean possiblyChanged = false;
Set<Entity> withoutPossibleChanges = createEntitySet();
for (Entity instance : instances) {
processed.add(instance);
if (!(instance instanceof ChangeTracker && instance instanceof BaseGenericIdEntity))
continue;
BaseGenericIdEntity entity = (BaseGenericIdEntity) instance;
boolean result = visitor.visit(entity);
if (!result) {
withoutPossibleChanges.add(instance);
}
possiblyChanged = result || possiblyChanged;
}
if (!possiblyChanged)
return;
if (warnAboutImplicitFlush) {
statisticsAccumulator.incImplicitFlushCount();
if (implicitFlushLog.isTraceEnabled()) {
implicitFlushLog.trace("Implicit flush due to query execution, see stack trace for the cause:\n" + StackTrace.asString());
} else {
implicitFlushLog.debug("Implicit flush due to query execution");
}
}
Collection<Entity> afterProcessing = container.getAllInstances();
if (afterProcessing.size() > processed.size()) {
afterProcessing.removeAll(processed);
beforeStore(container, visitor, afterProcessing, processed, false);
}
if (!withoutPossibleChanges.isEmpty()) {
afterProcessing = withoutPossibleChanges.stream().filter(instance -> {
ChangeTracker changeTracker = (ChangeTracker) instance;
AttributeChangeListener changeListener = (AttributeChangeListener) changeTracker._persistence_getPropertyChangeListener();
return changeListener != null && changeListener.hasChanges();
}).collect(Collectors.toList());
if (!afterProcessing.isEmpty()) {
beforeStore(container, visitor, afterProcessing, processed, false);
}
}
}
Aggregations