/**
     * @return Query info.
     * @throws GridException In case of error.
     */
    @SuppressWarnings({"unchecked"})
    private GridCacheQueryInfo localQueryInfo() throws GridException {
      GridCacheQueryBean qry = query();

      GridPredicate<GridCacheEntry<Object, Object>> prjPred =
          qry.query().projectionFilter() == null
              ? F.<GridCacheEntry<Object, Object>>alwaysTrue()
              : qry.query().projectionFilter();

      GridMarshaller marsh = cctx.marshaller();

      GridReducer<Object, Object> rdc =
          qry.reducer() != null
              ? marsh.<GridReducer<Object, Object>>unmarshal(marsh.marshal(qry.reducer()), null)
              : null;

      GridClosure<Object, Object> trans =
          qry.transform() != null
              ? marsh.<GridClosure<Object, Object>>unmarshal(marsh.marshal(qry.transform()), null)
              : null;

      return new GridCacheQueryInfo(
          true,
          prjPred,
          trans,
          rdc,
          qry.query(),
          GridCacheLocalQueryFuture.this,
          ctx.localNodeId(),
          cctx.io().nextIoId(),
          qry.query().includeMetadata(),
          true,
          qry.arguments());
    }
Exemplo n.º 2
0
  /**
   * Encodes given object to a byte array and returns flags that describe the type of serialized
   * object.
   *
   * @param obj Object to serialize.
   * @param out Output stream to which object should be written.
   * @return Serialization flags.
   * @throws GridException If JDK serialization failed.
   */
  private int encodeObj(Object obj, ByteArrayOutputStream out) throws GridException {
    int flags = 0;

    byte[] data = null;

    if (obj instanceof String) {
      data = ((String) obj).getBytes();
    } else if (obj instanceof Boolean) {
      data = new byte[] {(byte) ((Boolean) obj ? '1' : '0')};

      flags |= BOOLEAN_FLAG;
    } else if (obj instanceof Integer) {
      data = U.intToBytes((Integer) obj);

      flags |= INT_FLAG;
    } else if (obj instanceof Long) {
      data = U.longToBytes((Long) obj);

      flags |= LONG_FLAG;
    } else if (obj instanceof Date) {
      data = U.longToBytes(((Date) obj).getTime());

      flags |= DATE_FLAG;
    } else if (obj instanceof Byte) {
      data = new byte[] {(Byte) obj};

      flags |= BYTE_FLAG;
    } else if (obj instanceof Float) {
      data = U.intToBytes(Float.floatToIntBits((Float) obj));

      flags |= FLOAT_FLAG;
    } else if (obj instanceof Double) {
      data = U.longToBytes(Double.doubleToLongBits((Double) obj));

      flags |= DOUBLE_FLAG;
    } else if (obj instanceof byte[]) {
      data = (byte[]) obj;

      flags |= BYTE_ARR_FLAG;
    } else {
      jdkMarshaller.marshal(obj, out);

      flags |= SERIALIZED_FLAG;
    }

    if (data != null) out.write(data, 0, data.length);

    return flags;
  }
 /**
  * Serialize object to byte array using marshaller.
  *
  * @param obj Object to convert to byte array.
  * @return Byte array.
  * @throws GridException If failed to convert.
  */
 protected byte[] toBytes(Object obj) throws GridException {
   return marsh.marshal(obj);
 }