Search in sources :

Example 1 with AfterQueryEvent

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

the class DatastoreTemplateTests method queryByExampleSimpleEntityTest.

@Test
public void queryByExampleSimpleEntityTest() {
    EntityQuery.Builder builder = Query.newEntityQueryBuilder().setKind("test_kind");
    StructuredQuery.CompositeFilter filter = StructuredQuery.CompositeFilter.and(PropertyFilter.eq("color", "simple_test_color"), PropertyFilter.eq("int_field", 1));
    EntityQuery query = builder.setFilter(filter).build();
    verifyBeforeAndAfterEvents(null, new AfterQueryEvent(Collections.emptyList(), query), () -> this.datastoreTemplate.queryByExample(Example.of(this.simpleTestEntity, ExampleMatcher.matching().withIgnorePaths("id")), null), x -> x.verify(this.datastore, times(1)).run(query));
}
Also used : StructuredQuery(com.google.cloud.datastore.StructuredQuery) AfterQueryEvent(org.springframework.cloud.gcp.data.datastore.core.mapping.event.AfterQueryEvent) EntityQuery(com.google.cloud.datastore.EntityQuery) Test(org.junit.Test)

Example 2 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 keyQueryByExample.

@Override
public <T> Iterable<Key> keyQueryByExample(Example<T> example, DatastoreQueryOptions queryOptions) {
    Query query = exampleToQuery(example, queryOptions, true);
    Iterable<Key> results = () -> getDatastoreReadWriter().run(query);
    maybeEmitEvent(new AfterQueryEvent(results, query));
    return results;
}
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) IncompleteKey(com.google.cloud.datastore.IncompleteKey) Key(com.google.cloud.datastore.Key) BaseKey(com.google.cloud.datastore.BaseKey)

Example 3 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 query.

@Override
public <T> DatastoreResultsIterable<T> query(Query<? extends BaseEntity> query, Class<T> entityClass) {
    QueryResults<? extends BaseEntity> results = getDatastoreReadWriter().run(query);
    List<T> convertedResults = convertEntitiesForRead(results, entityClass);
    maybeEmitEvent(new AfterQueryEvent(convertedResults, query));
    return results != null ? new DatastoreResultsIterable<>(convertedResults, results.getCursorAfter()) : null;
}
Also used : AfterQueryEvent(org.springframework.cloud.gcp.data.datastore.core.mapping.event.AfterQueryEvent)

Example 4 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 queryKeys.

@Override
public Iterable<Key> queryKeys(Query<Key> query) {
    Iterable<Key> keys = () -> getDatastoreReadWriter().run(query);
    maybeEmitEvent(new AfterQueryEvent(keys, query));
    return keys;
}
Also used : AfterQueryEvent(org.springframework.cloud.gcp.data.datastore.core.mapping.event.AfterQueryEvent) IncompleteKey(com.google.cloud.datastore.IncompleteKey) Key(com.google.cloud.datastore.Key) BaseKey(com.google.cloud.datastore.BaseKey)

Example 5 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 queryIterable.

@Override
public <A, T> DatastoreResultsIterable<T> queryIterable(Query<A> query, Function<A, T> entityFunc) {
    QueryResults<A> results = getDatastoreReadWriter().run(query);
    List resultsList = new ArrayList();
    // cursor is not populated until we iterate
    results.forEachRemaining(e -> {
        resultsList.add(entityFunc.apply(e));
    });
    DatastoreResultsIterable<T> resultsIterable = new DatastoreResultsIterable<>(resultsList, results.getCursorAfter());
    maybeEmitEvent(new AfterQueryEvent(resultsIterable, query));
    return resultsIterable;
}
Also used : AfterQueryEvent(org.springframework.cloud.gcp.data.datastore.core.mapping.event.AfterQueryEvent) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList)

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