Search in sources :

Example 1 with JsonQueryResult

use of org.infinispan.query.remote.json.JsonQueryResult in project infinispan by infinispan.

the class JsonQuerySerializer method createQueryResponse.

@Override
public JsonQueryResponse createQueryResponse(RemoteQueryResult remoteQueryResult) {
    long totalResults = remoteQueryResult.getTotalResults();
    String[] projections = remoteQueryResult.getProjections();
    JsonQueryResponse response;
    if (projections == null) {
        List<Object> results = remoteQueryResult.getResults().stream().map(o -> transcoderFromStorage.transcode(o, storageMediaTye, APPLICATION_JSON)).collect(toList());
        List<Hit> hits = results.stream().map(Hit::new).collect(Collectors.toList());
        response = new JsonQueryResult(hits, totalResults);
    } else {
        response = new ProjectedJsonResult(totalResults, projections, remoteQueryResult.getResults());
    }
    return response;
}
Also used : Transcoder(org.infinispan.commons.dataconversion.Transcoder) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) MediaType(org.infinispan.commons.dataconversion.MediaType) Hit(org.infinispan.query.remote.json.Hit) ProjectedJsonResult(org.infinispan.query.remote.json.ProjectedJsonResult) APPLICATION_JSON(org.infinispan.commons.dataconversion.MediaType.APPLICATION_JSON) JsonQueryResponse(org.infinispan.query.remote.json.JsonQueryResponse) QueryRequest(org.infinispan.query.remote.client.impl.QueryRequest) Json(org.infinispan.commons.dataconversion.internal.Json) Collectors(java.util.stream.Collectors) JsonQueryResult(org.infinispan.query.remote.json.JsonQueryResult) Hit(org.infinispan.query.remote.json.Hit) ProjectedJsonResult(org.infinispan.query.remote.json.ProjectedJsonResult) JsonQueryResult(org.infinispan.query.remote.json.JsonQueryResult) JsonQueryResponse(org.infinispan.query.remote.json.JsonQueryResponse)

Aggregations

List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Collectors.toList (java.util.stream.Collectors.toList)1 MediaType (org.infinispan.commons.dataconversion.MediaType)1 APPLICATION_JSON (org.infinispan.commons.dataconversion.MediaType.APPLICATION_JSON)1 Transcoder (org.infinispan.commons.dataconversion.Transcoder)1 Json (org.infinispan.commons.dataconversion.internal.Json)1 QueryRequest (org.infinispan.query.remote.client.impl.QueryRequest)1 Hit (org.infinispan.query.remote.json.Hit)1 JsonQueryResponse (org.infinispan.query.remote.json.JsonQueryResponse)1 JsonQueryResult (org.infinispan.query.remote.json.JsonQueryResult)1 ProjectedJsonResult (org.infinispan.query.remote.json.ProjectedJsonResult)1