use of com.google.cloud.datastore.FullEntity.Builder in project spring-cloud-gcp by spring-cloud.
the class TwoStepsConversions method applyEntityValueBuilder.
private EntityValue applyEntityValueBuilder(Object val, String kindName, Consumer<Builder> consumer, boolean createKey) {
FullEntity.Builder<IncompleteKey> builder;
if (!createKey) {
builder = FullEntity.newBuilder();
} else {
/* The following does 3 sequential null checks. We only want an ID value if the object isn't null,
has an ID property, and the ID property isn't null.
* */
Optional idProp = Optional.ofNullable(val).map(v -> this.datastoreMappingContext.getPersistentEntity(v.getClass())).map(datastorePersistentEntity -> datastorePersistentEntity.getIdProperty()).map(id -> this.datastoreMappingContext.getPersistentEntity(val.getClass()).getPropertyAccessor(val).getProperty(id));
IncompleteKey key = idProp.isPresent() ? this.objectToKeyFactory.getKeyFromId(idProp.get(), kindName) : this.objectToKeyFactory.getIncompleteKey(kindName);
builder = FullEntity.newBuilder(key);
}
consumer.accept(builder);
return EntityValue.of(builder.build());
}
Aggregations