Search in sources :

Example 1 with BaseKey

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);
}
Also used : ArrayList(java.util.ArrayList) BaseKey(com.google.cloud.datastore.BaseKey) IncompleteKey(com.google.cloud.datastore.IncompleteKey)

Example 2 with BaseKey

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);
}
Also used : FullEntity(com.google.cloud.datastore.FullEntity) BaseEntity(com.google.cloud.datastore.BaseEntity) DatastorePersistentEntity(org.springframework.cloud.gcp.data.datastore.core.mapping.DatastorePersistentEntity) Entity(com.google.cloud.datastore.Entity) BaseKey(com.google.cloud.datastore.BaseKey) IncompleteKey(com.google.cloud.datastore.IncompleteKey) Key(com.google.cloud.datastore.Key) BaseKey(com.google.cloud.datastore.BaseKey)

Aggregations

BaseKey (com.google.cloud.datastore.BaseKey)2 IncompleteKey (com.google.cloud.datastore.IncompleteKey)2 BaseEntity (com.google.cloud.datastore.BaseEntity)1 Entity (com.google.cloud.datastore.Entity)1 FullEntity (com.google.cloud.datastore.FullEntity)1 Key (com.google.cloud.datastore.Key)1 ArrayList (java.util.ArrayList)1 DatastorePersistentEntity (org.springframework.cloud.gcp.data.datastore.core.mapping.DatastorePersistentEntity)1