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"); }
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"); }