use of org.springframework.data.relational.core.conversion.DbActionExecutionResult in project spring-data-jdbc by spring-projects.
the class JdbcAggregateChangeExecutionContext method executeInsertRoot.
<T> void executeInsertRoot(DbAction.InsertRoot<T> insert) {
RelationalPersistentEntity<T> persistentEntity = getRequiredPersistentEntity(insert.getEntityType());
Object id;
if (persistentEntity.hasVersionProperty()) {
RelationalPersistentProperty versionProperty = persistentEntity.getVersionProperty();
Assert.state(versionProperty != null, "Version property must not be null at this stage.");
long initialVersion = versionProperty.getActualType().isPrimitive() ? 1L : 0;
T rootEntity = //
RelationalEntityVersionUtils.setVersionNumberOnEntity(insert.getEntity(), initialVersion, persistentEntity, converter);
id = accessStrategy.insert(rootEntity, insert.getEntityType(), Identifier.empty());
setNewVersion(initialVersion);
} else {
id = accessStrategy.insert(insert.getEntity(), insert.getEntityType(), Identifier.empty());
}
add(new DbActionExecutionResult(insert, id));
}
use of org.springframework.data.relational.core.conversion.DbActionExecutionResult in project spring-data-jdbc by spring-projects.
the class JdbcAggregateChangeExecutionContext method getPotentialGeneratedIdFrom.
private Object getPotentialGeneratedIdFrom(DbAction.WithEntity<?> idOwningAction) {
if (idOwningAction instanceof DbAction.WithGeneratedId) {
Object generatedId;
DbActionExecutionResult dbActionExecutionResult = results.get(idOwningAction);
generatedId = dbActionExecutionResult == null ? null : dbActionExecutionResult.getId();
if (generatedId != null) {
return generatedId;
}
}
return getIdFrom(idOwningAction);
}
use of org.springframework.data.relational.core.conversion.DbActionExecutionResult in project spring-data-jdbc by spring-projects.
the class JdbcAggregateChangeExecutionContext method executeInsert.
<T> void executeInsert(DbAction.Insert<T> insert) {
Identifier parentKeys = getParentKeys(insert, converter);
Object id = accessStrategy.insert(insert.getEntity(), insert.getEntityType(), parentKeys);
add(new DbActionExecutionResult(insert, id));
}
use of org.springframework.data.relational.core.conversion.DbActionExecutionResult 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;
}
use of org.springframework.data.relational.core.conversion.DbActionExecutionResult in project spring-data-jdbc by spring-projects.
the class JdbcAggregateChangeExecutionContext method executeMerge.
<T> void executeMerge(DbAction.Merge<T> merge) {
// temporary implementation
if (!accessStrategy.update(merge.getEntity(), merge.getEntityType())) {
Object id = accessStrategy.insert(merge.getEntity(), merge.getEntityType(), getParentKeys(merge, converter));
add(new DbActionExecutionResult(merge, id));
} else {
add(new DbActionExecutionResult());
}
}
Aggregations