1
- " use strict" ;
1
+ ' use strict' ;
2
2
3
3
Object . defineProperty ( exports , "__esModule" , {
4
4
value : true
5
5
} ) ;
6
6
exports . WRITE = exports . READ = exports . Driver = undefined ;
7
7
8
- var _getPrototypeOf = require ( " babel-runtime/core-js/object/get-prototype-of" ) ;
8
+ var _getPrototypeOf = require ( ' babel-runtime/core-js/object/get-prototype-of' ) ;
9
9
10
10
var _getPrototypeOf2 = _interopRequireDefault ( _getPrototypeOf ) ;
11
11
12
- var _possibleConstructorReturn2 = require ( " babel-runtime/helpers/possibleConstructorReturn" ) ;
12
+ var _possibleConstructorReturn2 = require ( ' babel-runtime/helpers/possibleConstructorReturn' ) ;
13
13
14
14
var _possibleConstructorReturn3 = _interopRequireDefault ( _possibleConstructorReturn2 ) ;
15
15
16
- var _get2 = require ( " babel-runtime/helpers/get" ) ;
16
+ var _get2 = require ( ' babel-runtime/helpers/get' ) ;
17
17
18
18
var _get3 = _interopRequireDefault ( _get2 ) ;
19
19
20
- var _inherits2 = require ( " babel-runtime/helpers/inherits" ) ;
20
+ var _inherits2 = require ( ' babel-runtime/helpers/inherits' ) ;
21
21
22
22
var _inherits3 = _interopRequireDefault ( _inherits2 ) ;
23
23
24
- var _promise = require ( "babel-runtime/core-js/promise" ) ;
25
-
26
- var _promise2 = _interopRequireDefault ( _promise ) ;
27
-
28
- var _classCallCheck2 = require ( "babel-runtime/helpers/classCallCheck" ) ;
24
+ var _classCallCheck2 = require ( 'babel-runtime/helpers/classCallCheck' ) ;
29
25
30
26
var _classCallCheck3 = _interopRequireDefault ( _classCallCheck2 ) ;
31
27
32
- var _createClass2 = require ( " babel-runtime/helpers/createClass" ) ;
28
+ var _createClass2 = require ( ' babel-runtime/helpers/createClass' ) ;
33
29
34
30
var _createClass3 = _interopRequireDefault ( _createClass2 ) ;
35
31
36
- var _session = require ( " ./session" ) ;
32
+ var _session = require ( ' ./session' ) ;
37
33
38
34
var _session2 = _interopRequireDefault ( _session ) ;
39
35
40
- var _pool = require ( " ./internal/pool" ) ;
36
+ var _pool = require ( ' ./internal/pool' ) ;
41
37
42
38
var _pool2 = _interopRequireDefault ( _pool ) ;
43
39
44
- var _connector = require ( " ./internal/connector" ) ;
40
+ var _connector = require ( ' ./internal/connector' ) ;
45
41
46
- var _streamObserver = require ( " ./internal/stream-observer" ) ;
42
+ var _streamObserver = require ( ' ./internal/stream-observer' ) ;
47
43
48
44
var _streamObserver2 = _interopRequireDefault ( _streamObserver ) ;
49
45
50
- var _error = require ( "./error" ) ;
46
+ var _error = require ( './error' ) ;
47
+
48
+ var _connectionProviders = require ( './internal/connection-providers' ) ;
51
49
52
50
function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { default : obj } ; }
53
51
54
- var READ = 'READ' ,
55
- WRITE = 'WRITE' ;
56
- /**
57
- * A driver maintains one or more {@link Session sessions} with a remote
58
- * Neo4j instance. Through the {@link Session sessions} you can send statements
59
- * and retrieve results from the database.
60
- *
61
- * Drivers are reasonably expensive to create - you should strive to keep one
62
- * driver instance around per Neo4j Instance you connect to.
63
- *
64
- * @access public
65
- */
66
52
/**
67
53
* Copyright (c) 2002-2017 "Neo Technology,","
68
54
* Network Engine for Objects in Lund AB [http://neotechnology.com]
@@ -82,6 +68,19 @@ var READ = 'READ',
82
68
* limitations under the License.
83
69
*/
84
70
71
+ var READ = 'READ' ,
72
+ WRITE = 'WRITE' ;
73
+ /**
74
+ * A driver maintains one or more {@link Session sessions} with a remote
75
+ * Neo4j instance. Through the {@link Session sessions} you can send statements
76
+ * and retrieve results from the database.
77
+ *
78
+ * Drivers are reasonably expensive to create - you should strive to keep one
79
+ * driver instance around per Neo4j Instance you connect to.
80
+ *
81
+ * @access public
82
+ */
83
+
85
84
var Driver = function ( ) {
86
85
/**
87
86
* You should not be calling this directly, instead use {@link driver}.
@@ -104,6 +103,7 @@ var Driver = function () {
104
103
this . _token = token ;
105
104
this . _config = config ;
106
105
this . _pool = new _pool2 . default ( this . _createConnection . bind ( this ) , this . _destroyConnection . bind ( this ) , Driver . _validateConnection . bind ( this ) , config . connectionPoolSize ) ;
106
+ this . _connectionProvider = this . _createConnectionProvider ( url , this . _pool , this . _driverOnErrorCallback . bind ( this ) ) ;
107
107
}
108
108
109
109
/**
@@ -114,7 +114,7 @@ var Driver = function () {
114
114
115
115
116
116
( 0 , _createClass3 . default ) ( Driver , [ {
117
- key : " _createConnection" ,
117
+ key : ' _createConnection' ,
118
118
value : function _createConnection ( url , release ) {
119
119
var sessionId = this . _sessionIdGenerator ++ ;
120
120
var conn = ( 0 , _connector . connect ) ( url , this . _config ) ;
@@ -136,7 +136,7 @@ var Driver = function () {
136
136
**/
137
137
138
138
} , {
139
- key : " _destroyConnection" ,
139
+ key : ' _destroyConnection' ,
140
140
141
141
142
142
/**
@@ -160,69 +160,43 @@ var Driver = function () {
160
160
* it is returned to the pool, the session will be reset to a clean state and
161
161
* made available for others to use.
162
162
*
163
- * @param {String } mode of session - optional
163
+ * @param {string } [mode=WRITE] the access mode of this session, allowed values are {@link READ} and {@link WRITE}.
164
+ * @param {string } [bookmark=null] the initial reference to some previous transaction. Value is optional and
165
+ * absence indicates that that the bookmark does not exist or is unknown.
164
166
* @return {Session } new session.
165
167
*/
166
168
167
169
} , {
168
- key : "session" ,
169
- value : function session ( mode ) {
170
- var _this = this ;
171
-
170
+ key : 'session' ,
171
+ value : function session ( mode , bookmark ) {
172
172
var sessionMode = Driver . _validateSessionMode ( mode ) ;
173
- var connectionPromise = this . _acquireConnection ( sessionMode ) ;
174
- connectionPromise . catch ( function ( err ) {
175
- if ( _this . onError && err . code === _error . SERVICE_UNAVAILABLE ) {
176
- _this . onError ( err ) ;
177
- } else {
178
- //we don't need to tell the driver about this error
179
- }
180
- } ) ;
181
- return this . _createSession ( connectionPromise , this . _releaseConnection ( connectionPromise ) ) ;
182
- }
183
-
184
- /**
185
- * The returned function gets called on Session#close(), and is where we return the pooled 'connection' instance.
186
- * We don't pool Session instances, to avoid users using the Session after they've called close.
187
- * The `Session` object is just a thin wrapper around Connection anyway, so it makes little difference.
188
- * @param {Promise } connectionPromise - promise resolved with the connection.
189
- * @return {function(callback: function) } - function that releases the connection and then executes an optional callback.
190
- * @protected
191
- */
192
-
193
- } , {
194
- key : "_releaseConnection" ,
195
- value : function _releaseConnection ( connectionPromise ) {
196
- return function ( userDefinedCallback ) {
197
- connectionPromise . then ( function ( conn ) {
198
- // Queue up a 'reset', to ensure the next user gets a clean session to work with.
199
- conn . reset ( ) ;
200
- conn . sync ( ) ;
201
-
202
- // Return connection to the pool
203
- conn . _release ( ) ;
204
- } ) . catch ( function ( ignoredError ) { } ) ;
205
-
206
- if ( userDefinedCallback ) {
207
- userDefinedCallback ( ) ;
208
- }
209
- } ;
173
+ return this . _createSession ( sessionMode , this . _connectionProvider , bookmark , this . _config ) ;
210
174
}
211
175
} , {
212
- key : "_acquireConnection" ,
176
+ key : '_createConnectionProvider' ,
213
177
214
178
215
179
//Extension point
216
- value : function _acquireConnection ( mode ) {
217
- return _promise2 . default . resolve ( this . _pool . acquire ( this . _url ) ) ;
180
+ value : function _createConnectionProvider ( address , connectionPool , driverOnErrorCallback ) {
181
+ return new _connectionProviders . DirectConnectionProvider ( address , connectionPool , driverOnErrorCallback ) ;
218
182
}
219
183
220
184
//Extension point
221
185
222
186
} , {
223
- key : "_createSession" ,
224
- value : function _createSession ( connectionPromise , cb ) {
225
- return new _session2 . default ( connectionPromise , cb ) ;
187
+ key : '_createSession' ,
188
+ value : function _createSession ( mode , connectionProvider , bookmark , config ) {
189
+ return new _session2 . default ( mode , connectionProvider , bookmark , config ) ;
190
+ }
191
+ } , {
192
+ key : '_driverOnErrorCallback' ,
193
+ value : function _driverOnErrorCallback ( error ) {
194
+ var userDefinedOnErrorCallback = this . onError ;
195
+ if ( userDefinedOnErrorCallback && error . code === _error . SERVICE_UNAVAILABLE ) {
196
+ userDefinedOnErrorCallback ( error ) ;
197
+ } else {
198
+ // we don't need to tell the driver about this error
199
+ }
226
200
}
227
201
228
202
/**
@@ -232,7 +206,7 @@ var Driver = function () {
232
206
*/
233
207
234
208
} , {
235
- key : " close" ,
209
+ key : ' close' ,
236
210
value : function close ( ) {
237
211
for ( var sessionId in this . _openSessions ) {
238
212
if ( this . _openSessions . hasOwnProperty ( sessionId ) ) {
@@ -242,12 +216,12 @@ var Driver = function () {
242
216
}
243
217
}
244
218
} ] , [ {
245
- key : " _validateConnection" ,
219
+ key : ' _validateConnection' ,
246
220
value : function _validateConnection ( conn ) {
247
221
return conn . isOpen ( ) ;
248
222
}
249
223
} , {
250
- key : " _validateSessionMode" ,
224
+ key : ' _validateSessionMode' ,
251
225
value : function _validateSessionMode ( rawMode ) {
252
226
var mode = rawMode || WRITE ;
253
227
if ( mode !== READ && mode !== WRITE ) {
@@ -268,27 +242,27 @@ var _ConnectionStreamObserver = function (_StreamObserver) {
268
242
function _ConnectionStreamObserver ( driver , conn ) {
269
243
( 0 , _classCallCheck3 . default ) ( this , _ConnectionStreamObserver ) ;
270
244
271
- var _this2 = ( 0 , _possibleConstructorReturn3 . default ) ( this , ( _ConnectionStreamObserver . __proto__ || ( 0 , _getPrototypeOf2 . default ) ( _ConnectionStreamObserver ) ) . call ( this ) ) ;
245
+ var _this = ( 0 , _possibleConstructorReturn3 . default ) ( this , ( _ConnectionStreamObserver . __proto__ || ( 0 , _getPrototypeOf2 . default ) ( _ConnectionStreamObserver ) ) . call ( this ) ) ;
272
246
273
- _this2 . _driver = driver ;
274
- _this2 . _conn = conn ;
275
- _this2 . _hasFailed = false ;
276
- return _this2 ;
247
+ _this . _driver = driver ;
248
+ _this . _conn = conn ;
249
+ _this . _hasFailed = false ;
250
+ return _this ;
277
251
}
278
252
279
253
( 0 , _createClass3 . default ) ( _ConnectionStreamObserver , [ {
280
- key : " onError" ,
254
+ key : ' onError' ,
281
255
value : function onError ( error ) {
282
256
if ( ! this . _hasFailed ) {
283
- ( 0 , _get3 . default ) ( _ConnectionStreamObserver . prototype . __proto__ || ( 0 , _getPrototypeOf2 . default ) ( _ConnectionStreamObserver . prototype ) , " onError" , this ) . call ( this , error ) ;
257
+ ( 0 , _get3 . default ) ( _ConnectionStreamObserver . prototype . __proto__ || ( 0 , _getPrototypeOf2 . default ) ( _ConnectionStreamObserver . prototype ) , ' onError' , this ) . call ( this , error ) ;
284
258
if ( this . _driver . onError ) {
285
259
this . _driver . onError ( error ) ;
286
260
}
287
261
this . _hasFailed = true ;
288
262
}
289
263
}
290
264
} , {
291
- key : " onCompleted" ,
265
+ key : ' onCompleted' ,
292
266
value : function onCompleted ( message ) {
293
267
if ( this . _driver . onCompleted ) {
294
268
this . _driver . onCompleted ( message ) ;
0 commit comments