当前位置: 首页>>代码示例>>Java>>正文


Java RowModel.getKey方法代码示例

本文整理汇总了Java中org.apache.hadoop.hbase.rest.model.RowModel.getKey方法的典型用法代码示例。如果您正苦于以下问题:Java RowModel.getKey方法的具体用法?Java RowModel.getKey怎么用?Java RowModel.getKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.hadoop.hbase.rest.model.RowModel的用法示例。


在下文中一共展示了RowModel.getKey方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkAndPut

import org.apache.hadoop.hbase.rest.model.RowModel; //导入方法依赖的package包/类
/**
 * Validates the input request parameters, parses columns from CellSetModel,
 * and invokes checkAndPut on HTable.
 *
 * @param model instance of CellSetModel
 * @return Response 200 OK, 304 Not modified, 400 Bad request
 */
Response checkAndPut(final CellSetModel model) {
  HTablePool pool = servlet.getTablePool();
  HTableInterface table = null;
  try {
    if (model.getRows().size() != 1) {
      return Response.status(Response.Status.BAD_REQUEST)
        .type(MIMETYPE_TEXT).entity("Bad request" + CRLF)
        .build();
    }

    RowModel rowModel = model.getRows().get(0);
    byte[] key = rowModel.getKey();
    if (key == null) {
      key = rowspec.getRow();
    }

    List<CellModel> cellModels = rowModel.getCells();
    int cellModelCount = cellModels.size();
    if (key == null || cellModelCount <= 1) {
      return Response.status(Response.Status.BAD_REQUEST)
        .type(MIMETYPE_TEXT).entity("Bad request" + CRLF)
        .build();
    }

    Put put = new Put(key);
    CellModel valueToCheckCell = cellModels.get(cellModelCount - 1);
    byte[] valueToCheckColumn = valueToCheckCell.getColumn();
    byte[][] valueToPutParts = KeyValue.parseColumn(valueToCheckColumn);
    if (valueToPutParts.length == 2 && valueToPutParts[1].length > 0) {
      CellModel valueToPutCell = null;
      for (int i = 0, n = cellModelCount - 1; i < n ; i++) {
        if(Bytes.equals(cellModels.get(i).getColumn(),
            valueToCheckCell.getColumn())) {
          valueToPutCell = cellModels.get(i);
          break;
        }
      }
      if (valueToPutCell != null) {
        put.add(valueToPutParts[0], valueToPutParts[1], valueToPutCell
          .getTimestamp(), valueToPutCell.getValue());
      } else {
        return Response.status(Response.Status.BAD_REQUEST)
          .type(MIMETYPE_TEXT).entity("Bad request" + CRLF)
          .build();
      }
    } else {
      return Response.status(Response.Status.BAD_REQUEST)
        .type(MIMETYPE_TEXT).entity("Bad request" + CRLF)
        .build();
    }

    table = pool.getTable(this.tableResource.getName());
    boolean retValue = table.checkAndPut(key, valueToPutParts[0],
      valueToPutParts[1], valueToCheckCell.getValue(), put);
    if (LOG.isDebugEnabled()) {
      LOG.debug("CHECK-AND-PUT " + put.toString() + ", returns " + retValue);
    }
    table.flushCommits();
    ResponseBuilder response = Response.ok();
    if (!retValue) {
      response = Response.status(304);
    }
    return response.build();
  } catch (IOException e) {
    return Response.status(Response.Status.SERVICE_UNAVAILABLE)
      .type(MIMETYPE_TEXT).entity("Unavailable" + CRLF)
      .build();
  } finally {
    if (table != null) try {
      table.close();
    } catch (IOException ioe) { }
  }
}
 
开发者ID:fengchen8086,项目名称:LCIndex-HBase-0.94.16,代码行数:81,代码来源:RowResource.java

示例2: checkAndPut

import org.apache.hadoop.hbase.rest.model.RowModel; //导入方法依赖的package包/类
/**
 * Validates the input request parameters, parses columns from CellSetModel,
 * and invokes checkAndPut on HTable.
 *
 * @param model instance of CellSetModel
 * @return Response 200 OK, 304 Not modified, 400 Bad request
 */
Response checkAndPut(final CellSetModel model) {
  HTableInterface table = null;
  try {
    if (model.getRows().size() != 1) {
      return Response.status(Response.Status.BAD_REQUEST)
        .type(MIMETYPE_TEXT).entity("Bad request" + CRLF)
        .build();
    }

    RowModel rowModel = model.getRows().get(0);
    byte[] key = rowModel.getKey();
    if (key == null) {
      key = rowspec.getRow();
    }

    List<CellModel> cellModels = rowModel.getCells();
    int cellModelCount = cellModels.size();
    if (key == null || cellModelCount <= 1) {
      return Response.status(Response.Status.BAD_REQUEST)
        .type(MIMETYPE_TEXT).entity("Bad request" + CRLF)
        .build();
    }

    Put put = new Put(key);
    CellModel valueToCheckCell = cellModels.get(cellModelCount - 1);
    byte[] valueToCheckColumn = valueToCheckCell.getColumn();
    byte[][] valueToPutParts = KeyValue.parseColumn(valueToCheckColumn);
    if (valueToPutParts.length != 2) {
      return Response.status(Response.Status.BAD_REQUEST)
        .type(MIMETYPE_TEXT).entity("Bad request" + CRLF)
        .build();
    }
    CellModel valueToPutCell = null;
    for (int i = 0, n = cellModelCount - 1; i < n ; i++) {
      if(Bytes.equals(cellModels.get(i).getColumn(),
          valueToCheckCell.getColumn())) {
        valueToPutCell = cellModels.get(i);
        break;
      }
    }
    if (null == valueToPutCell) {
      return Response.status(Response.Status.BAD_REQUEST)
        .type(MIMETYPE_TEXT).entity("Bad request" + CRLF)
        .build();
    }
    put.addImmutable(valueToPutParts[0], valueToPutParts[1], valueToPutCell
      .getTimestamp(), valueToPutCell.getValue());

    table = servlet.getTable(this.tableResource.getName());
    boolean retValue = table.checkAndPut(key, valueToPutParts[0],
      valueToPutParts[1], valueToCheckCell.getValue(), put);
    if (LOG.isDebugEnabled()) {
      LOG.debug("CHECK-AND-PUT " + put.toString() + ", returns " + retValue);
    }
    table.flushCommits();
    ResponseBuilder response = Response.ok();
    if (!retValue) {
      response = Response.status(304);
    }
    return response.build();
  } catch (IOException e) {
    return Response.status(Response.Status.SERVICE_UNAVAILABLE)
      .type(MIMETYPE_TEXT).entity("Unavailable" + CRLF)
      .build();
  } finally {
    if (table != null) try {
      table.close();
    } catch (IOException ioe) { }
  }
}
 
开发者ID:cloud-software-foundation,项目名称:c5,代码行数:78,代码来源:RowResource.java


注:本文中的org.apache.hadoop.hbase.rest.model.RowModel.getKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。