1818 */
1919import RequestMessage from './request-message'
2020import * as v1 from './packstream-v1'
21- import { newError } from '../error'
2221import Bookmark from './bookmark'
2322import TxConfig from './tx-config'
2423import { ACCESS_MODE_WRITE } from './constants'
24+ import { assertDbIsEmpty , assertTxConfigIsEmpty } from './bolt-protocol-util'
2525
2626export default class BoltProtocol {
2727 /**
@@ -78,13 +78,15 @@ export default class BoltProtocol {
7878
7979 /**
8080 * Begin an explicit transaction.
81+ * @param {StreamObserver } observer the response observer.
8182 * @param {Bookmark } bookmark the bookmark.
8283 * @param {TxConfig } txConfig the configuration.
84+ * @param {string } db the target database name.
8385 * @param {string } mode the access mode.
84- * @param {StreamObserver } observer the response observer.
8586 */
86- beginTransaction ( bookmark , txConfig , mode , observer ) {
87+ beginTransaction ( observer , { bookmark, txConfig, db , mode } ) {
8788 assertTxConfigIsEmpty ( txConfig , this . _connection , observer )
89+ assertDbIsEmpty ( db , this . _connection , observer )
8890
8991 const runMessage = RequestMessage . run (
9092 'BEGIN' ,
@@ -103,14 +105,11 @@ export default class BoltProtocol {
103105 commitTransaction ( observer ) {
104106 // WRITE access mode is used as a place holder here, it has
105107 // no effect on behaviour for Bolt V1 & V2
106- this . run (
107- 'COMMIT' ,
108- { } ,
109- Bookmark . empty ( ) ,
110- TxConfig . empty ( ) ,
111- ACCESS_MODE_WRITE ,
112- observer
113- )
108+ this . run ( 'COMMIT' , { } , observer , {
109+ bookmark : Bookmark . empty ( ) ,
110+ txConfig : TxConfig . empty ( ) ,
111+ mode : ACCESS_MODE_WRITE
112+ } )
114113 }
115114
116115 /**
@@ -120,28 +119,28 @@ export default class BoltProtocol {
120119 rollbackTransaction ( observer ) {
121120 // WRITE access mode is used as a place holder here, it has
122121 // no effect on behaviour for Bolt V1 & V2
123- this . run (
124- 'ROLLBACK' ,
125- { } ,
126- Bookmark . empty ( ) ,
127- TxConfig . empty ( ) ,
128- ACCESS_MODE_WRITE ,
129- observer
130- )
122+ this . run ( 'ROLLBACK' , { } , observer , {
123+ bookmark : Bookmark . empty ( ) ,
124+ txConfig : TxConfig . empty ( ) ,
125+ mode : ACCESS_MODE_WRITE
126+ } )
131127 }
132128
133129 /**
134130 * Send a Cypher statement through the underlying connection.
135131 * @param {string } statement the cypher statement.
136132 * @param {object } parameters the statement parameters.
133+ * @param {StreamObserver } observer the response observer.
137134 * @param {Bookmark } bookmark the bookmark.
138135 * @param {TxConfig } txConfig the auto-commit transaction configuration.
136+ * @param {string } db the target database name.
139137 * @param {string } mode the access mode.
140- * @param {StreamObserver } observer the response observer.
141138 */
142- run ( statement , parameters , bookmark , txConfig , mode , observer ) {
143- // bookmark and mode are ignored in this versioon of the protocol
139+ run ( statement , parameters , observer , { bookmark, txConfig, db , mode } ) {
140+ // bookmark and mode are ignored in this version of the protocol
144141 assertTxConfigIsEmpty ( txConfig , this . _connection , observer )
142+ // passing in a db name on this protocol version throws an error
143+ assertDbIsEmpty ( db , this . _connection , observer )
145144
146145 const runMessage = RequestMessage . run ( statement , parameters )
147146 const pullAllMessage = RequestMessage . pullAll ( )
@@ -167,22 +166,3 @@ export default class BoltProtocol {
167166 return new v1 . Unpacker ( disableLosslessIntegers )
168167 }
169168}
170-
171- /**
172- * @param {TxConfig } txConfig the auto-commit transaction configuration.
173- * @param {Connection } connection the connection.
174- * @param {StreamObserver } observer the response observer.
175- */
176- function assertTxConfigIsEmpty ( txConfig , connection , observer ) {
177- if ( ! txConfig . isEmpty ( ) ) {
178- const error = newError (
179- 'Driver is connected to the database that does not support transaction configuration. ' +
180- 'Please upgrade to neo4j 3.5.0 or later in order to use this functionality'
181- )
182-
183- // unsupported API was used, consider this a fatal error for the current connection
184- connection . _handleFatalError ( error )
185- observer . onError ( error )
186- throw error
187- }
188- }
0 commit comments