use of org.springframework.data.relational.core.conversion.DbAction in project spring-data-jdbc by spring-projects.
the class JdbcAggregateChangeExecutionContext method populateIdsIfNecessary.
@SuppressWarnings("unchecked")
@Nullable
<T> T populateIdsIfNecessary() {
T newRoot = null;
// have the results so that the inserts on the leaves come first.
List<DbActionExecutionResult> reverseResults = new ArrayList<>(results.values());
Collections.reverse(reverseResults);
StagedValues cascadingValues = new StagedValues();
for (DbActionExecutionResult result : reverseResults) {
DbAction<?> action = result.getAction();
if (!(action instanceof DbAction.WithGeneratedId)) {
continue;
}
DbAction.WithEntity<?> withEntity = (DbAction.WithGeneratedId<?>) action;
Object newEntity = setIdAndCascadingProperties(withEntity, result.getId(), cascadingValues);
// the id property was immutable so we have to propagate changes up the tree
if (newEntity != withEntity.getEntity()) {
if (action instanceof DbAction.Insert) {
DbAction.Insert<?> insert = (DbAction.Insert<?>) action;
Pair<?, ?> qualifier = insert.getQualifier();
cascadingValues.stage(insert.getDependingOn(), insert.getPropertyPath(), qualifier == null ? null : qualifier.getSecond(), newEntity);
} else if (action instanceof DbAction.InsertRoot) {
newRoot = (T) newEntity;
}
}
}
return newRoot;
}
Aggregations