use of com.google.cloud.datastore.PathElement in project spring-cloud-gcp by spring-cloud.
the class DatastoreTemplate method validateKey.
private void validateKey(Object entity, PathElement ancestorPE) {
DatastorePersistentEntity datastorePersistentEntity = this.datastoreMappingContext.getPersistentEntity(entity.getClass());
DatastorePersistentProperty idProp = datastorePersistentEntity.getIdPropertyOrFail();
if (!TypeUtils.isAssignable(BaseKey.class, idProp.getType())) {
throw new DatastoreDataException("Only Key types are allowed for descendants id");
}
Key key = getKey(entity, false);
if (key == null || key.getAncestors().stream().anyMatch((pe) -> pe.equals(ancestorPE))) {
return;
}
throw new DatastoreDataException("Descendant object has a key without current ancestor");
}
Aggregations