-
Notifications
You must be signed in to change notification settings - Fork 197
Bookmarking #104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bookmarking #104
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -241,6 +241,8 @@ class Session(object): | |
|
||
transaction = None | ||
|
||
last_bookmark = None | ||
|
||
def __init__(self, connection, access_mode=None): | ||
self.connection = connection | ||
self.access_mode = access_mode | ||
|
@@ -265,6 +267,8 @@ def run(self, statement, parameters=None, **kwparameters): | |
:return: Cypher result | ||
:rtype: :class:`.StatementResult` | ||
""" | ||
self.last_bookmark = None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to do this initialization together with initialization in line 314? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, yes we do. This clears the bookmark before a run, it's not initialisation. |
||
|
||
statement = _norm_statement(statement) | ||
parameters = _norm_parameters(parameters, **kwparameters) | ||
|
||
|
@@ -301,13 +305,15 @@ def close(self): | |
self.transaction.close() | ||
if self.connection: | ||
if not self.connection.closed: | ||
self.connection.fetch_all() | ||
self.connection.sync() | ||
self.connection.in_use = False | ||
self.connection = None | ||
|
||
def begin_transaction(self): | ||
def begin_transaction(self, bookmark=None): | ||
""" Create a new :class:`.Transaction` within this session. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should docstring also say something about the bookmark parameter? |
||
|
||
:param bookmark: a bookmark to which the server should | ||
synchronise before beginning the transaction | ||
:return: new :class:`.Transaction` instance. | ||
""" | ||
if self.transaction: | ||
|
@@ -316,15 +322,23 @@ def begin_transaction(self): | |
def clear_transaction(): | ||
self.transaction = None | ||
|
||
self.run("BEGIN") | ||
parameters = {} | ||
if bookmark is not None: | ||
parameters["bookmark"] = bookmark | ||
|
||
self.run("BEGIN", parameters) | ||
self.transaction = Transaction(self, on_close=clear_transaction) | ||
return self.transaction | ||
|
||
def commit_transaction(self): | ||
self.run("COMMIT") | ||
result = self.run("COMMIT") | ||
self.connection.sync() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a way to test that we send commit and rollback messages eagerly? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tests added for that. |
||
summary = result.summary() | ||
self.last_bookmark = summary.metadata.get("bookmark") | ||
|
||
def rollback_transaction(self): | ||
self.run("ROLLBACK") | ||
self.connection.sync() | ||
|
||
|
||
class Transaction(object): | ||
|
@@ -342,7 +356,7 @@ class Transaction(object): | |
#: and rolled back otherwise. This attribute can be set in user code | ||
#: multiple times before a transaction completes with only the final | ||
#: value taking effect. | ||
success = False | ||
success = None | ||
|
||
#: Indicator to show whether the transaction has been closed, either | ||
#: with commit or rollback. | ||
|
@@ -356,8 +370,8 @@ def __enter__(self): | |
return self | ||
|
||
def __exit__(self, exc_type, exc_value, traceback): | ||
if exc_value: | ||
self.success = False | ||
if self.success is None: | ||
self.success = not bool(exc_type) | ||
self.close() | ||
|
||
def run(self, statement, parameters=None, **kwparameters): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
server_version
field is initialized here but where is it read?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just used in a test right now. It will conflict with #108 so I'll adjust it properly for that.