Search in sources :

Example 1 with QueryResponse

use of org.infinispan.query.remote.client.impl.QueryResponse in project infinispan by infinispan.

the class DefaultQuerySerializer method createQueryResponse.

@Override
public QueryResponse createQueryResponse(RemoteQueryResult remoteQueryResult) {
    List<?> list = remoteQueryResult.getResults();
    int numResults = list.size();
    String[] projection = remoteQueryResult.getProjections();
    int projSize = projection != null ? projection.length : 0;
    List<WrappedMessage> results = new ArrayList<>(projSize == 0 ? numResults : numResults * projSize);
    for (Object o : list) {
        if (projSize == 0) {
            results.add(new WrappedMessage(o));
        } else {
            Object[] row = (Object[]) o;
            for (int i = 0; i < projSize; i++) {
                results.add(new WrappedMessage(row[i]));
            }
        }
    }
    QueryResponse response = new QueryResponse();
    response.setTotalResults(remoteQueryResult.getTotalResults());
    response.setNumResults(numResults);
    response.setProjectionSize(projSize);
    response.setResults(results);
    return response;
}
Also used : WrappedMessage(org.infinispan.protostream.WrappedMessage) QueryResponse(org.infinispan.query.remote.client.impl.QueryResponse) ArrayList(java.util.ArrayList)

Aggregations

ArrayList (java.util.ArrayList)1 WrappedMessage (org.infinispan.protostream.WrappedMessage)1 QueryResponse (org.infinispan.query.remote.client.impl.QueryResponse)1