Search in sources :

Example 6 with AfterQueryEvent

use of org.springframework.cloud.gcp.data.datastore.core.mapping.event.AfterQueryEvent in project spring-cloud-gcp by spring-cloud.

the class DatastoreTemplate method findAll.

@Override
public <T> DatastoreResultsCollection<T> findAll(Class<T> entityClass, DatastoreQueryOptions queryOptions) {
    DatastorePersistentEntity<?> persistentEntity = this.datastoreMappingContext.getPersistentEntity(entityClass);
    EntityQuery.Builder builder = Query.newEntityQueryBuilder().setKind(persistentEntity.kindName());
    applyQueryOptions(builder, queryOptions, persistentEntity);
    Query query = builder.build();
    QueryResults queryResults = getDatastoreReadWriter().run(query);
    Collection<T> convertedResults = convertEntitiesForRead(queryResults, entityClass);
    maybeEmitEvent(new AfterQueryEvent(convertedResults, query));
    return new DatastoreResultsCollection<>(convertedResults, queryResults != null ? queryResults.getCursorAfter() : null);
}
Also used : AfterQueryEvent(org.springframework.cloud.gcp.data.datastore.core.mapping.event.AfterQueryEvent) Query(com.google.cloud.datastore.Query) KeyQuery(com.google.cloud.datastore.KeyQuery) ProjectionEntityQuery(com.google.cloud.datastore.ProjectionEntityQuery) StructuredQuery(com.google.cloud.datastore.StructuredQuery) EntityQuery(com.google.cloud.datastore.EntityQuery) ProjectionEntityQuery(com.google.cloud.datastore.ProjectionEntityQuery) EntityQuery(com.google.cloud.datastore.EntityQuery) QueryResults(com.google.cloud.datastore.QueryResults)

Example 7 with AfterQueryEvent

use of org.springframework.cloud.gcp.data.datastore.core.mapping.event.AfterQueryEvent in project spring-cloud-gcp by spring-cloud.

the class DatastoreTemplate method queryKeysOrEntities.

@Override
public <T> DatastoreResultsIterable<?> queryKeysOrEntities(Query query, Class<T> entityClass) {
    QueryResults results = getDatastoreReadWriter().run(query);
    DatastoreResultsIterable resultsIterable;
    if (results.getResultClass() == Key.class) {
        resultsIterable = new DatastoreResultsIterable(results, results.getCursorAfter());
    } else {
        resultsIterable = new DatastoreResultsIterable<>(convertEntitiesForRead(results, entityClass), results.getCursorAfter());
    }
    maybeEmitEvent(new AfterQueryEvent(resultsIterable, query));
    return resultsIterable;
}
Also used : AfterQueryEvent(org.springframework.cloud.gcp.data.datastore.core.mapping.event.AfterQueryEvent) QueryResults(com.google.cloud.datastore.QueryResults)

Aggregations

AfterQueryEvent (org.springframework.cloud.gcp.data.datastore.core.mapping.event.AfterQueryEvent)7 EntityQuery (com.google.cloud.datastore.EntityQuery)3 StructuredQuery (com.google.cloud.datastore.StructuredQuery)3 BaseKey (com.google.cloud.datastore.BaseKey)2 IncompleteKey (com.google.cloud.datastore.IncompleteKey)2 Key (com.google.cloud.datastore.Key)2 KeyQuery (com.google.cloud.datastore.KeyQuery)2 ProjectionEntityQuery (com.google.cloud.datastore.ProjectionEntityQuery)2 Query (com.google.cloud.datastore.Query)2 QueryResults (com.google.cloud.datastore.QueryResults)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Test (org.junit.Test)1