@ThreadSafe public class SpannerKVTransaction extends ForwardingKVStore implements KVTransaction
SpannerKVDatabase transaction.| Modifier and Type | Field and Description |
|---|---|
protected DatabaseClient |
client |
protected TimestampBound |
consistency |
protected SpannerKVDatabase |
kvdb |
protected Logger |
log |
protected String |
tableName |
| Modifier | Constructor and Description |
|---|---|
protected |
SpannerKVTransaction(SpannerKVDatabase kvdb,
DatabaseClient client,
String tableName,
TimestampBound consistency)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
commit() |
protected KVStore |
delegate() |
byte[] |
get(byte[] key) |
KVPair |
getAtLeast(byte[] minKey,
byte[] maxKey) |
KVPair |
getAtMost(byte[] maxKey,
byte[] minKey) |
TimestampBound |
getConsistency()
Get the consistency level configured for this transaction.
|
SpannerKVDatabase |
getKVDatabase() |
CloseableIterator<KVPair> |
getRange(byte[] minKey,
byte[] maxKey,
boolean reverse) |
Timestamp |
getTimestamp()
Get the timestamp associated with this transaction.
|
boolean |
isReadOnly() |
boolean |
isStrongConsistency()
Convenience method to determine whether this transaction is using strong consistency.
|
CloseableKVStore |
mutableSnapshot()
Create a mutable snapshot of this transaction.
|
void |
rollback() |
void |
setReadOnly(boolean readOnly) |
void |
setTimeout(long timeout)
Set transaction timeout.
|
Future<Void> |
watchKey(byte[] key)
Set key watch.
|
protected RuntimeException |
wrapException(SpannerException e) |
adjustCounter, decodeCounter, encodeCounter, put, remove, removeRangeclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitadjustCounter, decodeCounter, encodeCounter, getRange, getRange, put, remove, removeRangeprotected final Logger log
protected final SpannerKVDatabase kvdb
protected final DatabaseClient client
protected final String tableName
protected final TimestampBound consistency
protected SpannerKVTransaction(SpannerKVDatabase kvdb, DatabaseClient client, String tableName, TimestampBound consistency)
kvdb - associated databaseclient - client for accesstableName - Spanner key/value database table nameconsistency - transaction consistency levelIllegalArgumentException - if any paramter is nullpublic TimestampBound getConsistency()
Note that read-write transactions always use strong consistency.
public boolean isStrongConsistency()
public Timestamp getTimestamp()
For read-only transactions, this returns the Spanner timestamp at which the data was accessed. It should not be invoked until at least one data query has occurred.
For read-write transactions, this returns the Spanner timestamp at which the changes were applied. It should not be invoked until the transaction is committed.
IllegalStateException - if timestamp is not available yetpublic SpannerKVDatabase getKVDatabase()
getKVDatabase in interface KVTransactionpublic void setTimeout(long timeout)
Currently not supported; this method does nothing.
setTimeout in interface KVTransactionpublic boolean isReadOnly()
isReadOnly in interface KVTransactionpublic void setReadOnly(boolean readOnly)
setReadOnly in interface KVTransactionpublic void commit()
commit in interface KVTransactionpublic void rollback()
rollback in interface KVTransactionpublic Future<Void> watchKey(byte[] key)
Key watches are not supported.
watchKey in interface KVTransactionUnsupportedOperationException - alwayspublic CloseableKVStore mutableSnapshot()
This method is not supported.
With Spanner, a transaction is not needed to create mutable snapshots; instead, see
SpannerKVDatabase.snapshot() and MutableView.
mutableSnapshot in interface KVTransactionUnsupportedOperationException - alwayspublic byte[] get(byte[] key)
get in interface KVStoreget in class ForwardingKVStorepublic KVPair getAtLeast(byte[] minKey, byte[] maxKey)
getAtLeast in interface KVStoregetAtLeast in class ForwardingKVStorepublic KVPair getAtMost(byte[] maxKey, byte[] minKey)
getAtMost in interface KVStoregetAtMost in class ForwardingKVStorepublic CloseableIterator<KVPair> getRange(byte[] minKey, byte[] maxKey, boolean reverse)
getRange in interface KVStoregetRange in class ForwardingKVStoreprotected KVStore delegate()
delegate in class ForwardingKVStoreprotected RuntimeException wrapException(SpannerException e)
Copyright © 2017. All rights reserved.