Search in sources :

Example 1 with WrappedMessage

use of org.infinispan.protostream.WrappedMessage 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)

Example 2 with WrappedMessage

use of org.infinispan.protostream.WrappedMessage in project infinispan by infinispan.

the class FilterResultMarshaller method readFrom.

@Override
public FilterResult readFrom(ProtoStreamReader reader) throws IOException {
    byte[] instance = reader.readBytes("instance");
    List<WrappedMessage> projection = reader.readCollection("projection", new ArrayList<>(), WrappedMessage.class);
    List<WrappedMessage> sortProjection = reader.readCollection("sortProjection", new ArrayList<>(), WrappedMessage.class);
    Object i = null;
    if (instance != null) {
        i = ProtobufUtil.fromWrappedByteArray(reader.getSerializationContext(), instance);
    }
    Object[] p = null;
    if (!projection.isEmpty()) {
        p = new Object[projection.size()];
        int j = 0;
        for (WrappedMessage m : projection) {
            p[j++] = m.getValue();
        }
    }
    Comparable[] sp = null;
    if (!sortProjection.isEmpty()) {
        sp = new Comparable[sortProjection.size()];
        int j = 0;
        for (WrappedMessage m : sortProjection) {
            sp[j++] = (Comparable) m.getValue();
        }
    }
    return new FilterResult(i, p, sp);
}
Also used : WrappedMessage(org.infinispan.protostream.WrappedMessage) FilterResult(org.infinispan.query.remote.client.FilterResult)

Example 3 with WrappedMessage

use of org.infinispan.protostream.WrappedMessage in project infinispan by infinispan.

the class FilterResultMarshaller method writeTo.

@Override
public void writeTo(ProtoStreamWriter writer, FilterResult filterResult) throws IOException {
    if (filterResult.getProjection() == null) {
        // skip marshalling the instance if there is a projection
        writer.writeBytes("instance", (byte[]) filterResult.getInstance());
    } else {
        WrappedMessage[] p = new WrappedMessage[filterResult.getProjection().length];
        for (int i = 0; i < p.length; i++) {
            p[i] = new WrappedMessage(filterResult.getProjection()[i]);
        }
        writer.writeArray("projection", p, WrappedMessage.class);
    }
    if (filterResult.getSortProjection() != null) {
        WrappedMessage[] p = new WrappedMessage[filterResult.getSortProjection().length];
        for (int i = 0; i < p.length; i++) {
            p[i] = new WrappedMessage(filterResult.getSortProjection()[i]);
        }
        writer.writeArray("sortProjection", p, WrappedMessage.class);
    }
}
Also used : WrappedMessage(org.infinispan.protostream.WrappedMessage)

Example 4 with WrappedMessage

use of org.infinispan.protostream.WrappedMessage in project infinispan by infinispan.

the class QueryResponse method extractResults.

@Override
public List<?> extractResults(SerializationContext serializationContext) throws IOException {
    List<Object> unwrappedResults;
    if (projectionSize > 0) {
        unwrappedResults = new ArrayList<>(results.size() / projectionSize);
        Iterator<WrappedMessage> it = results.iterator();
        while (it.hasNext()) {
            Object[] row = new Object[projectionSize];
            for (int i = 0; i < row.length; i++) {
                row[i] = it.next().getValue();
            }
            unwrappedResults.add(row);
        }
    } else {
        unwrappedResults = new ArrayList<>(results.size());
        for (WrappedMessage r : results) {
            Object o = r.getValue();
            if (serializationContext != null && o instanceof byte[]) {
                o = ProtobufUtil.fromWrappedByteArray(serializationContext, (byte[]) o);
            }
            unwrappedResults.add(o);
        }
    }
    return unwrappedResults;
}
Also used : WrappedMessage(org.infinispan.protostream.WrappedMessage)

Example 5 with WrappedMessage

use of org.infinispan.protostream.WrappedMessage in project protostream by infinispan.

the class CompileTimeProtoSchemaGenerator method importProtoTypeMetadata.

@Override
protected ProtoTypeMetadata importProtoTypeMetadata(XClass javaType) {
    if (javaType == typeFactory.fromClass(WrappedMessage.class)) {
        GenericDescriptor descriptor = serializationContext.getDescriptorByName(WrappedMessage.PROTOBUF_TYPE_NAME);
        BaseMarshaller<WrappedMessage> marshaller = serializationContext.getMarshaller(WrappedMessage.PROTOBUF_TYPE_NAME);
        return new ImportedProtoTypeMetadata(descriptor, marshaller, javaType);
    }
    String fileName = dependencies.get(javaType);
    if (fileName != null) {
        String packageName = serializationContext.getFileDescriptors().get(fileName).getPackage();
        return new CompileTimeImportedProtoTypeMetadata(makeTypeMetadata(javaType), packageName, fileName);
    }
    return null;
}
Also used : WrappedMessage(org.infinispan.protostream.WrappedMessage) ImportedProtoTypeMetadata(org.infinispan.protostream.annotations.impl.ImportedProtoTypeMetadata) GenericDescriptor(org.infinispan.protostream.descriptors.GenericDescriptor)

Aggregations

WrappedMessage (org.infinispan.protostream.WrappedMessage)7 SerializationContext (org.infinispan.protostream.SerializationContext)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 GeneratedSchema (org.infinispan.protostream.GeneratedSchema)1 ProtoSchemaBuilder (org.infinispan.protostream.annotations.ProtoSchemaBuilder)1 ImportedProtoTypeMetadata (org.infinispan.protostream.annotations.impl.ImportedProtoTypeMetadata)1 GenericDescriptor (org.infinispan.protostream.descriptors.GenericDescriptor)1 AbstractProtoStreamTest (org.infinispan.protostream.test.AbstractProtoStreamTest)1 FilterResult (org.infinispan.query.remote.client.FilterResult)1 QueryResponse (org.infinispan.query.remote.client.impl.QueryResponse)1