Search in sources :

Example 1 with QueryOperation

use of io.spine.server.tenant.QueryOperation in project core-java by SpineEventEngine.

the class Stand method execute.

/**
 * Reads a particular set of items from the read-side of the application and
 * feed the result into an instance.
 *
 * <p>{@link Query} defines the query target and the expected detail level for response.
 *
 * <p>The query results are fed to an instance
 * of {@link StreamObserver}&lt;{@link QueryResponse}&gt;.
 *
 * @param query            an instance of query
 * @param responseObserver an observer to feed the query results to.
 */
public void execute(final Query query, final StreamObserver<QueryResponse> responseObserver) {
    queryValidator.validate(query, responseObserver);
    final TypeUrl type = Queries.typeOf(query);
    final QueryProcessor queryProcessor = processorFor(type);
    final QueryOperation op = new QueryOperation(query) {

        @Override
        public void run() {
            final ImmutableCollection<Any> readResult = queryProcessor.process(query());
            final QueryResponse response = QueryResponse.newBuilder().addAllMessages(readResult).setResponse(Responses.ok()).build();
            responseObserver.onNext(response);
            responseObserver.onCompleted();
        }
    };
    op.execute();
}
Also used : QueryResponse(io.spine.client.QueryResponse) TypeUrl(io.spine.type.TypeUrl) TypeConverter.toAny(io.spine.protobuf.TypeConverter.toAny) Any(com.google.protobuf.Any) QueryOperation(io.spine.server.tenant.QueryOperation)

Aggregations

Any (com.google.protobuf.Any)1 QueryResponse (io.spine.client.QueryResponse)1 TypeConverter.toAny (io.spine.protobuf.TypeConverter.toAny)1 QueryOperation (io.spine.server.tenant.QueryOperation)1 TypeUrl (io.spine.type.TypeUrl)1