def __init__(self, client, read_only=False): self._dg = client self._dc = client.any_client() self._ctx = api.TxnContext() self._finished = False self._mutated = False self._read_only = read_only
def __init__(self, client): self._dc = client self._ctx = api.TxnContext() self._dc.set_lin_read(self._ctx) self._finished = False self._mutated = False self._sequencing = api.LinRead.CLIENT_SIDE
def __init__(self, client, read_only=False, best_effort=False): if not read_only and best_effort: raise Exception('Best effort transactions are only compatible with ' 'read-only transactions') self._dg = client self._dc = client.any_client() self._ctx = api.TxnContext() self._finished = False self._mutated = False self._read_only = read_only self._best_effort = best_effort
def commit(self, *args, **kwargs): """Commits any mutations performed in the transaction. Once the transaction is committed its lifespan is complete and no further mutations or commits can be made.""" if self._finished: raise Exception('Cannot commit a transaction which is complete') self._finished = True if not self._mutated: return txn_context = api.TxnContext(start_ts=self.start_ts, keys=self.keys, lin_read=self.lin_read) resp_txn_context = self.client.stub.CommitOrAbort( txn_context, *args, **kwargs) return resp_txn_context