use of com.google.cloud.datastore.BaseKey in project spring-cloud-gcp by spring-cloud.
the class DatastoreTemplate method convertEntitiesForRead.
private <T> List<T> convertEntitiesForRead(Iterator<? extends BaseEntity> entities, Class<T> entityClass, ReadContext context) {
if (entities == null) {
return Collections.emptyList();
}
List<BaseKey> keys = new ArrayList<>();
entities.forEachRemaining(e -> {
IncompleteKey key = e.getKey();
context.putReadEntity(key, e);
keys.add(key);
});
return convertEntitiesForRead(keys, entityClass, context);
}
use of com.google.cloud.datastore.BaseKey in project spring-cloud-gcp by spring-cloud.
the class DatastoreTemplate method findAllById.
private <T> List<T> findAllById(Set<Key> keys, Class<T> entityClass, ReadContext context) {
List<Key> missingKeys = keys.stream().filter(context::notCached).collect(Collectors.toList());
if (!missingKeys.isEmpty()) {
List<Entity> entities = getDatastoreReadWriter().fetch(missingKeys.toArray(new Key[] {}));
Assert.isTrue(missingKeys.size() == entities.size(), "Fetched incorrect number of entities");
for (int i = 0; i < missingKeys.size(); i++) {
BaseKey key = missingKeys.get(i);
context.putReadEntity(key, entities.get(i));
}
}
return convertEntitiesForRead(keys, entityClass, context);
}
Aggregations