Package org.tarantool.core.cmd

Examples of org.tarantool.core.cmd.Response


  /** {@inheritDoc} */
  @Override
  public synchronized Response execute(Request request) {
    int op = request.getOp();
    if (op == Ping.OP_CODE) {
      return new Response(Ping.OP_CODE, 0, request.getId());
    } else if (op == Update.OP_CODE || op == Insert.OP_CODE || op == Delete.OP_CODE) {
      return executeDML(request, op);

    } else if (op == Select.OP_CODE) {
      return executeSelect(request);
View Full Code Here


    for (int i = 0; i < result.size(); i++) {
      responseBody[i] = result.get(i).pack();
      len += responseBody[i].length + 4;
    }

    Response response = new Response(code, len, request.getId());
    ByteBuffer bodyBuffer = ByteBuffer.allocate(len).order(ByteOrder.LITTLE_ENDIAN).putInt(result.size());
    for (byte[] tuple : responseBody) {
      bodyBuffer.putInt(tuple.length).put(tuple);
    }
    response.setBody(bodyBuffer.array());
    return response;
  }
View Full Code Here

    ByteBuffer buffer = ByteBuffer.wrap(body).order(ByteOrder.LITTLE_ENDIAN);
    Tuple tuple = Tuple.create(buffer, ByteOrder.LITTLE_ENDIAN);
    Tuple stored = null;
    Space space = spaces.get(spaceNum);
    if (op != Insert.OP_CODE && (stored = space.get(tuple)) == null) {
      Response response = new Response(op, 4, request.getId());
      response.setBody(ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN).putInt(0).array());
      return response;
    }

    if (op == Insert.OP_CODE) {
      stored = put(spaceNum, tuple, (flags & Flags.ADD_TUPLE) > 0, (flags & Flags.REPLACE_TUPLE) > 0);
    } else if (op == Delete.OP_CODE) {
      stored = delete(spaceNum, tuple);
    } else if (op == Update.OP_CODE) {
      int ops = buffer.getInt();
      for (int i = 0; i < ops; i++) {
        update(spaceNum, buffer, tuple);
      }
      stored = get(spaceNum, 0, new Tuple(1).setBytes(0, tuple.getBytes(0))).get(0);
    }

    if ((dmlRequest.getFlags() & Flags.RETURN_TUPLE) > 0) {
      byte[] responseBody = stored.pack();
      Response response = new Response(op, responseBody.length + 8, request.getId());
      response.setBody(ByteBuffer.allocate(responseBody.length + 8).order(ByteOrder.LITTLE_ENDIAN).putInt(1).putInt(responseBody.length)
          .put(responseBody).array());
      return response;
    } else {
      Response response = new Response(op, 4, request.getId());
      response.setCount(1);
      return response;
    }
  }
View Full Code Here

   *
   * @return a {@link org.tarantool.core.cmd.Response} object.
   */
  public Response read() {
    ByteBuffer headers = read(HEADER_SIZE);
    Response response = new Response(headers.getInt(), headers.getInt(), headers.getInt());
    if (response.getSize() > 0) {
      ByteBuffer body = read(response.getSize());
      response.setRet(body.getInt());
      if (response.getRet() != 0) {
        handleErrorMessage(response, body);
      }
      if (body.remaining() > 4) {
        byte[] answer = new byte[body.remaining()];
        body.get(answer);
        response.setBody(answer);
      } else {
        response.setCount(body.getInt());
      }
    }
    return response;
  }
View Full Code Here

  /** {@inheritDoc} */
  @Override
  public Integer delete(int space, Tuple tuple) {
    try {
      Response response = transport.execute(new Delete(id.incrementAndGet(), tuple.pack()).space(space));
      return response.getCount();
    } finally {
      returnConnection();
    }
  }
View Full Code Here

  /** {@inheritDoc} */
  @Override
  public Tuple deleteAndGet(int space, Tuple tuple) {
    try {
      Response response = transport.execute(new Delete(id.incrementAndGet(), tuple.pack()).space(space).flags(Flags.RETURN_TUPLE));
      return response.readSingleTuple();
    } finally {
      returnConnection();
    }
  }
View Full Code Here

  /** {@inheritDoc} */
  @Override
  public Tuple updateAndGet(int space, Tuple tuple, List<Operation> ops) {
    try {
      Response response = transport.execute(new Update(id.incrementAndGet(), tuple, ops).space(space).flags(Flags.RETURN_TUPLE));
      return response.readSingleTuple();
    } finally {
      returnConnection();
    }

  }
View Full Code Here

  /** {@inheritDoc} */
  @Override
  public Integer update(int space, Tuple tuple, List<Operation> ops) {
    try {
      Response response = transport.execute(new Update(id.incrementAndGet(), tuple, ops).space(space));
      return response.getCount();
    } finally {
      returnConnection();
    }

  }
View Full Code Here

  /** {@inheritDoc} */
  @Override
  public Tuple insertAndGet(int space, Tuple tuple) {
    try {
      Response response = transport.execute(new Insert(id.incrementAndGet(), tuple.pack()).space(space).flags(Flags.RETURN_TUPLE | Flags.ADD_TUPLE));
      return response.readSingleTuple();
    } finally {
      returnConnection();
    }

  }
View Full Code Here

  /** {@inheritDoc} */
  @Override
  public Integer insert(int space, Tuple tuple) {
    try {
      Response response = transport.execute(new Insert(id.incrementAndGet(), tuple.pack()).space(space).flags(Flags.ADD_TUPLE));
      return response.getCount();
    } finally {
      returnConnection();
    }

  }
View Full Code Here

TOP

Related Classes of org.tarantool.core.cmd.Response

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.