def auto_run( self, graph_name, cypher, parameters=None, readonly=False, # after=None, metadata=None, timeout=None ): self._assert_open() self._assert_no_transaction() self._transaction = BoltTransaction( graph_name, self.protocol_version, readonly, # after, metadata, timeout ) result = self._run(graph_name, cypher, parameters or {}, self._transaction.extra, final=True) try: result.buffer() except BrokenWireError as error: raise_from( TransactionError("Transaction could not run " "due to disconnection"), error) else: try: self._audit(self._transaction) except Failure as failure: raise_from(TransactionError("Failed to run transaction"), failure) else: return result
def begin( self, graph_name, readonly=False, # after=None, metadata=None, timeout=None ): self._assert_open() self._assert_no_transaction() self._transaction = BoltTransaction( graph_name, self.protocol_version, readonly, # after, metadata, timeout ) log.debug("[#%04X] C: BEGIN %r", self.local_port, self._transaction.extra) response = self._write_request(0x11, self._transaction.extra) try: self._sync(response) except BrokenWireError as error: raise_from( TransactionError("Transaction could not begin " "due to disconnection"), error) else: try: self._audit(self._transaction) except Failure as failure: raise_from(TransactionError("Failed to begin transaction"), failure) else: if callable(self._on_bind): self._on_bind(self._transaction, self) return self._transaction
def auto_run( self, graph_name, cypher, parameters=None, readonly=False, # after=None, metadata=None, timeout=None ): self._set_transaction( graph_name, readonly=readonly, # after, metadata, timeout ) result = self._run(graph_name, cypher, parameters or {}, final=True) try: # TODO: can we avoid this buffering before the first # PULL/DISCARD is sent? result.buffer() except BrokenWireError as error: raise_from( TransactionError("Transaction could not run " "due to disconnection"), error) else: try: self._audit(self._transaction) except Failure as failure: raise_from(TransactionError("Failed to run transaction"), failure) else: return result
def begin( self, graph_name, readonly=False, # after=None, metadata=None, timeout=None ): self._set_transaction( graph_name, readonly=readonly, # after, metadata, timeout ) log.debug("[#%04X] C: RUN 'BEGIN' %r", self.local_port, self._transaction.extra) log.debug("[#%04X] C: DISCARD_ALL", self.local_port) responses = (self._write_request(0x10, "BEGIN", self._transaction.extra), self._write_request(0x2F)) try: self._sync(*responses) except BrokenWireError as error: raise_from( TransactionError("Transaction could not begin " "due to disconnection"), error) else: try: self._audit(self._transaction) except Failure as failure: raise_from(TransactionError("Failed to begin transaction"), failure) else: if callable(self._on_bind): self._on_bind(self._transaction, self) return self._transaction
def begin(self, graph_name, readonly=False, # after=None, metadata=None, timeout=None ): if graph_name and not self.supports_multi(): raise TypeError("Neo4j {} does not support " "named graphs".format(self.neo4j_version)) if readonly: raise TypeError("Readonly transactions are not supported over HTTP") # if after: # raise TypeError("Bookmarks are not supported over HTTP") # if metadata: # raise TypeError("Transaction metadata is not supported over HTTP") # if timeout: # raise TypeError("Transaction timeouts are not supported over HTTP") try: r = self._post(HTTPTransaction.begin_uri(graph_name)) except ConnectionError as error: raise_from(TransactionError("Transaction failed to begin"), error) except HTTPError as error: raise_from(TransactionError("Transaction failed to begin"), error) else: if r.status != 201: raise TransactionError("Transaction failed to begin " "due to HTTP status %r" % r.status) rs = HTTPResponse.from_json(r.status, r.data.decode("utf-8")) location_path = urlsplit(r.headers["Location"]).path tx = HTTPTransaction(graph_name, location_path.rpartition("/")[-1]) self.release() rs.audit(tx) return tx
def _assert_is_last_result(self, result): if not self._transaction: raise TransactionError("No active transaction") if result is not self._transaction.last(): raise NotImplementedError( "Random query access is not yet supported")
def _assert_is_last_result(self, result): if not self._transaction: raise TransactionError("No active transaction") if result is not self._transaction.last(): raise TypeError( "Random query access is not supported before Bolt 4.0")
def _assert_no_transaction(self): if self._transaction: raise TransactionError( "Bolt connection already holds transaction %r", self._transaction)
def _assert_valid_tx(self, tx): if not tx: raise TransactionError("No transaction") if tx not in self._transactions: raise TransactionError("Invalid transaction")