1- " use strict" ;
1+ ' use strict' ;
22
33Object . defineProperty ( exports , "__esModule" , {
44 value : true
55} ) ;
66exports . WRITE = exports . READ = exports . Driver = undefined ;
77
8- var _getPrototypeOf = require ( " babel-runtime/core-js/object/get-prototype-of" ) ;
8+ var _getPrototypeOf = require ( ' babel-runtime/core-js/object/get-prototype-of' ) ;
99
1010var _getPrototypeOf2 = _interopRequireDefault ( _getPrototypeOf ) ;
1111
12- var _possibleConstructorReturn2 = require ( " babel-runtime/helpers/possibleConstructorReturn" ) ;
12+ var _possibleConstructorReturn2 = require ( ' babel-runtime/helpers/possibleConstructorReturn' ) ;
1313
1414var _possibleConstructorReturn3 = _interopRequireDefault ( _possibleConstructorReturn2 ) ;
1515
16- var _get2 = require ( " babel-runtime/helpers/get" ) ;
16+ var _get2 = require ( ' babel-runtime/helpers/get' ) ;
1717
1818var _get3 = _interopRequireDefault ( _get2 ) ;
1919
20- var _inherits2 = require ( " babel-runtime/helpers/inherits" ) ;
20+ var _inherits2 = require ( ' babel-runtime/helpers/inherits' ) ;
2121
2222var _inherits3 = _interopRequireDefault ( _inherits2 ) ;
2323
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' ) ;
2925
3026var _classCallCheck3 = _interopRequireDefault ( _classCallCheck2 ) ;
3127
32- var _createClass2 = require ( " babel-runtime/helpers/createClass" ) ;
28+ var _createClass2 = require ( ' babel-runtime/helpers/createClass' ) ;
3329
3430var _createClass3 = _interopRequireDefault ( _createClass2 ) ;
3531
36- var _session = require ( " ./session" ) ;
32+ var _session = require ( ' ./session' ) ;
3733
3834var _session2 = _interopRequireDefault ( _session ) ;
3935
40- var _pool = require ( " ./internal/pool" ) ;
36+ var _pool = require ( ' ./internal/pool' ) ;
4137
4238var _pool2 = _interopRequireDefault ( _pool ) ;
4339
44- var _connector = require ( " ./internal/connector" ) ;
40+ var _connector = require ( ' ./internal/connector' ) ;
4541
46- var _streamObserver = require ( " ./internal/stream-observer" ) ;
42+ var _streamObserver = require ( ' ./internal/stream-observer' ) ;
4743
4844var _streamObserver2 = _interopRequireDefault ( _streamObserver ) ;
4945
50- var _error = require ( "./error" ) ;
46+ var _error = require ( './error' ) ;
47+
48+ var _connectionProviders = require ( './internal/connection-providers' ) ;
5149
5250function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { default : obj } ; }
5351
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- */
6652/**
6753 * Copyright (c) 2002-2017 "Neo Technology,","
6854 * Network Engine for Objects in Lund AB [http://neotechnology.com]
@@ -82,6 +68,19 @@ var READ = 'READ',
8268 * limitations under the License.
8369 */
8470
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+
8584var Driver = function ( ) {
8685 /**
8786 * You should not be calling this directly, instead use {@link driver}.
@@ -104,6 +103,7 @@ var Driver = function () {
104103 this . _token = token ;
105104 this . _config = config ;
106105 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 ) ) ;
107107 }
108108
109109 /**
@@ -114,7 +114,7 @@ var Driver = function () {
114114
115115
116116 ( 0 , _createClass3 . default ) ( Driver , [ {
117- key : " _createConnection" ,
117+ key : ' _createConnection' ,
118118 value : function _createConnection ( url , release ) {
119119 var sessionId = this . _sessionIdGenerator ++ ;
120120 var conn = ( 0 , _connector . connect ) ( url , this . _config ) ;
@@ -136,7 +136,7 @@ var Driver = function () {
136136 **/
137137
138138 } , {
139- key : " _destroyConnection" ,
139+ key : ' _destroyConnection' ,
140140
141141
142142 /**
@@ -160,69 +160,43 @@ var Driver = function () {
160160 * it is returned to the pool, the session will be reset to a clean state and
161161 * made available for others to use.
162162 *
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.
164166 * @return {Session } new session.
165167 */
166168
167169 } , {
168- key : "session" ,
169- value : function session ( mode ) {
170- var _this = this ;
171-
170+ key : 'session' ,
171+ value : function session ( mode , bookmark ) {
172172 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 ) ;
210174 }
211175 } , {
212- key : "_acquireConnection" ,
176+ key : '_createConnectionProvider' ,
213177
214178
215179 //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 ) ;
218182 }
219183
220184 //Extension point
221185
222186 } , {
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+ }
226200 }
227201
228202 /**
@@ -232,7 +206,7 @@ var Driver = function () {
232206 */
233207
234208 } , {
235- key : " close" ,
209+ key : ' close' ,
236210 value : function close ( ) {
237211 for ( var sessionId in this . _openSessions ) {
238212 if ( this . _openSessions . hasOwnProperty ( sessionId ) ) {
@@ -242,12 +216,12 @@ var Driver = function () {
242216 }
243217 }
244218 } ] , [ {
245- key : " _validateConnection" ,
219+ key : ' _validateConnection' ,
246220 value : function _validateConnection ( conn ) {
247221 return conn . isOpen ( ) ;
248222 }
249223 } , {
250- key : " _validateSessionMode" ,
224+ key : ' _validateSessionMode' ,
251225 value : function _validateSessionMode ( rawMode ) {
252226 var mode = rawMode || WRITE ;
253227 if ( mode !== READ && mode !== WRITE ) {
@@ -268,27 +242,27 @@ var _ConnectionStreamObserver = function (_StreamObserver) {
268242 function _ConnectionStreamObserver ( driver , conn ) {
269243 ( 0 , _classCallCheck3 . default ) ( this , _ConnectionStreamObserver ) ;
270244
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 ) ) ;
272246
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 ;
277251 }
278252
279253 ( 0 , _createClass3 . default ) ( _ConnectionStreamObserver , [ {
280- key : " onError" ,
254+ key : ' onError' ,
281255 value : function onError ( error ) {
282256 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 ) ;
284258 if ( this . _driver . onError ) {
285259 this . _driver . onError ( error ) ;
286260 }
287261 this . _hasFailed = true ;
288262 }
289263 }
290264 } , {
291- key : " onCompleted" ,
265+ key : ' onCompleted' ,
292266 value : function onCompleted ( message ) {
293267 if ( this . _driver . onCompleted ) {
294268 this . _driver . onCompleted ( message ) ;
0 commit comments