public interface ReadTransaction extends ReadTransactionContext
Transaction. This is the interface that
Transaction's snapshot presents.Transaction.commit() and wait on the result on all transactions,
even ones that only read. This is done automatically when using the retry loops from
Database.run(java.util.function.Function). This is explained more in the intro to Transaction.Transaction| Modifier and Type | Field and Description |
|---|---|
static int |
ROW_LIMIT_UNLIMITED
When passed to a
getRange() call that takes a limit parameter,
indicates that the query should return unlimited rows. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
addReadConflictKeyIfNotSnapshot(byte[] key)
Adds the read conflict range that this
ReadTransaction would have added as if it had read
the given key. |
boolean |
addReadConflictRangeIfNotSnapshot(byte[] keyBegin,
byte[] keyEnd)
Adds the read conflict range that this
ReadTransaction would have added as if it had read
the given key range. |
java.util.concurrent.CompletableFuture<byte[]> |
get(byte[] key)
Gets a value from the database.
|
java.util.concurrent.CompletableFuture<byte[]> |
getKey(KeySelector selector)
Returns the key referenced by the specified
KeySelector. |
AsyncIterable<KeyValue> |
getRange(byte[] begin,
byte[] end)
Gets an ordered range of keys and values from the database.
|
AsyncIterable<KeyValue> |
getRange(byte[] begin,
byte[] end,
int limit)
Gets an ordered range of keys and values from the database.
|
AsyncIterable<KeyValue> |
getRange(byte[] begin,
byte[] end,
int limit,
boolean reverse)
Gets an ordered range of keys and values from the database.
|
AsyncIterable<KeyValue> |
getRange(byte[] begin,
byte[] end,
int limit,
boolean reverse,
StreamingMode mode)
Gets an ordered range of keys and values from the database.
|
AsyncIterable<KeyValue> |
getRange(KeySelector begin,
KeySelector end)
Gets an ordered range of keys and values from the database.
|
AsyncIterable<KeyValue> |
getRange(KeySelector begin,
KeySelector end,
int limit)
Gets an ordered range of keys and values from the database.
|
AsyncIterable<KeyValue> |
getRange(KeySelector begin,
KeySelector end,
int limit,
boolean reverse)
Gets an ordered range of keys and values from the database.
|
AsyncIterable<KeyValue> |
getRange(KeySelector begin,
KeySelector end,
int limit,
boolean reverse,
StreamingMode mode)
Gets an ordered range of keys and values from the database.
|
AsyncIterable<KeyValue> |
getRange(Range range)
Gets an ordered range of keys and values from the database.
|
AsyncIterable<KeyValue> |
getRange(Range range,
int limit)
Gets an ordered range of keys and values from the database.
|
AsyncIterable<KeyValue> |
getRange(Range range,
int limit,
boolean reverse)
Gets an ordered range of keys and values from the database.
|
AsyncIterable<KeyValue> |
getRange(Range range,
int limit,
boolean reverse,
StreamingMode mode)
Gets an ordered range of keys and values from the database.
|
java.util.concurrent.CompletableFuture<java.lang.Long> |
getReadVersion()
Gets the version at which the reads for this
Transaction will access the database. |
boolean |
isSnapshot()
Gets whether this transaction is a snapshot view of the database.
|
TransactionOptions |
options()
Returns a set of options that can be set on a
Transaction |
void |
setReadVersion(long version)
Directly sets the version of the database at which to execute reads.
|
ReadTransaction |
snapshot()
Return a special-purpose, read-only view of the database.
|
getExecutor, read, readAsyncstatic final int ROW_LIMIT_UNLIMITED
getRange() call that takes a limit parameter,
indicates that the query should return unlimited rows.boolean isSnapshot()
ReadTransaction.
snapshot()ReadTransaction snapshot()
ReadTransaction with relaxed isolation propertiesjava.util.concurrent.CompletableFuture<java.lang.Long> getReadVersion()
Transaction will access the database.void setReadVersion(long version)
transaction_too_old errors will be thrown from read operations.
Infrequently used.version - the version at which to read from the databaseboolean addReadConflictRangeIfNotSnapshot(byte[] keyBegin,
byte[] keyEnd)
ReadTransaction would have added as if it had read
the given key range. If this is a snapshot view of the database, this will
not add the conflict range. This mirrors how reading a range through a snapshot view
of the database does not add a conflict range for the read keys.keyBegin - the first key in the range (inclusive)keyEnd - the last key in the range (exclusive)true if the read conflict range was added and false otherwiseTransaction.addReadConflictRange(byte[], byte[])boolean addReadConflictKeyIfNotSnapshot(byte[] key)
ReadTransaction would have added as if it had read
the given key. If this is a snapshot view of the database, this will
not add the conflict range. This mirrors how reading a key through a snapshot view
of the database does not add a conflict range for the read key.key - the key to add to the read conflict range set (it this is not a snapshot view of the database)true if the read conflict key was added and false otherwiseTransaction.addReadConflictKey(byte[])java.util.concurrent.CompletableFuture<byte[]> get(byte[] key)
null if the key is not
present in the database.key - the key whose value to fetch from the databaseCompletableFuture which will be set to the value corresponding to
the key or to null if the key does not exist.java.util.concurrent.CompletableFuture<byte[]> getKey(KeySelector selector)
KeySelector.
By default, the key is cached for the duration of the transaction, providing
a potential performance benefit. However, the value of the key is also retrieved,
using network bandwidth. Invoking setReadYourWritesDisable will avoid
both the caching and the increased network bandwidth.selector - the relative key location to resolveCompletableFuture which will be set to an absolute database keyKeySelectorAsyncIterable<KeyValue> getRange(KeySelector begin, KeySelector end)
KeySelectors, with the begin
KeySelector inclusive and the end KeySelector exclusive.begin - the beginning of the range (inclusive)end - the end of the range (exclusive)KeySelector,
AsyncIteratorAsyncIterable<KeyValue> getRange(KeySelector begin, KeySelector end, int limit)
KeySelectors, with the begin
KeySelector inclusive and the end KeySelector exclusive.begin - the beginning of the range (inclusive)end - the end of the range (exclusive)limit - the maximum number of results to return. Limits results to the
first keys in the range. Pass ROW_LIMIT_UNLIMITED if this query
should not limit the number of results.KeySelector,
AsyncIteratorAsyncIterable<KeyValue> getRange(KeySelector begin, KeySelector end, int limit, boolean reverse)
KeySelectors, with the begin
KeySelector inclusive and the end KeySelector exclusive.begin - the beginning of the range (inclusive)end - the end of the range (exclusive)limit - the maximum number of results to return. Limits results to the
first keys in the range. Pass ROW_LIMIT_UNLIMITED if this query
should not limit the number of results. If reverse is true rows
will be limited starting at the end of the range.reverse - return results starting at the end of the range in reverse order.
Reading ranges in reverse is supported natively by the database and should
have minimal extra cost.KeySelector,
AsyncIteratorAsyncIterable<KeyValue> getRange(KeySelector begin, KeySelector end, int limit, boolean reverse, StreamingMode mode)
KeySelectors, with the begin
KeySelector inclusive and the end KeySelector exclusive.begin - the beginning of the range (inclusive)end - the end of the range (exclusive)limit - the maximum number of results to return. Limits results to the
first keys in the range. Pass ROW_LIMIT_UNLIMITED if this query
should not limit the number of results. If reverse is true rows
will be limited starting at the end of the range.reverse - return results starting at the end of the range in reverse order.
Reading ranges in reverse is supported natively by the database and should
have minimal extra cost.mode - provide a hint about how the results are to be used. This
can provide speed improvements or efficiency gains based on the caller's
knowledge of the upcoming access pattern.
When converting the result of this query to a list using AsyncIterable.asList() with the ITERATOR streaming
mode, the query is automatically modified to fetch results in larger batches. This is done because it is
known in advance that the AsyncIterable.asList() function will fetch all results in the range. If a limit is specified,
the EXACT streaming mode will be used, and otherwise it will use WANT_ALL.
To achieve comparable performance when iterating over an entire range without using AsyncIterable.asList(), the same
streaming mode would need to be used.
KeySelector,
AsyncIteratorAsyncIterable<KeyValue> getRange(byte[] begin, byte[] end)
byte[] arrays, with the begin
key inclusive and the end key exclusive.begin - the beginning of the range (inclusive)end - the end of the range (exclusive)KeySelector,
AsyncIteratorAsyncIterable<KeyValue> getRange(byte[] begin, byte[] end, int limit)
byte[] arrays, with the begin
key inclusive and the end key exclusive.begin - the beginning of the range (inclusive)end - the end of the range (exclusive)limit - the maximum number of results to return. Limits results to the
first keys in the range. Pass ROW_LIMIT_UNLIMITED if this query
should not limit the number of results.KeySelector,
AsyncIteratorAsyncIterable<KeyValue> getRange(byte[] begin, byte[] end, int limit, boolean reverse)
byte[] arrays, with the begin
key inclusive and the end key exclusive.begin - the beginning of the range (inclusive)end - the end of the range (exclusive)limit - the maximum number of results to return. Limits results to the
first keys in the range. Pass ROW_LIMIT_UNLIMITED if this query
should not limit the number of results. If reverse is true rows
will be limited starting at the end of the range.reverse - return results starting at the end of the range in reverse order.
Reading ranges in reverse is supported natively by the database and should
have minimal extra cost.KeySelector,
AsyncIteratorAsyncIterable<KeyValue> getRange(byte[] begin, byte[] end, int limit, boolean reverse, StreamingMode mode)
byte[] arrays, with the begin
key inclusive and the end key exclusive.begin - the beginning of the range (inclusive)end - the end of the range (exclusive)limit - the maximum number of results to return. Limits results to the
first keys in the range. Pass ROW_LIMIT_UNLIMITED if this query
should not limit the number of results. If reverse is true rows
will be limited starting at the end of the range.reverse - return results starting at the end of the range in reverse order.
Reading ranges in reverse is supported natively by the database and should
have minimal extra cost.mode - provide a hint about how the results are to be used. This
can provide speed improvements or efficiency gains based on the caller's
knowledge of the upcoming access pattern.
When converting the result of this query to a list using AsyncIterable.asList() with the ITERATOR streaming
mode, the query is automatically modified to fetch results in larger batches. This is done because it is
known in advance that the AsyncIterable.asList() function will fetch all results in the range. If a limit is specified,
the EXACT streaming mode will be used, and otherwise it will use WANT_ALL.
To achieve comparable performance when iterating over an entire range without using AsyncIterable.asList(), the same
streaming mode would need to be used.
KeySelector,
AsyncIteratorAsyncIterable<KeyValue> getRange(Range range)
byte[] arrays, with the begin
key inclusive and the end key exclusive. Ranges are returned
from calls to Tuple.range() and Range.startsWith(byte[]). getRangeStartsWith( k ) with getRange(Range.startsWith( k ))range - the range of keys to returnKeySelector,
AsyncIteratorAsyncIterable<KeyValue> getRange(Range range, int limit)
byte[] arrays, with the begin
key inclusive and the end key exclusive. Ranges are returned
from calls to Tuple.range() and Range.startsWith(byte[]). getRangeStartsWith( k ) with getRange(Range.startsWith( k ))range - the range of keys to returnlimit - the maximum number of results to return. Limits results to the
first keys in the range. Pass ROW_LIMIT_UNLIMITED if this query
should not limit the number of results.KeySelector,
AsyncIteratorAsyncIterable<KeyValue> getRange(Range range, int limit, boolean reverse)
byte[] arrays, with the begin
key inclusive and the end key exclusive. Ranges are returned
from calls to Tuple.range() and Range.startsWith(byte[]). getRangeStartsWith( k ) with getRange(Range.startsWith( k ))range - the range of keys to returnlimit - the maximum number of results to return. Limits results to the
first keys in the range. Pass ROW_LIMIT_UNLIMITED if this query
should not limit the number of results. If reverse is true rows
will be limited starting at the end of the range.reverse - return results starting at the end of the range in reverse order.
Reading ranges in reverse is supported natively by the database and should
have minimal extra cost.KeySelector,
AsyncIteratorAsyncIterable<KeyValue> getRange(Range range, int limit, boolean reverse, StreamingMode mode)
byte[] arrays, with the begin
key inclusive and the end key exclusive. Ranges are returned
from calls to Tuple.range() and Range.startsWith(byte[]). getRangeStartsWith( k ) with getRange(Range.startsWith( k ))range - the range of keys to returnlimit - the maximum number of results to return. Limits results to the
first keys in the range. Pass ROW_LIMIT_UNLIMITED if this query
should not limit the number of results. If reverse is true rows
will be limited starting at the end of the range.reverse - return results starting at the end of the range in reverse order.
Reading ranges in reverse is supported natively by the database and should
have minimal extra cost.mode - provide a hint about how the results are to be used. This
can provide speed improvements or efficiency gains based on the caller's
knowledge of the upcoming access pattern.
When converting the result of this query to a list using AsyncIterable.asList() with the ITERATOR streaming
mode, the query is automatically modified to fetch results in larger batches. This is done because it is
known in advance that the AsyncIterable.asList() function will fetch all results in the range. If a limit is specified,
the EXACT streaming mode will be used, and otherwise it will use WANT_ALL.
To achieve comparable performance when iterating over an entire range without using AsyncIterable.asList(), the same
streaming mode would need to be used.
KeySelector,
AsyncIteratorTransactionOptions options()
TransactionTransaction