oracledb 5.2.0 → 5.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/CHANGELOG.md +145 -48
  2. package/LICENSE.txt +443 -0
  3. package/NOTICE.txt +1 -0
  4. package/README.md +7 -4
  5. package/THIRD_PARTY_LICENSES.txt +52 -0
  6. package/build/Release/oracledb-5.5.0-darwin-x64.node +0 -0
  7. package/build/Release/oracledb-5.5.0-darwin-x64.node-buildinfo.txt +1 -0
  8. package/build/Release/oracledb-5.5.0-linux-x64.node +0 -0
  9. package/build/Release/oracledb-5.5.0-linux-x64.node-buildinfo.txt +1 -0
  10. package/build/Release/oracledb-5.5.0-win32-x64.node +0 -0
  11. package/build/Release/oracledb-5.5.0-win32-x64.node-buildinfo.txt +1 -0
  12. package/lib/aqDeqOptions.js +1 -1
  13. package/lib/aqEnqOptions.js +1 -1
  14. package/lib/aqMessage.js +1 -1
  15. package/lib/aqQueue.js +1 -1
  16. package/lib/connection.js +173 -2
  17. package/lib/dbObject.js +1 -1
  18. package/lib/lob.js +1 -1
  19. package/lib/oracledb.js +160 -6
  20. package/lib/pool.js +47 -82
  21. package/lib/poolStatistics.js +124 -0
  22. package/lib/queryStream.js +8 -6
  23. package/lib/resultset.js +14 -1
  24. package/lib/sodaCollection.js +1 -1
  25. package/lib/sodaDatabase.js +1 -1
  26. package/lib/sodaDocCursor.js +1 -1
  27. package/lib/sodaDocument.js +1 -1
  28. package/lib/sodaOperation.js +1 -1
  29. package/lib/util.js +25 -4
  30. package/package/install.js +1 -1
  31. package/package/prunebinaries.js +1 -1
  32. package/package.json +2 -2
  33. package/LICENSE.md +0 -2485
  34. package/build/Release/oracledb-5.2.0-darwin-x64.node +0 -0
  35. package/build/Release/oracledb-5.2.0-darwin-x64.node-buildinfo.txt +0 -1
  36. package/build/Release/oracledb-5.2.0-linux-x64.node +0 -0
  37. package/build/Release/oracledb-5.2.0-linux-x64.node-buildinfo.txt +0 -1
  38. package/build/Release/oracledb-5.2.0-win32-x64.node +0 -0
  39. package/build/Release/oracledb-5.2.0-win32-x64.node-buildinfo.txt +0 -1
package/lib/connection.js CHANGED
@@ -1,4 +1,4 @@
1
- // Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved
1
+ // Copyright (c) 2016, 2022, Oracle and/or its affiliates.
2
2
 
3
3
  //-----------------------------------------------------------------------------
4
4
  //
@@ -172,7 +172,20 @@ async function close(a1) {
172
172
  nodbUtil.assert(nodbUtil.isObject(a1), 'NJS-005', 1);
173
173
  options = a1;
174
174
  }
175
- await this._close(options);
175
+
176
+ // If already in the process of closing, throw an error instead of doing
177
+ // a roundtrip
178
+ if (this._closing) {
179
+ throw new Error (nodbUtil.getErrorMessage('NJS-003'));
180
+ }
181
+
182
+ this._closing = true;
183
+ try {
184
+ await this._close(options);
185
+ } finally {
186
+ this._closing = false;
187
+ }
188
+
176
189
  for (const cls of Object.values(this._dbObjectClasses)) {
177
190
  cls.prototype.constructor = Object;
178
191
  cls.prototype = null;
@@ -314,6 +327,144 @@ function buildDbObjectClass(schema, name, fqn) {
314
327
  return (DbObject);
315
328
  }
316
329
 
330
+ //-----------------------------------------------------------------------------
331
+ // tpcBegin()
332
+ // Starts a two-phase-commit transaction
333
+ //----------------------------------------------------------------------------
334
+ async function tpcBegin(xid, flag, timeout) {
335
+ nodbUtil.checkArgCount(arguments, 1, 3);
336
+ nodbUtil.assert(nodbUtil.isXid(xid), 'NJS-005', 1);
337
+
338
+ if (arguments.length < 3) {
339
+ timeout = 60; // seconds
340
+ } else {
341
+ nodbUtil.assert(typeof timeout === 'number', 'NJS-005', 3);
342
+ }
343
+
344
+ if (arguments.length < 2) {
345
+ flag = this._oracledb.TPC_BEGIN_NEW;
346
+ } else {
347
+ nodbUtil.assert(typeof flag === 'number', 'NJS-005', 2);
348
+ }
349
+ await this._tpcBegin(xid, flag, timeout);
350
+ }
351
+
352
+
353
+ //-----------------------------------------------------------------------------
354
+ // tpcCommit
355
+ // Commit the two-phase-commit transaction
356
+ //-----------------------------------------------------------------------------
357
+ async function tpcCommit(xid, onePhase) {
358
+ nodbUtil.checkArgCount(arguments, 0, 2);
359
+
360
+ if (arguments.length < 2) {
361
+ onePhase = false;
362
+ } else {
363
+ nodbUtil.assert(typeof onePhase === 'boolean', 'NJS-005', 2);
364
+ }
365
+ if (arguments.length >= 1) {
366
+ nodbUtil.assert(nodbUtil.isXid(xid), 'NJS-005', 1);
367
+ }
368
+ await this._tpcCommit(xid, onePhase);
369
+ }
370
+
371
+
372
+ //-----------------------------------------------------------------------------
373
+ // tpcEnd
374
+ // Ends the two-phase-commit transaction
375
+ //-----------------------------------------------------------------------------
376
+ async function tpcEnd(xid, flag) {
377
+ nodbUtil.checkArgCount(arguments, 0, 2);
378
+
379
+ if (arguments.length < 2) {
380
+ flag = this._oracledb.TPC_END_NORMAL;
381
+ } else {
382
+ nodbUtil.assert(typeof flag === 'number', 'NJS-005', 2);
383
+ }
384
+
385
+ if (arguments.length >= 1) {
386
+ nodbUtil.assert(nodbUtil.isXid(xid), 'NJS-005', 1);
387
+ }
388
+
389
+ await this._tpcEnd(xid, flag);
390
+ }
391
+
392
+
393
+ //-----------------------------------------------------------------------------
394
+ // tpcForget
395
+ // causes the server to forget a heuristically completed global transaction.
396
+ //-----------------------------------------------------------------------------
397
+ async function tpcForget(xid) {
398
+
399
+ nodbUtil.checkArgCount(arguments, 1, 1);
400
+ nodbUtil.assert(nodbUtil.isXid(xid), 'NJS-005', 1);
401
+
402
+ await this._tpcForget(xid);
403
+ }
404
+
405
+
406
+ //-----------------------------------------------------------------------------
407
+ // tpcPrepare
408
+ // prepares a global transaction for commit.
409
+ //-----------------------------------------------------------------------------
410
+ async function tpcPrepare(xid) {
411
+ nodbUtil.checkArgCount(arguments, 0, 1);
412
+
413
+ if (arguments.length >= 1) {
414
+ nodbUtil.assert(nodbUtil.isXid(xid), 'NJS-005', 1);
415
+ }
416
+
417
+ return await this._tpcPrepare(xid);
418
+ }
419
+
420
+
421
+ //-----------------------------------------------------------------------------
422
+ // tpcRecover
423
+ // Returns a list of pending transactions
424
+ //-----------------------------------------------------------------------------
425
+ async function tpcRecover(asString) {
426
+ nodbUtil.checkArgCount(arguments, 0, 1);
427
+
428
+ if (arguments.length == 1) {
429
+ nodbUtil.assert(typeof asString === 'boolean', 'NJS-005', 1);
430
+ } else {
431
+ asString = true;
432
+ }
433
+
434
+ const sqlStr = `
435
+ SELECT
436
+ formatid as "formatId",
437
+ UTL_RAW.CAST_TO_VARCHAR2(globalid) as "globalTransactionId",
438
+ UTL_RAW.CAST_TO_VARCHAR2(branchid) as "branchQualifier"
439
+ FROM DBA_PENDING_TRANSACTIONS`;
440
+ const sqlBuf = `
441
+ SELECT
442
+ formatid as "formatId",
443
+ globalid as "globalTransactionId",
444
+ branchid as "branchQualifier"
445
+ FROM DBA_PENDING_TRANSACTIONS`;
446
+ const options = {
447
+ outFormat: this._oracledb.OUT_FORMAT_OBJECT,
448
+ };
449
+
450
+ const result = await this._execute(asString ? sqlStr : sqlBuf, {}, options);
451
+ return result.resultSet._getAllRows(options, result.metaData, false);
452
+ }
453
+
454
+
455
+ //-----------------------------------------------------------------------------
456
+ // tpcRollback()
457
+ // Rollbacks the current changes in two-phase-commit
458
+ //-----------------------------------------------------------------------------
459
+ async function tpcRollback(xid) {
460
+ nodbUtil.checkArgCount(arguments, 0, 1);
461
+ if (arguments.length == 1) {
462
+ nodbUtil.assert(nodbUtil.isXid(xid), 'NJS-005', 1);
463
+ }
464
+
465
+ await this._tpcRollback(xid);
466
+ }
467
+
317
468
 
318
469
  // define class
319
470
  class Connection extends EventEmitter {
@@ -323,6 +474,7 @@ class Connection extends EventEmitter {
323
474
  this._dbObjectClasses = {};
324
475
  this._requestQueue = [];
325
476
  this._inProgress = false;
477
+ this._closing = false;
326
478
  }
327
479
 
328
480
  // extend class with promisified functions
@@ -344,6 +496,13 @@ class Connection extends EventEmitter {
344
496
  this.shutdown = nodbUtil.callbackify(nodbUtil.serialize(shutdown));
345
497
  this.startup = nodbUtil.callbackify(nodbUtil.serialize(startup));
346
498
  this.subscribe = nodbUtil.callbackify(nodbUtil.serialize(subscribe));
499
+ this.tpcBegin = nodbUtil.callbackify(nodbUtil.serialize(tpcBegin));
500
+ this.tpcCommit = nodbUtil.callbackify(nodbUtil.serialize(tpcCommit));
501
+ this.tpcEnd = nodbUtil.callbackify(nodbUtil.serialize(tpcEnd));
502
+ this.tpcForget = nodbUtil.callbackify(nodbUtil.serialize(tpcForget));
503
+ this.tpcPrepare = nodbUtil.callbackify(nodbUtil.serialize(tpcPrepare));
504
+ this.tpcRecover = nodbUtil.callbackify(nodbUtil.serialize(tpcRecover));
505
+ this.tpcRollback = nodbUtil.callbackify(nodbUtil.serialize(tpcRollback));
347
506
  this.unsubscribe = nodbUtil.callbackify(nodbUtil.serialize(unsubscribe));
348
507
  }
349
508
 
@@ -395,6 +554,18 @@ class Connection extends EventEmitter {
395
554
  return (this._getSodaDatabase());
396
555
  }
397
556
 
557
+ //--------------------------------------------------------------------------
558
+ // isHealthy()
559
+ // To get the health status of the connection.
560
+ // NOTE: if this function returns false, the application must close the
561
+ // connection obect.
562
+ // This is a synchronous call.
563
+ //---------------------------------------------------------------------------
564
+ isHealthy() {
565
+ return (!this._closing && this._isHealthy());
566
+ }
567
+
568
+
398
569
  // The queryStream function is similar to execute except that it immediately
399
570
  // returns a QueryStream.
400
571
  queryStream(sql, binding, options) {
package/lib/dbObject.js CHANGED
@@ -1,4 +1,4 @@
1
- // Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
1
+ // Copyright (c) 2019, 2022, Oracle and/or its affiliates.
2
2
  //
3
3
  //----------------------------------------------------------------------------
4
4
  //
package/lib/lob.js CHANGED
@@ -1,4 +1,4 @@
1
- // Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved
1
+ // Copyright (c) 2016, 2022, Oracle and/or its affiliates.
2
2
 
3
3
  //-----------------------------------------------------------------------------
4
4
  //
package/lib/oracledb.js CHANGED
@@ -1,4 +1,4 @@
1
- // Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved
1
+ // Copyright (c) 2015, 2022, Oracle and/or its affiliates.
2
2
 
3
3
  //-----------------------------------------------------------------------------
4
4
  //
@@ -43,6 +43,7 @@ const BaseDbObject = require('./dbObject.js');
43
43
  const Connection = require('./connection.js');
44
44
  const Lob = require('./lob.js');
45
45
  const Pool = require('./pool.js');
46
+ const PoolStatistics = require('./poolStatistics.js');
46
47
  const ResultSet = require('./resultset.js');
47
48
  const SodaDatabase = require('./sodaDatabase.js');
48
49
  const SodaCollection = require('./sodaCollection.js');
@@ -99,11 +100,13 @@ class OracleDb {
99
100
  }
100
101
 
101
102
  // extend class with promisified functions
102
- _extend() {
103
- this.getConnection = nodbUtil.callbackify(getConnection);
104
- this.createPool = nodbUtil.callbackify(createPool);
105
- this.shutdown = nodbUtil.callbackify(shutdown);
106
- this.startup = nodbUtil.callbackify(startup);
103
+ _extend(_oracledb) {
104
+ this.getConnection = nodbUtil.callbackify(getConnection).bind(_oracledb);
105
+ this.createPool = nodbUtil.callbackify(createPool).bind(_oracledb);
106
+ this.shutdown = nodbUtil.callbackify(shutdown).bind(_oracledb);
107
+ this.startup = nodbUtil.callbackify(startup).bind(_oracledb);
108
+ this.initOracleClient = this.initOracleClient.bind(_oracledb);
109
+ this._accessTokenHandler = this._accessTokenHandler.bind(_oracledb);
107
110
  }
108
111
 
109
112
  // temporary method for determining if an object is a date until
@@ -112,6 +115,22 @@ class OracleDb {
112
115
  return util.isDate(val);
113
116
  }
114
117
 
118
+ // handler for access token callbacks
119
+ async _accessTokenHandler(userFn, externalObj, refresh) {
120
+ let accessToken;
121
+ try {
122
+ let result = userFn(refresh);
123
+ if (result instanceof Promise) {
124
+ result = await result;
125
+ }
126
+
127
+ _checkToken(result);
128
+ accessToken = result;
129
+ } finally {
130
+ this._returnAccessToken(externalObj, accessToken);
131
+ }
132
+ }
133
+
115
134
  // retrieves a pool from the pool cache (synchronous method)
116
135
  getPool(poolAlias) {
117
136
  let pool;
@@ -173,6 +192,21 @@ async function createPool(poolAttrs) {
173
192
  throw new Error(nodbUtil.getErrorMessage('NJS-046', poolAlias));
174
193
  }
175
194
 
195
+ if (poolAttrs.accessToken !== undefined) {
196
+ // cannot set username or password for token based authentication
197
+ if (poolAttrs.user !== undefined ||
198
+ poolAttrs.password !== undefined) {
199
+ throw new Error(nodbUtil.getErrorMessage('NJS-084'));
200
+ }
201
+
202
+ // homogeneous and externalAuth must be set to true for token based
203
+ // authentication
204
+ if (poolAttrs.homogeneous === false ||
205
+ poolAttrs.externalAuth === false) {
206
+ throw new Error(nodbUtil.getErrorMessage('NJS-085'));
207
+ }
208
+ }
209
+
176
210
  // create an adjusted set of pool attributes to pass to the C layer; the
177
211
  // session callback must be removed if it is a JavaScript function and the
178
212
  // queue timeout is used to specify the maximum amount of time that the C
@@ -190,6 +224,28 @@ async function createPool(poolAttrs) {
190
224
  adjustedPoolAttrs.queueTimeout = this.queueTimeout;
191
225
  }
192
226
 
227
+ // token based authentication
228
+ if (poolAttrs.accessToken !== undefined) {
229
+ // accessTokenCallback is depricated from node-oracledb 5.5
230
+ if (poolAttrs.accessTokenCallback !== undefined &&
231
+ typeof poolAttrs.accessToken === 'function') {
232
+ throw new Error(nodbUtil.getErrorMessage('NJS-088'));
233
+ }
234
+
235
+ let accessToken;
236
+ if (typeof poolAttrs.accessToken === 'function') {
237
+ adjustedPoolAttrs.accessTokenCallback = poolAttrs.accessToken;
238
+ accessToken = await poolAttrs.accessToken(false);
239
+
240
+ if (_isTokenExpired(accessToken)) {
241
+ accessToken = await poolAttrs.accessToken(true);
242
+ }
243
+ } else {
244
+ accessToken = poolAttrs.accessToken;
245
+ }
246
+ _checkToken(accessToken, adjustedPoolAttrs);
247
+ }
248
+
193
249
  // Need to prevent another call in the same stack from succeeding, otherwise
194
250
  // two pools could be created with the same poolAlias and the second one that
195
251
  // comes back would overwrite the first in the cache.
@@ -269,6 +325,31 @@ async function getConnection(a1) {
269
325
 
270
326
  // otherwise, create a new standalone connection
271
327
  } else {
328
+ if (connAttrs.accessToken !== undefined) {
329
+ // cannot set username or password for token based authentication
330
+ if (connAttrs.user !== undefined ||
331
+ connAttrs.password !== undefined) {
332
+ throw new Error(nodbUtil.getErrorMessage('NJS-084'));
333
+ }
334
+
335
+ // externalAuth must be set to true for token based authentication
336
+ if (connAttrs.externalAuth === false) {
337
+ throw new Error(nodbUtil.getErrorMessage('NJS-086'));
338
+ }
339
+
340
+ let accessToken;
341
+ if (typeof connAttrs.accessToken === 'function') {
342
+ accessToken = await connAttrs.accessToken(false);
343
+
344
+ if (_isTokenExpired(accessToken)) {
345
+ accessToken = await connAttrs.accessToken(true);
346
+ }
347
+ } else {
348
+ accessToken = connAttrs.accessToken;
349
+ }
350
+ _checkToken(accessToken, connAttrs);
351
+ }
352
+
272
353
  try {
273
354
  return await this._getConnection(connAttrs);
274
355
  } catch (err) {
@@ -366,6 +447,78 @@ async function startup(a1, a2) {
366
447
  }
367
448
 
368
449
 
450
+ //-----------------------------------------------------------------------------
451
+ // _isTokenExpiredUtil()
452
+ // Function to check validity and expiry of token
453
+ //-----------------------------------------------------------------------------
454
+ function _isTokenExpiredUtil(accessToken) {
455
+ nodbUtil.assert(typeof accessToken === 'string', 'NJS-084', 1);
456
+
457
+ if (accessToken.split('.')[1] === undefined) {
458
+ throw new Error(nodbUtil.getErrorMessage('NJS-084'));
459
+ }
460
+
461
+ const base64Url = accessToken.split('.')[1];
462
+ const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
463
+ const buff = Buffer.from(base64, 'base64');
464
+ const payloadInit = buff.toString('ascii');
465
+
466
+ let expiry = JSON.parse(payloadInit).exp;
467
+ nodbUtil.assert(expiry != undefined, 'NJS-084');
468
+ expiry = expiry * 1000;
469
+
470
+ return (new Date().getTime() > expiry);
471
+ }
472
+
473
+
474
+ //-----------------------------------------------------------------------------
475
+ // _isTokenExpired()
476
+ // Function to check validity of token parameter
477
+ //-----------------------------------------------------------------------------
478
+ function _isTokenExpired(accessToken) {
479
+ switch (typeof accessToken) {
480
+ case 'string':
481
+ if (accessToken === '') {
482
+ throw new Error(nodbUtil.getErrorMessage('NJS-084'));
483
+ }
484
+
485
+ return _isTokenExpiredUtil(accessToken);
486
+ case 'object':
487
+ if (accessToken.token === undefined ||
488
+ accessToken.token === '' ||
489
+ accessToken.privateKey === undefined ||
490
+ accessToken.privateKey === '') {
491
+ throw new Error(nodbUtil.getErrorMessage('NJS-084'));
492
+ }
493
+
494
+ return _isTokenExpiredUtil(accessToken.token);
495
+ default:
496
+ throw new Error(nodbUtil.getErrorMessage('NJS-084'));
497
+ }
498
+ }
499
+
500
+
501
+ //-----------------------------------------------------------------------------
502
+ // _checkToken()
503
+ // Function to check validity of token parameter
504
+ //-----------------------------------------------------------------------------
505
+ function _checkToken(accessToken, attrs) {
506
+ if (_isTokenExpired(accessToken)) {
507
+ throw new Error(nodbUtil.getErrorMessage('NJS-087'));
508
+ }
509
+
510
+ if (attrs === undefined)
511
+ return;
512
+
513
+ if (typeof accessToken === 'string') {
514
+ attrs.token = accessToken;
515
+ } else {
516
+ attrs.token = accessToken.token;
517
+ attrs.privateKey = accessToken.privateKey;
518
+ }
519
+ }
520
+
521
+
369
522
  // create instance which will be exported
370
523
  let oracleDbInst = new OracleDb();
371
524
 
@@ -380,6 +533,7 @@ proto.BaseDbObject = BaseDbObject;
380
533
  proto.Connection = Connection;
381
534
  proto.Lob = Lob;
382
535
  proto.Pool = Pool;
536
+ proto.PoolStatistics = PoolStatistics;
383
537
  proto.ResultSet = ResultSet;
384
538
  proto.SodaDatabase = SodaDatabase;
385
539
  proto.SodaCollection = SodaCollection;
package/lib/pool.js CHANGED
@@ -1,4 +1,4 @@
1
- // Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved
1
+ // Copyright (c) 2016, 2022, Oracle and/or its affiliates.
2
2
 
3
3
  //-----------------------------------------------------------------------------
4
4
  //
@@ -22,6 +22,8 @@
22
22
  const EventEmitter = require('events');
23
23
  const nodbUtil = require('./util.js');
24
24
  const util = require('util');
25
+ const PoolStatistics = require('./poolStatistics.js');
26
+
25
27
 
26
28
  //-----------------------------------------------------------------------------
27
29
  // _checkRequestQueue()
@@ -328,44 +330,7 @@ function logStatistics() {
328
330
  if (stats === null) {
329
331
  throw new Error(nodbUtil.getErrorMessage('NJS-083'));
330
332
  }
331
-
332
- console.log('\nPool statistics:');
333
- console.log('...gathered at:', new Date(stats.gatheredDate).toISOString());
334
- console.log('...up time (milliseconds):', stats.upTime);
335
- console.log('...up time from last reset (milliseconds)',
336
- stats.upTimeSinceReset);
337
- console.log('...connection requests:', stats.connectionRequests);
338
- console.log('...requests enqueued:', stats.requestsEnqueued);
339
- console.log('...requests dequeued:', stats.requestsDequeued);
340
- console.log('...requests failed:', stats.failedRequests);
341
- console.log('...requests exceeding queueMax:', stats.rejectedRequests);
342
- console.log('...requests exceeding queueTimeout:', stats.requestTimeouts);
343
- console.log('...current queue length:', stats.currentQueueLength);
344
- console.log('...maximum queue length:', stats.maximumQueueLength);
345
- console.log('...sum of time in queue (milliseconds):', stats.timeInQueue);
346
- console.log('...minimum time in queue (milliseconds):',
347
- stats.minimumTimeInQueue);
348
- console.log('...maximum time in queue (milliseconds):',
349
- stats.maximumTimeInQueue);
350
- console.log('...average time in queue (milliseconds):',
351
- stats.averageTimeInQueue);
352
- console.log('...pool connections in use:', stats.connectionsInUse);
353
- console.log('...pool connections open:', stats.connectionsOpen);
354
- console.log('Pool attributes:');
355
- console.log('...poolAlias:', stats.poolAlias);
356
- console.log('...queueMax:', stats.queueMax);
357
- console.log('...queueTimeout (milliseconds):', stats.queueTimeout);
358
- console.log('...poolMin:', stats.poolMin);
359
- console.log('...poolMax:', stats.poolMax);
360
- console.log('...poolIncrement:', stats.poolIncrement);
361
- console.log('...poolTimeout (seconds):', stats.poolTimeout);
362
- console.log('...poolPingInterval (seconds):', stats.poolPingInterval);
363
- console.log('...poolMaxPerShard:', stats.poolMaxPerShard);
364
- console.log('...sessionCallback:', stats.sessionCallback);
365
- console.log('...stmtCacheSize:', stats.stmtCacheSize);
366
- console.log('...sodaMetaDataCache:', stats.sodaMetaDataCache);
367
- console.log('Related environment variables:');
368
- console.log('...UV_THREADPOOL_SIZE:', stats.threadPoolSize);
333
+ stats.logStatistics();
369
334
  }
370
335
 
371
336
 
@@ -375,54 +340,12 @@ function logStatistics() {
375
340
  // properties
376
341
  //-----------------------------------------------------------------------------
377
342
  function getStatistics() {
378
- let averageTimeInQueue;
379
- let stats = { };
380
-
381
- // if the pool is not OPEN, throw appropriate err
382
343
  this._checkPoolOpen(false);
383
344
 
384
345
  if (this._enableStatistics !== true) {
385
346
  return null;
386
347
  }
387
-
388
- averageTimeInQueue = 0;
389
-
390
- if (this._totalRequestsEnqueued !== 0) {
391
- averageTimeInQueue = Math.round(this._totalTimeInQueue /
392
- this._totalRequestsEnqueued);
393
- }
394
-
395
- stats.gatheredDate = Date.now ();
396
- stats.upTime = stats.gatheredDate - this._createdDate;
397
- stats.upTimeSinceReset = stats.gatheredDate - this._timeOfReset;
398
- stats.connectionRequests = this._totalConnectionRequests;
399
- stats.requestsEnqueued = this._totalRequestsEnqueued;
400
- stats.requestsDequeued = this._totalRequestsDequeued;
401
- stats.failedRequests = this._totalFailedRequests;
402
- stats.rejectedRequests = this._totalRequestsRejected;
403
- stats.requestTimeouts = this._totalRequestTimeouts;
404
- stats.maximumQueueLength = this._maximumQueueLength;
405
- stats.currentQueueLength = this._connRequestQueue.length;
406
- stats.timeInQueue = this._totalTimeInQueue;
407
- stats.minimumTimeInQueue = this._minTimeInQueue;
408
- stats.maximumTimeInQueue = this._maxTimeInQueue;
409
- stats.averageTimeInQueue = averageTimeInQueue;
410
- stats.connectionsInUse = this.connectionsInUse;
411
- stats.connectionsOpen = this.connectionsOpen;
412
- stats.poolAlias = this.poolAlias;
413
- stats.queueMax = this.queueMax;
414
- stats.queueTimeout = this.queueTimeout;
415
- stats.poolMin = this.poolMin;
416
- stats.poolMax = this.poolMax;
417
- stats.poolIncrement = this.poolIncrement;
418
- stats.poolTimeout = this.poolTimeout;
419
- stats.poolPingInterval = this.poolPingInterval;
420
- stats.poolMaxPerShard = this.poolMaxPerShard;
421
- stats.stmtCacheSize = this.stmtCacheSize;
422
- stats.sodaMetaDataCache = this.sodaMetaDataCache;
423
- stats.threadPoolSize = process.env.UV_THREADPOOL_SIZE;
424
-
425
- return stats;
348
+ return new PoolStatistics(this);
426
349
  }
427
350
 
428
351
 
@@ -467,6 +390,35 @@ function _setup(poolAttrs, poolAlias, oracledb) {
467
390
  this._sessionCallback = poolAttrs.sessionCallback;
468
391
  }
469
392
 
393
+ // Properties - edition, events, externalAuth - values can be set globally
394
+ // on oracledb and can be overridden at pool creation time.
395
+ if (typeof poolAttrs.edition !== 'undefined') {
396
+ this.edition = poolAttrs.edition;
397
+ } else {
398
+ this.edition = oracledb.edition;
399
+ }
400
+
401
+ if (typeof poolAttrs.events !== 'undefined') {
402
+ this.events = poolAttrs.events;
403
+ } else {
404
+ this.events = oracledb.events;
405
+ }
406
+
407
+ if (typeof poolAttrs.externalAuth !== 'undefined') {
408
+ this.externalAuth = poolAttrs.externalAuth;
409
+ } else {
410
+ this.externalAuth = oracledb.externalAuth;
411
+ }
412
+
413
+ // Properties - homogeneous, user, connectString - are NOT global properties
414
+ if (typeof poolAttrs.homogeneous !== 'undefined') {
415
+ this.homogeneous = poolAttrs.homogeneous;
416
+ } else {
417
+ this.homogeneous = true;
418
+ }
419
+ this.user = poolAttrs.user || poolAttrs.userName;
420
+ this.connectString = poolAttrs.connectString || poolAttrs.connectionString;
421
+
470
422
  // register event handler for when request queue should be checked
471
423
  this.on('_checkRequestQueue', this._checkRequestQueue);
472
424
 
@@ -536,6 +488,18 @@ function _setup(poolAttrs, poolAlias, oracledb) {
536
488
  }
537
489
 
538
490
 
491
+ //-----------------------------------------------------------------------------
492
+ // setAccessToken()
493
+ // set parameters for token based authentication
494
+ //-----------------------------------------------------------------------------
495
+ async function setAccessToken(options) {
496
+ // check arguments
497
+ nodbUtil.checkArgCount(arguments, 1, 1);
498
+ nodbUtil.assert(nodbUtil.isObject(options), 'NJS-005', 1);
499
+ await this._setAccessToken(options);
500
+ }
501
+
502
+
539
503
  class Pool extends EventEmitter {
540
504
 
541
505
  _extend(oracledb) {
@@ -545,6 +509,7 @@ class Pool extends EventEmitter {
545
509
  this.close = nodbUtil.callbackify(close);
546
510
  this.getConnection = nodbUtil.callbackify(getConnection);
547
511
  this.reconfigure = nodbUtil.callbackify(reconfigure);
512
+ this.setAccessToken = nodbUtil.callbackify(setAccessToken);
548
513
  this.logStatistics = logStatistics;
549
514
  this.getStatistics = getStatistics;
550
515
  this.terminate = this.close;