18
18
*/
19
19
import RequestMessage from './request-message' ;
20
20
import * as v1 from './packstream-v1' ;
21
+ import { newError } from '../error' ;
22
+ import Bookmark from './bookmark' ;
23
+ import TxConfig from './tx-config' ;
21
24
22
25
export default class BoltProtocol {
23
26
@@ -49,6 +52,15 @@ export default class BoltProtocol {
49
52
return this . _unpacker ;
50
53
}
51
54
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
+
52
64
/**
53
65
* Perform initialization and authentication of the underlying connection.
54
66
* @param {string } clientName the client name.
@@ -63,9 +75,12 @@ export default class BoltProtocol {
63
75
/**
64
76
* Begin an explicit transaction.
65
77
* @param {Bookmark } bookmark the bookmark.
78
+ * @param {TxConfig } txConfig the configuration.
66
79
* @param {StreamObserver } observer the response observer.
67
80
*/
68
- beginTransaction ( bookmark , observer ) {
81
+ beginTransaction ( bookmark , txConfig , observer ) {
82
+ assertTxConfigIsEmpty ( txConfig , this . _connection , observer ) ;
83
+
69
84
const runMessage = RequestMessage . run ( 'BEGIN' , bookmark . asBeginTransactionParameters ( ) ) ;
70
85
const pullAllMessage = RequestMessage . pullAll ( ) ;
71
86
@@ -78,24 +93,29 @@ export default class BoltProtocol {
78
93
* @param {StreamObserver } observer the response observer.
79
94
*/
80
95
commitTransaction ( observer ) {
81
- this . run ( 'COMMIT' , { } , observer ) ;
96
+ this . run ( 'COMMIT' , { } , Bookmark . empty ( ) , TxConfig . empty ( ) , observer ) ;
82
97
}
83
98
84
99
/**
85
100
* Rollback the explicit transaction.
86
101
* @param {StreamObserver } observer the response observer.
87
102
*/
88
103
rollbackTransaction ( observer ) {
89
- this . run ( 'ROLLBACK' , { } , observer ) ;
104
+ this . run ( 'ROLLBACK' , { } , Bookmark . empty ( ) , TxConfig . empty ( ) , observer ) ;
90
105
}
91
106
92
107
/**
93
108
* Send a Cypher statement through the underlying connection.
94
109
* @param {string } statement the cypher statement.
95
110
* @param {object } parameters the statement parameters.
111
+ * @param {Bookmark } bookmark the bookmark.
112
+ * @param {TxConfig } txConfig the auto-commit transaction configuration.
96
113
* @param {StreamObserver } observer the response observer.
97
114
*/
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
+
99
119
const runMessage = RequestMessage . run ( statement , parameters ) ;
100
120
const pullAllMessage = RequestMessage . pullAll ( ) ;
101
121
@@ -120,3 +140,20 @@ export default class BoltProtocol {
120
140
return new v1 . Unpacker ( disableLosslessIntegers ) ;
121
141
}
122
142
}
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