AbacusUtil Docs | Download | Javadoc | FAQ | Community

HBaseExecutor

HBaseExecutor is a wrapper of HBase Java client. Just like SQLExecutor, it makes things much easier to operate data with HBase by the straight support of Entity/String, and almost all the java basic types: boolean...double...String...Date...Calendar.... Rather than introducing something new or different, HBaseExecutor is created to make things simpler. Here is a simple sample:

@Test
public void test_crud() {
    Account account = createAccount2();

    // Insert is supported by Model/entity
    hbaseExecutor.put("account", toAnyPut(account));

    // Get is supported by Model/entity
    Account dbAccount = hbaseExecutor.get(Account.class, "account", AnyGet.valueOf(account.getId()));
    N.println(dbAccount);

    // Delete the inserted account
    hbaseExecutor.delete("account", AnyDelete.valueOf(account.getId()));
}

Comparing to the sample by Put/Get/Delete:

@Test
public void test_crud_2() throws IOException {
    Account account = createAccount2();

    // Insert an account into HBase store
    Put put = new Put(Bytes.toBytes(account.getId()));
    put.addColumn(Bytes.toBytes("name"), Bytes.toBytes("firstName"), Bytes.toBytes(account.getName().firstName().value()));
    put.addColumn(Bytes.toBytes("name"), Bytes.toBytes("lastName"), Bytes.toBytes(account.getName().lastName().value()));
    put.addColumn(Bytes.toBytes("contact"), Bytes.toBytes("city"), Bytes.toBytes(account.getContact().city().value()));
    put.addColumn(Bytes.toBytes("contact"), Bytes.toBytes("state"), Bytes.toBytes(account.getContact().state().value()));
    put.addColumn(Bytes.toBytes("createTime"), Bytes.toBytes(""), Bytes.toBytes(N.stringOf(account.createTime().value())));

    hbaseExecutor.put("account", put);

    // Get the inserted account from HBase store
    Result result = hbaseExecutor.get("account", new Get(Bytes.toBytes(account.getId())));
    CellScanner cellScanner = result.cellScanner();
    while (cellScanner.advance()) {
        final Cell cell = cellScanner.current();
        N.println(Bytes.toString(cell.getFamilyArray(), cell.getFamilyOffset(), cell.getFamilyLength()));
        N.println(Bytes.toString(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength()));
        N.println(Bytes.toString(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()));
        // ... a lot of work to do
    }

    // Delete the inserted account from HBase store.
    hbaseExecutor.delete("account", new Delete(Bytes.toBytes(account.getId())));
}

Try it now. Here are the steps: