@@ -34,15 +34,17 @@ class Session {
3434
3535 /**
3636 * @constructor
37- * @param {string } mode - the default access mode for this session.
38- * @param connectionProvider - the connection provider to acquire connections from.
37+ * @param {string } mode the default access mode for this session.
38+ * @param {ConnectionProvider } connectionProvider - the connection provider to acquire connections from.
39+ * @param {string } bookmark - the initial bookmark for this session.
3940 */
40- constructor ( mode , connectionProvider ) {
41+ constructor ( mode , connectionProvider , bookmark ) {
4142 this . _mode = mode ;
4243 this . _readConnectionHolder = new ConnectionHolder ( READ , connectionProvider ) ;
4344 this . _writeConnectionHolder = new ConnectionHolder ( WRITE , connectionProvider ) ;
4445 this . _open = true ;
4546 this . _hasTx = false ;
47+ this . _lastBookmark = bookmark ;
4648 }
4749
4850 /**
@@ -84,11 +86,17 @@ class Session {
8486 *
8587 * While a transaction is open the session cannot be used to run statements outside the transaction.
8688 *
89+ * @param {string } bookmark - a reference to a previous transaction. DEPRECATED: This function is deprecated in
90+ * favour of {@link Driver#session(string)} that accepts an initial bookmark. Session will ensure that all nested
91+ * transactions are chained with bookmarks to guarantee causal consistency.
8792 * @returns {Transaction } - New Transaction
8893 */
8994 beginTransaction ( bookmark ) {
9095 if ( bookmark ) {
91- assertString ( bookmark , "Bookmark" ) ;
96+ assertString ( bookmark , 'Bookmark' ) ;
97+ }
98+ if ( typeof bookmark !== 'undefined' ) {
99+ this . _lastBookmark = bookmark ;
92100 }
93101
94102 if ( this . _hasTx ) {
@@ -99,21 +107,25 @@ class Session {
99107
100108 this . _hasTx = true ;
101109
102- // todo: add mode parameter
103- const mode = this . _mode ;
104- const connectionHolder = this . _connectionHolderWithMode ( mode ) ;
110+ const connectionHolder = this . _connectionHolderWithMode ( this . _mode ) ;
105111 connectionHolder . initializeConnection ( ) ;
106112
107113 return new Transaction ( connectionHolder , ( ) => {
108114 this . _hasTx = false ;
109115 } ,
110- this . _onRunFailure ( ) , bookmark , ( bookmark ) => { this . _lastBookmark = bookmark } ) ;
116+ this . _onRunFailure ( ) , this . _lastBookmark , this . _updateBookmark . bind ( this ) ) ;
111117 }
112118
113119 lastBookmark ( ) {
114120 return this . _lastBookmark ;
115121 }
116122
123+ _updateBookmark ( newBookmark ) {
124+ if ( newBookmark ) {
125+ this . _lastBookmark = newBookmark ;
126+ }
127+ }
128+
117129 /**
118130 * Close this session.
119131 * @param {function() } callback - Function to be called after the session has been closed
0 commit comments