Пример #1
0
  @GET
  @Produces({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF, MIMETYPE_PROTOBUF_IETF})
  public Response get(final @Context UriInfo uriInfo) {
    MultivaluedMap<String, String> params = uriInfo.getQueryParameters();

    servlet.getMetrics().incrementRequests(1);
    try {
      CellSetModel model = new CellSetModel();
      for (String rk : params.get(ROW_KEYS_PARAM_NAME)) {
        RowSpec rowSpec = new RowSpec(rk);

        if (this.versions != null) {
          rowSpec.setMaxVersions(this.versions);
        }
        ResultGenerator generator =
            ResultGenerator.fromRowSpec(
                this.tableResource.getName(),
                rowSpec,
                null,
                !params.containsKey(NOCACHE_PARAM_NAME));
        Cell value = null;
        RowModel rowModel = new RowModel(rk);
        if (generator.hasNext()) {
          while ((value = generator.next()) != null) {
            rowModel.addCell(
                new CellModel(
                    CellUtil.cloneFamily(value),
                    CellUtil.cloneQualifier(value),
                    value.getTimestamp(),
                    CellUtil.cloneValue(value)));
          }
          model.addRow(rowModel);
        } else {
          LOG.trace("The row : " + rk + " not found in the table.");
        }
      }

      if (model.getRows().size() == 0) {
        // If no rows found.
        servlet.getMetrics().incrementFailedGetRequests(1);
        return Response.status(Response.Status.NOT_FOUND)
            .type(MIMETYPE_TEXT)
            .entity("No rows found." + CRLF)
            .build();
      } else {
        servlet.getMetrics().incrementSucessfulGetRequests(1);
        return Response.ok(model).build();
      }
    } catch (Exception e) {
      servlet.getMetrics().incrementFailedGetRequests(1);
      return processException(e);
    }
  }
 @GET
 @Produces({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF})
 public Response get(
     final @Context UriInfo uriInfo,
     @QueryParam("n") int maxRows,
     final @QueryParam("c") int maxValues) {
   if (LOG.isDebugEnabled()) {
     LOG.debug("GET " + uriInfo.getAbsolutePath());
   }
   servlet.getMetrics().incrementRequests(1);
   CellSetModel model = new CellSetModel();
   RowModel rowModel = null;
   byte[] rowKey = null;
   int limit = batch;
   if (maxValues > 0) {
     limit = maxValues;
   }
   int count = limit;
   do {
     KeyValue value = null;
     try {
       value = generator.next();
     } catch (IllegalStateException e) {
       ScannerResource.delete(id);
       throw new WebApplicationException(Response.Status.GONE);
     }
     if (value == null) {
       LOG.info("generator exhausted");
       // respond with 204 (No Content) if an empty cell set would be
       // returned
       if (count == limit) {
         return Response.noContent().build();
       }
       break;
     }
     if (rowKey == null) {
       rowKey = value.getRow();
       rowModel = new RowModel(rowKey);
     }
     if (!Bytes.equals(value.getRow(), rowKey)) {
       // if maxRows was given as a query param, stop if we would exceed the
       // specified number of rows
       if (maxRows > 0) {
         if (--maxRows == 0) {
           generator.putBack(value);
           break;
         }
       }
       model.addRow(rowModel);
       rowKey = value.getRow();
       rowModel = new RowModel(rowKey);
     }
     rowModel.addCell(
         new CellModel(
             value.getFamily(), value.getQualifier(), value.getTimestamp(), value.getValue()));
   } while (--count > 0);
   model.addRow(rowModel);
   ResponseBuilder response = Response.ok(model);
   response.cacheControl(cacheControl);
   return response.build();
 }