Beispiel #1
0
  // Retrieves the row from the table and check if it exists and has not been flagged as deleted
  protected Map<RecordId, Result> getRows(List<RecordId> recordIds, List<FieldType> fields)
      throws RecordException {
    Map<RecordId, Result> results = new HashMap<RecordId, Result>();

    try {
      List<Get> gets = new ArrayList<Get>();
      for (RecordId recordId : recordIds) {
        Get get = new Get(recordId.toBytes());
        // Add the columns for the fields to get
        addFieldsToGet(get, fields);
        get.setMaxVersions(1); // Only retrieve the most recent version of each field
        gets.add(get);
      }

      // Retrieve the data from the repository
      int i = 0;
      for (Result result : recordTable.get(gets)) {
        if (result == null || result.isEmpty()) {
          i++; // Skip this recordId (instead of throwing a RecordNotFoundException)
          continue;
        }
        // Check if the record was deleted
        byte[] deleted = recdec.getLatest(result, RecordCf.DATA.bytes, RecordColumn.DELETED.bytes);
        if ((deleted == null) || (Bytes.toBoolean(deleted))) {
          i++; // Skip this recordId (instead of throwing a RecordNotFoundException)
          continue;
        }
        results.put(recordIds.get(i++), result);
      }
    } catch (IOException e) {
      throw new RecordException(
          "Exception occurred while retrieving records '" + recordIds + "' from HBase table", e);
    }
    return results;
  }
Beispiel #2
0
  // Retrieves the row from the table and check if it exists and has not been flagged as deleted
  protected Result getRow(
      RecordId recordId, Long version, int numberOfVersions, List<FieldType> fields)
      throws RecordException {
    Result result;
    Get get = new Get(recordId.toBytes());
    get.setFilter(REAL_RECORDS_FILTER);

    try {
      // Add the columns for the fields to get
      addFieldsToGet(get, fields);

      if (version != null)
        get.setTimeRange(0, version + 1); // Only retrieve data within this timerange
      get.setMaxVersions(numberOfVersions);

      // Retrieve the data from the repository
      result = recordTable.get(get);

      if (result == null || result.isEmpty()) throw new RecordNotFoundException(recordId);

    } catch (IOException e) {
      throw new RecordException(
          "Exception occurred while retrieving record '" + recordId + "' from HBase table", e);
    }
    return result;
  }