4.1. Querying HBase with the Java API

The HBase Java API allows application developers to specify the desired data consistency for a query using the setConsistency() method, as shown in the following example. A new enum, CONSISTENCY, specifies two levels of data consistency: TIMELINE and STRONG.

Get get = new Get(row);
Result result = table.get(get);

HBase application developers can also pass multiple gets:

Get get1 = new Get(row);
ArrayList<Get> gets = new ArrayList<Get>();
Result[] results = table.get(gets);

The setConsistency() method is also available for Scan objects:

Scan scan = new Scan();
ResultScanner scanner = table.getScanner(scan);

In addition, use the Result.isStale() method to determine whether the query results arrived from the primary or a secondary region server:

Result result = table.get(get);
if (result.isStale()) {

loading table of contents...