use of com.palantir.atlasdb.keyvalue.api.Value in project atlasdb by palantir.
the class JdbcKeyValueService method addGarbageCollectionSentinelValues.
@Override
public void addGarbageCollectionSentinelValues(final TableReference tableRef, Iterable<Cell> cells) {
int numCells = Iterables.size(cells);
if (numCells == 0) {
return;
}
for (List<Cell> partCells : Iterables.partition(cells, batchSizeForMutations)) {
Long timestamp = Value.INVALID_VALUE_TIMESTAMP;
byte[] value = new byte[0];
final RowN[] rows = new RowN[numCells];
int i = 0;
for (Cell cell : partCells) {
rows[i++] = row(new Object[] { cell.getRowName(), cell.getColumnName(), timestamp, value });
}
run((Function<DSLContext, Void>) ctx -> {
ctx.insertInto(table(tableName(tableRef)), field(ROW_NAME, byte[].class), field(COL_NAME, byte[].class), field(TIMESTAMP, Long.class), field(VALUE, byte[].class)).select(ctx.select(T1_ROW_NAME, T1_COL_NAME, T1_TIMESTAMP, T1_VALUE).from(values(ctx, rows, TEMP_TABLE_1, ROW_NAME, COL_NAME, TIMESTAMP, VALUE)).whereNotExists(ctx.selectOne().from(atlasTable(tableRef).as(ATLAS_TABLE)).where(A_ROW_NAME.eq(T1_ROW_NAME).and(A_COL_NAME.eq(T1_COL_NAME)).and(A_TIMESTAMP.eq(T1_TIMESTAMP))))).execute();
return null;
});
}
}
use of com.palantir.atlasdb.keyvalue.api.Value in project atlasdb by palantir.
the class JdbcKeyValueService method getRange.
@Override
public ClosableIterator<RowResult<Value>> getRange(final TableReference tableRef, final RangeRequest rangeRequest, final long timestamp) {
Iterable<RowResult<Value>> iter = new AbstractPagingIterable<RowResult<Value>, TokenBackedBasicResultsPage<RowResult<Value>, byte[]>>() {
@Override
protected TokenBackedBasicResultsPage<RowResult<Value>, byte[]> getFirstPage() {
return getPageWithValues(tableRef, rangeRequest, timestamp);
}
@Override
protected TokenBackedBasicResultsPage<RowResult<Value>, byte[]> getNextPage(TokenBackedBasicResultsPage<RowResult<Value>, byte[]> previous) {
byte[] startRow = previous.getTokenForNextPage();
RangeRequest newRange = rangeRequest.getBuilder().startRowInclusive(startRow).build();
return getPageWithValues(tableRef, newRange, timestamp);
}
};
return ClosableIterators.wrap(iter.iterator());
}
use of com.palantir.atlasdb.keyvalue.api.Value in project atlasdb by palantir.
the class JdbcKeyValueService method getRowsSomeColumns.
private Map<Cell, Value> getRowsSomeColumns(final TableReference tableRef, final Iterable<byte[]> rows, final ColumnSelection columnSelection, final long timestamp) {
if (Iterables.isEmpty(rows)) {
return ImmutableMap.of();
}
return run(ctx -> {
Select<? extends Record> query = getLatestTimestampQuerySomeColumns(ctx, tableRef, ImmutableList.copyOf(rows), columnSelection.getSelectedColumns(), timestamp);
Result<? extends Record> records = fetchValues(ctx, tableRef, query);
Map<Cell, Value> results = Maps.newHashMapWithExpectedSize(records.size());
for (Record record : records) {
results.put(Cell.create(record.getValue(A_ROW_NAME), record.getValue(A_COL_NAME)), Value.create(record.getValue(A_VALUE), record.getValue(A_TIMESTAMP)));
}
return results;
});
}
use of com.palantir.atlasdb.keyvalue.api.Value in project atlasdb by palantir.
the class JdbcKeyValueService method getRowsAllColumns.
private Map<Cell, Value> getRowsAllColumns(final TableReference tableRef, final Iterable<byte[]> rows, final long timestamp) {
if (Iterables.isEmpty(rows)) {
return ImmutableMap.of();
}
return run(ctx -> {
Select<? extends Record> query = getLatestTimestampQueryAllColumns(ctx, tableRef, ImmutableList.copyOf(rows), timestamp);
Result<? extends Record> records = fetchValues(ctx, tableRef, query);
Map<Cell, Value> results = Maps.newHashMapWithExpectedSize(records.size());
for (Record record : records) {
results.put(Cell.create(record.getValue(A_ROW_NAME), record.getValue(A_COL_NAME)), Value.create(record.getValue(A_VALUE), record.getValue(A_TIMESTAMP)));
}
return results;
});
}
use of com.palantir.atlasdb.keyvalue.api.Value in project atlasdb by palantir.
the class SimpleTransactionService method get.
@Override
public Long get(long startTimestamp) {
Cell cell = getTransactionCell(startTimestamp);
Map<Cell, Value> returnMap = keyValueService.get(TransactionConstants.TRANSACTION_TABLE, ImmutableMap.of(cell, MAX_TIMESTAMP));
if (returnMap.containsKey(cell)) {
return TransactionConstants.getTimestampForValue(returnMap.get(cell).getContents());
} else {
return null;
}
}
Aggregations