Get get = getFromThrift(tGet); assertArrayEquals(get.getAttribute("attribute1"), attributeValue); TPut tPut = new TPut(wrap(rowName) , columnValues); tPut.setAttributes(attributes); Put put = putFromThrift(tPut); assertArrayEquals(put.getAttribute("attribute1"), attributeValue); Scan scan = scanFromThrift(tScan); assertArrayEquals(scan.getAttribute("attribute1"), attributeValue); TIncrement tIncrement = new TIncrement(wrap(rowName), incrementColumns); tIncrement.setAttributes(attributes); Increment increment = incrementFromThrift(tIncrement); assertArrayEquals(increment.getAttribute("attribute1"), attributeValue); Delete delete = deleteFromThrift(tDelete); assertArrayEquals(delete.getAttribute("attribute1"), attributeValue);
@Override public List<TDelete> deleteMultiple(ByteBuffer table, List<TDelete> deletes) throws TIOError, TException { checkReadOnlyMode(); Table htable = getTable(table); try { htable.delete(deletesFromThrift(deletes)); } catch (IOException e) { throw getTIOError(e); } finally { closeTable(htable); } return Collections.emptyList(); }
@Override public List<TResult> getMultiple(ByteBuffer table, List<TGet> gets) throws TIOError, TException { Table htable = getTable(table); try { return resultsFromHBase(htable.get(getsFromThrift(gets))); } catch (IOException e) { throw getTIOError(e); } finally { closeTable(htable); } }
@Override public TResult get(ByteBuffer table, TGet get) throws TIOError, TException { Table htable = getTable(table); try { return resultFromHBase(htable.get(getFromThrift(get))); } catch (IOException e) { throw getTIOError(e); } finally { closeTable(htable); } }
@Override public TResult increment(ByteBuffer table, TIncrement increment) throws TIOError, TException { checkReadOnlyMode(); Table htable = getTable(table); try { return resultFromHBase(htable.increment(incrementFromThrift(increment))); } catch (IOException e) { throw getTIOError(e); } finally { closeTable(htable); } }
Delete delete = deleteFromThrift(tDelete); assertEquals(Durability.SKIP_WAL, delete.getDurability()); delete = deleteFromThrift(tDelete); assertEquals(Durability.ASYNC_WAL, delete.getDurability()); delete = deleteFromThrift(tDelete); assertEquals(Durability.SYNC_WAL, delete.getDurability()); delete = deleteFromThrift(tDelete); assertEquals(Durability.FSYNC_WAL, delete.getDurability()); Put put = putFromThrift(tPut); assertEquals(Durability.SKIP_WAL, put.getDurability()); put = putFromThrift(tPut); assertEquals(Durability.ASYNC_WAL, put.getDurability()); put = putFromThrift(tPut); assertEquals(Durability.SYNC_WAL, put.getDurability()); put = putFromThrift(tPut); assertEquals(Durability.FSYNC_WAL, put.getDurability()); Increment increment = incrementFromThrift(tIncrement); assertEquals(Durability.SKIP_WAL, increment.getDurability()); increment = incrementFromThrift(tIncrement); assertEquals(Durability.ASYNC_WAL, increment.getDurability());
/** * Converts multiple {@link TPut}s (Thrift) into a list of {@link Put}s (HBase). * * @param in list of <code>TPut</code>s to convert * * @return list of converted <code>Put</code>s * * @see #putFromThrift(TPut) */ public static List<Put> putsFromThrift(List<TPut> in) { List<Put> out = new ArrayList<>(in.size()); for (TPut put : in) { out.add(putFromThrift(put)); } return out; }
/** * Converts multiple {@link TDelete}s (Thrift) into a list of {@link Delete}s (HBase). * * @param in list of <code>TDelete</code>s to convert * * @return list of converted <code>Delete</code>s * * @see #deleteFromThrift(TDelete) */ public static List<Delete> deletesFromThrift(List<TDelete> in) { List<Delete> out = new ArrayList<>(in.size()); for (TDelete delete : in) { out.add(deleteFromThrift(delete)); } return out; }
/** * Creates a {@link RowMutations} (HBase) from a {@link TRowMutations} (Thrift) * * @param in the <code>TRowMutations</code> to convert * * @return converted <code>RowMutations</code> */ public static RowMutations rowMutationsFromThrift(TRowMutations in) throws IOException { List<TMutation> mutations = in.getMutations(); RowMutations out = new RowMutations(in.getRow(), mutations.size()); for (TMutation mutation : mutations) { if (mutation.isSetPut()) { out.add(putFromThrift(mutation.getPut())); } if (mutation.isSetDeleteSingle()) { out.add(deleteFromThrift(mutation.getDeleteSingle())); } } return out; }
/** * Converts multiple {@link TGet}s (Thrift) into a list of {@link Get}s (HBase). * * @param in list of <code>TGet</code>s to convert * * @return list of <code>Get</code> objects * * @throws IOException if an invalid time range or max version parameter is given * @see #getFromThrift(TGet) */ public static List<Get> getsFromThrift(List<TGet> in) throws IOException { List<Get> out = new ArrayList<>(in.size()); for (TGet get : in) { out.add(getFromThrift(get)); } return out; }
@Test public void testConsistency() throws Exception { byte[] rowName = Bytes.toBytes("testConsistency"); TGet tGet = new TGet(wrap(rowName)); tGet.setConsistency(TConsistency.STRONG); Get get = getFromThrift(tGet); assertEquals(Consistency.STRONG, get.getConsistency()); tGet.setConsistency(TConsistency.TIMELINE); tGet.setTargetReplicaId(1); get = getFromThrift(tGet); assertEquals(Consistency.TIMELINE, get.getConsistency()); assertEquals(1, get.getReplicaId()); TScan tScan = new TScan(); tScan.setConsistency(TConsistency.STRONG); Scan scan = scanFromThrift(tScan); assertEquals(Consistency.STRONG, scan.getConsistency()); tScan.setConsistency(TConsistency.TIMELINE); tScan.setTargetReplicaId(1); scan = scanFromThrift(tScan); assertEquals(Consistency.TIMELINE, scan.getConsistency()); assertEquals(1, scan.getReplicaId()); TResult tResult = new TResult(); assertFalse(tResult.isSetStale()); tResult.setStale(true); assertTrue(tResult.isSetStale()); }
@Override public List<TResult> getScannerResults(ByteBuffer table, TScan scan, int numRows) throws TIOError, TException { Table htable = getTable(table); List<TResult> results = null; ResultScanner scanner = null; try { scanner = htable.getScanner(scanFromThrift(scan)); results = resultsFromHBase(scanner.next(numRows)); } catch (IOException e) { throw getTIOError(e); } finally { if (scanner != null) { scanner.close(); } closeTable(htable); } return results; }
@Override public int openScanner(ByteBuffer table, TScan scan) throws TIOError, TException { Table htable = getTable(table); ResultScanner resultScanner = null; try { resultScanner = htable.getScanner(scanFromThrift(scan)); } catch (IOException e) { throw getTIOError(e); } finally { closeTable(htable); } return addScanner(resultScanner); }
@Override public TResult append(ByteBuffer table, TAppend append) throws TIOError, TException { checkReadOnlyMode(); Table htable = getTable(table); try { return resultFromHBase(htable.append(appendFromThrift(append))); } catch (IOException e) { throw getTIOError(e); } finally { closeTable(htable); } }
@Override public void putMultiple(ByteBuffer table, List<TPut> puts) throws TIOError, TException { checkReadOnlyMode(); Table htable = getTable(table); try { htable.put(putsFromThrift(puts)); } catch (IOException e) { throw getTIOError(e); } finally { closeTable(htable); } }
/** * Converts multiple {@link Result}s (HBase) into a list of {@link TResult}s (Thrift). * * @param in array of <code>Result</code>s to convert * * @return list of converted <code>TResult</code>s * * @see #resultFromHBase(Result) */ public static List<TResult> resultsFromHBase(Result[] in) { List<TResult> out = new ArrayList<>(in.length); for (Result result : in) { out.add(resultFromHBase(result)); } return out; }
@Override public List<TResult> getScannerRows(int scannerId, int numRows) throws TIOError, TIllegalArgument, TException { ResultScanner scanner = getScanner(scannerId); if (scanner == null) { TIllegalArgument ex = new TIllegalArgument(); ex.setMessage("Invalid scanner Id"); throw ex; } try { connectionCache.updateConnectionAccessTime(); return resultsFromHBase(scanner.next(numRows)); } catch (IOException e) { throw getTIOError(e); } }
@Override public List<Boolean> existsAll(ByteBuffer table, List<TGet> gets) throws TIOError, TException { Table htable = getTable(table); try { boolean[] exists = htable.existsAll(getsFromThrift(gets)); List<Boolean> result = new ArrayList<>(exists.length); for (boolean exist : exists) { result.add(exist); } return result; } catch (IOException e) { throw getTIOError(e); } finally { closeTable(htable); } }
@Override public List<TDelete> deleteMultiple(ByteBuffer table, List<TDelete> deletes) throws TIOError, TException { HTableInterface htable = getTable(table.array()); List<Delete> tempDeletes = deletesFromThrift(deletes); try { htable.delete(tempDeletes); } catch (IOException e) { throw getTIOError(e); } finally { closeTable(htable); } return deletesFromHBase(tempDeletes); }
Delete delete = deleteFromThrift(tDelete); assertEquals(Durability.SKIP_WAL, delete.getDurability()); delete = deleteFromThrift(tDelete); assertEquals(Durability.ASYNC_WAL, delete.getDurability()); delete = deleteFromThrift(tDelete); assertEquals(Durability.SYNC_WAL, delete.getDurability()); delete = deleteFromThrift(tDelete); assertEquals(Durability.FSYNC_WAL, delete.getDurability()); Put put = putFromThrift(tPut); assertEquals(Durability.SKIP_WAL, put.getDurability()); put = putFromThrift(tPut); assertEquals(Durability.ASYNC_WAL, put.getDurability()); put = putFromThrift(tPut); assertEquals(Durability.SYNC_WAL, put.getDurability()); put = putFromThrift(tPut); assertEquals(Durability.FSYNC_WAL, put.getDurability()); Increment increment = incrementFromThrift(tIncrement); assertEquals(Durability.SKIP_WAL, increment.getDurability()); increment = incrementFromThrift(tIncrement); assertEquals(Durability.ASYNC_WAL, increment.getDurability());