Exemple #1
0
  private List<Object> executeQuery() {
    List<Object> results;

    QueryOperation op = cache.getOperationsFactory().newQueryOperation(this);
    QueryResponse response = op.execute();
    totalResults = (int) response.getTotalResults();
    if (response.getProjectionSize() > 0) {
      results = new ArrayList<Object>(response.getResults().size() / response.getProjectionSize());
      Iterator<WrappedMessage> it = response.getResults().iterator();
      while (it.hasNext()) {
        Object[] row = new Object[response.getProjectionSize()];
        for (int i = 0; i < response.getProjectionSize(); i++) {
          row[i] = it.next().getValue();
        }
        results.add(row);
      }
    } else {
      results = new ArrayList<Object>(response.getResults().size());
      SerializationContext serCtx = getSerializationContext();
      for (WrappedMessage r : response.getResults()) {
        try {
          byte[] bytes = (byte[]) r.getValue();
          Object o = ProtobufUtil.fromWrappedByteArray(serCtx, bytes);
          results.add(o);
        } catch (IOException e) {
          throw new HotRodClientException(e);
        }
      }
    }

    return results;
  }
  @Override
  public <T> List<T> list() {
    if (results == null) {
      results = cache.query(this);
    }

    return results;
  }
  public RemoteQueryFactory(RemoteCacheImpl cache) {
    serializationContext =
        ProtoStreamMarshaller.getSerializationContext(cache.getRemoteCacheManager());

    this.cache = cache;

    try {
      MarshallerRegistration.registerMarshallers(serializationContext);
    } catch (Exception e) {
      throw new HotRodClientException("Failed to initialise the Protobuf serialization context", e);
    }
  }