1818 */
1919import RequestMessage from './request-message' ;
2020import * as v1 from './packstream-v1' ;
21+ import { newError } from '../error' ;
22+ import Bookmark from './bookmark' ;
23+ import TxConfig from './tx-config' ;
2124
2225export default class BoltProtocol {
2326
@@ -49,6 +52,15 @@ export default class BoltProtocol {
4952 return this . _unpacker ;
5053 }
5154
55+ /**
56+ * Transform metadata received in SUCCESS message before it is passed to the handler.
57+ * @param {object } metadata the received metadata.
58+ * @return {object } transformed metadata.
59+ */
60+ transformMetadata ( metadata ) {
61+ return metadata ;
62+ }
63+
5264 /**
5365 * Perform initialization and authentication of the underlying connection.
5466 * @param {string } clientName the client name.
@@ -63,9 +75,12 @@ export default class BoltProtocol {
6375 /**
6476 * Begin an explicit transaction.
6577 * @param {Bookmark } bookmark the bookmark.
78+ * @param {TxConfig } txConfig the configuration.
6679 * @param {StreamObserver } observer the response observer.
6780 */
68- beginTransaction ( bookmark , observer ) {
81+ beginTransaction ( bookmark , txConfig , observer ) {
82+ assertTxConfigIsEmpty ( txConfig , this . _connection , observer ) ;
83+
6984 const runMessage = RequestMessage . run ( 'BEGIN' , bookmark . asBeginTransactionParameters ( ) ) ;
7085 const pullAllMessage = RequestMessage . pullAll ( ) ;
7186
@@ -78,24 +93,29 @@ export default class BoltProtocol {
7893 * @param {StreamObserver } observer the response observer.
7994 */
8095 commitTransaction ( observer ) {
81- this . run ( 'COMMIT' , { } , observer ) ;
96+ this . run ( 'COMMIT' , { } , Bookmark . empty ( ) , TxConfig . empty ( ) , observer ) ;
8297 }
8398
8499 /**
85100 * Rollback the explicit transaction.
86101 * @param {StreamObserver } observer the response observer.
87102 */
88103 rollbackTransaction ( observer ) {
89- this . run ( 'ROLLBACK' , { } , observer ) ;
104+ this . run ( 'ROLLBACK' , { } , Bookmark . empty ( ) , TxConfig . empty ( ) , observer ) ;
90105 }
91106
92107 /**
93108 * Send a Cypher statement through the underlying connection.
94109 * @param {string } statement the cypher statement.
95110 * @param {object } parameters the statement parameters.
111+ * @param {Bookmark } bookmark the bookmark.
112+ * @param {TxConfig } txConfig the auto-commit transaction configuration.
96113 * @param {StreamObserver } observer the response observer.
97114 */
98- run ( statement , parameters , observer ) {
115+ run ( statement , parameters , bookmark , txConfig , observer ) {
116+ // bookmark is ignored in this version of the protocol
117+ assertTxConfigIsEmpty ( txConfig , this . _connection , observer ) ;
118+
99119 const runMessage = RequestMessage . run ( statement , parameters ) ;
100120 const pullAllMessage = RequestMessage . pullAll ( ) ;
101121
@@ -120,3 +140,20 @@ export default class BoltProtocol {
120140 return new v1 . Unpacker ( disableLosslessIntegers ) ;
121141 }
122142}
143+
144+ /**
145+ * @param {TxConfig } txConfig the auto-commit transaction configuration.
146+ * @param {Connection } connection the connection.
147+ * @param {StreamObserver } observer the response observer.
148+ */
149+ function assertTxConfigIsEmpty ( txConfig , connection , observer ) {
150+ if ( ! txConfig . isEmpty ( ) ) {
151+ const error = newError ( 'Driver is connected to the database that does not support transaction configuration. ' +
152+ 'Please upgrade to neo4j 3.5.0 or later in order to use this functionality' ) ;
153+
154+ // unsupported API was used, consider this a fatal error for the current connection
155+ connection . _handleFatalError ( error ) ;
156+ observer . onError ( error ) ;
157+ throw error ;
158+ }
159+ }
0 commit comments