コード例 #1
0
  /**
   * Method to execute a Delete mutation operation on Hypertable. A delete is implemented by
   * Hypertable as a put that inserts tombstone values.
   *
   * @param tableName
   * @param delete
   * @throws ClientException
   * @throws TException
   */
  public void delete(String tableName, Delete delete) throws ClientException, TException {
    long mutator = client.mutator_open(ns, tableName, 0, 0);

    for (int i = 0; i < delete._getCells().size(); i++) {
      Cell c = delete._getCells().get(i);
      if (c.getKey().isSetRevision()) {
        int revs = (int) c.getKey().getRevision();
        System.out.println(revs);
        String cfam = c.getKey().getColumn_family();
        String cqual = c.getKey().getColumn_qualifier();
        c.getKey().setRevisionIsSet(false);
        List<Result> res =
            this.scan(
                tableName, new Scan(delete.getRowkey()).addColumn(cfam, cqual).setRevisions(revs));
        if (!res.isEmpty()) {
          System.out.println(res.get(0).getValueRevisions(cfam, cqual));
          for (Long ts : res.get(0).getTimestampRevisions(cfam, cqual))
            delete.deleteColumn(cfam, cqual, ts);
        }
        delete._getCells().remove(i--);
      }
    }

    try {
      if (delete._getCells().size() > 1) client.mutator_set_cells(mutator, delete._getCells());
      else if (delete._getCells().size() == 1)
        client.mutator_set_cell(mutator, delete._getCells().get(0));
    } finally {
      client.mutator_close(mutator);
    }
  }
コード例 #2
0
  /**
   * Method to execute a batch Delete mutation operation on Hypertable. A delete is implemented by
   * Hypertable as a put that inserts tombstone values.
   *
   * @param tableName
   * @param deletes
   * @throws ClientException
   * @throws TException
   */
  public void delete(String tableName, List<Delete> deletes) throws ClientException, TException {
    long mutator = client.mutator_open(ns, tableName, 0, 0);

    List<Cell> cells = new LinkedList<Cell>();

    for (Delete delete : deletes) cells.addAll(delete._getCells());

    try {
      if (cells.size() > 1) client.mutator_set_cells(mutator, cells);
      else if (cells.size() == 1) client.mutator_set_cell(mutator, cells.get(0));
    } finally {
      client.mutator_close(mutator);
    }
  }