HBaseDataStore implements DataStore { @Override public Document get(final Table table, String id) throws DataStoreException { HTableInterface hTable = null; try { Get get = new Get(Bytes.toBytes(id + ":" + table.getName())) .addColumn(COLUMN_FAMILY, DATA_FIELD_NAME) .addColumn(COLUMN_FAMILY, TIMESTAMP_FIELD_NAME); hTable = tableWrapper.getTable(table); Result getResult = hTable.get(get); if (!getResult.isEmpty()) { byte[] data = getResult.getValue(COLUMN_FAMILY, DATA_FIELD_NAME); byte[] timestamp = getResult.getValue(COLUMN_FAMILY, TIMESTAMP_FIELD_NAME); long time = Bytes.toLong(timestamp); return new Document(id, time, mapper.readTree(data)); } else { throw new DataStoreException(DataStoreException.ErrorCode.STORE_NO_DATA_FOUND_FOR_ID, String.format("No data found for ID: %s", id)); } } catch (DataStoreException ex) { throw ex; } catch (IOException ex) { throw new DataStoreException(DataStoreException.ErrorCode.STORE_SINGLE_GET, ex.getMessage(), ex); } catch (Exception ex) { throw new DataStoreException(DataStoreException.ErrorCode.STORE_SINGLE_GET, ex.getMessage(), ex); } finally { if (null != hTable) { try { hTable.close(); } catch (IOException e) { logger.error("Error closing table: ", e); } } } } HBaseDataStore(HbaseTableConnection tableWrapper, ObjectMapper mapper); @Override void save(final Table table, Document document); @Override void save(final Table table, List<Document> documents); @Override Document get(final Table table, String id); @Override List<Document> get(final Table table, List<String> ids); Put getPutForDocument(final Table table, Document document);  }
@Test public void testGetSingleMissingDocument() { try { HBaseDataStore.get(TEST_APP, UUID.randomUUID().toString()); fail(); } catch (DataStoreException ex) { assertEquals(DataStoreException.ErrorCode.STORE_NO_DATA_FOUND_FOR_ID, ex.getErrorCode()); } }
@Test public void testGetBulkNullIdList() throws Exception { List<String> ids = null; try { HBaseDataStore.get(TEST_APP, ids); fail(); } catch (DataStoreException ex) { assertEquals(DataStoreException.ErrorCode.STORE_INVALID_REQUEST, ex.getErrorCode()); } }
@Test public void testGetBulkMissingDocument() throws Exception { List<String> ids = new Vector<String>(); for (int i = 0; i < 10; i++) { ids.add(UUID.randomUUID().toString()); } try { HBaseDataStore.get(TEST_APP, ids); fail(); } catch (DataStoreException ex) { assertEquals(DataStoreException.ErrorCode.STORE_NO_DATA_FOUND_FOR_IDS, ex.getErrorCode()); } }