oracledb 5.4.0 → 6.0.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 (108) hide show
  1. package/CHANGELOG.md +1 -1849
  2. package/LICENSE.txt +8 -222
  3. package/NOTICE.txt +1 -1
  4. package/README.md +38 -30
  5. package/SECURITY.md +38 -0
  6. package/THIRD_PARTY_LICENSES.txt +1 -1
  7. package/build/Release/oracledb-6.0.0-darwin-x64.node +0 -0
  8. package/build/Release/oracledb-6.0.0-darwin-x64.node-buildinfo.txt +1 -0
  9. package/build/Release/oracledb-6.0.0-js-buildinfo.txt +1 -0
  10. package/build/Release/oracledb-6.0.0-linux-arm64.node +0 -0
  11. package/build/Release/oracledb-6.0.0-linux-arm64.node-buildinfo.txt +1 -0
  12. package/build/Release/oracledb-6.0.0-linux-x64.node +0 -0
  13. package/build/Release/oracledb-6.0.0-linux-x64.node-buildinfo.txt +1 -0
  14. package/build/Release/oracledb-6.0.0-win32-x64.node +0 -0
  15. package/build/Release/oracledb-6.0.0-win32-x64.node-buildinfo.txt +1 -0
  16. package/examples/README.md +113 -0
  17. package/examples/dbconfig.js +100 -0
  18. package/examples/example.js +156 -0
  19. package/index.js +26 -0
  20. package/lib/aqDeqOptions.js +146 -7
  21. package/lib/aqEnqOptions.js +59 -7
  22. package/lib/aqMessage.js +118 -7
  23. package/lib/aqQueue.js +242 -53
  24. package/lib/connection.js +1324 -465
  25. package/lib/constants.js +203 -0
  26. package/lib/dbObject.js +346 -32
  27. package/lib/errors.js +781 -0
  28. package/lib/impl/aqDeqOptions.js +197 -0
  29. package/lib/impl/aqEnqOptions.js +89 -0
  30. package/lib/impl/aqMessage.js +134 -0
  31. package/lib/impl/aqQueue.js +81 -0
  32. package/lib/impl/connection.js +529 -0
  33. package/lib/impl/dbObject.js +159 -0
  34. package/lib/impl/index.js +59 -0
  35. package/lib/impl/lob.js +85 -0
  36. package/lib/impl/pool.js +195 -0
  37. package/lib/impl/resultset.js +223 -0
  38. package/lib/impl/sodaCollection.js +174 -0
  39. package/lib/impl/sodaDatabase.js +81 -0
  40. package/lib/impl/sodaDocCursor.js +63 -0
  41. package/lib/impl/sodaDocument.js +98 -0
  42. package/lib/impl/sodaOperation.js +109 -0
  43. package/lib/lob.js +156 -68
  44. package/lib/oracledb.js +1051 -257
  45. package/lib/pool.js +654 -465
  46. package/lib/poolStatistics.js +23 -9
  47. package/lib/queryStream.js +14 -7
  48. package/lib/resultset.js +292 -171
  49. package/lib/settings.js +191 -0
  50. package/lib/sodaCollection.js +214 -201
  51. package/lib/sodaDatabase.js +107 -71
  52. package/lib/sodaDocCursor.js +44 -32
  53. package/lib/sodaDocument.js +76 -14
  54. package/lib/sodaOperation.js +131 -118
  55. package/lib/thin/connection.js +1038 -0
  56. package/lib/thin/dbObject.js +629 -0
  57. package/lib/thin/index.js +40 -0
  58. package/lib/thin/lob.js +188 -0
  59. package/lib/thin/pool.js +481 -0
  60. package/lib/thin/protocol/buffer.js +1040 -0
  61. package/lib/thin/protocol/capabilities.js +116 -0
  62. package/lib/thin/protocol/constants.js +764 -0
  63. package/lib/thin/protocol/encryptDecrypt.js +185 -0
  64. package/lib/thin/protocol/messages/auth.js +348 -0
  65. package/lib/thin/protocol/messages/base.js +475 -0
  66. package/lib/thin/protocol/messages/commit.js +56 -0
  67. package/lib/thin/protocol/messages/dataType.js +382 -0
  68. package/lib/thin/protocol/messages/execute.js +312 -0
  69. package/lib/thin/protocol/messages/fetch.js +60 -0
  70. package/lib/thin/protocol/messages/index.js +53 -0
  71. package/lib/thin/protocol/messages/lobOp.js +200 -0
  72. package/lib/thin/protocol/messages/logOff.js +53 -0
  73. package/lib/thin/protocol/messages/ping.js +56 -0
  74. package/lib/thin/protocol/messages/protocol.js +78 -0
  75. package/lib/thin/protocol/messages/rollback.js +56 -0
  76. package/lib/thin/protocol/messages/sessionRelease.js +60 -0
  77. package/lib/thin/protocol/messages/withData.js +811 -0
  78. package/lib/thin/protocol/oson.js +660 -0
  79. package/lib/thin/protocol/packet.js +520 -0
  80. package/lib/thin/protocol/protocol.js +202 -0
  81. package/lib/thin/protocol/utils.js +88 -0
  82. package/lib/thin/resultSet.js +122 -0
  83. package/lib/thin/sqlnet/connStrategy.js +175 -0
  84. package/lib/thin/sqlnet/constants.js +199 -0
  85. package/lib/thin/sqlnet/ezConnectResolver.js +488 -0
  86. package/lib/thin/sqlnet/navNodes.js +870 -0
  87. package/lib/thin/sqlnet/networkSession.js +620 -0
  88. package/lib/thin/sqlnet/ntTcp.js +525 -0
  89. package/lib/thin/sqlnet/nvStrToNvPair.js +783 -0
  90. package/lib/thin/sqlnet/packet.js +405 -0
  91. package/lib/thin/sqlnet/paramParser.js +205 -0
  92. package/lib/thin/sqlnet/sessionAtts.js +160 -0
  93. package/lib/thin/statement.js +301 -0
  94. package/lib/thin/util.js +289 -0
  95. package/lib/transformer.js +250 -0
  96. package/lib/types.js +357 -0
  97. package/lib/util.js +194 -108
  98. package/lib/version.js +36 -0
  99. package/package/README.md +33 -30
  100. package/package/install.js +89 -64
  101. package/package/prunebinaries.js +60 -12
  102. package/package.json +3 -3
  103. package/build/Release/oracledb-5.4.0-darwin-x64.node +0 -0
  104. package/build/Release/oracledb-5.4.0-darwin-x64.node-buildinfo.txt +0 -1
  105. package/build/Release/oracledb-5.4.0-linux-x64.node +0 -0
  106. package/build/Release/oracledb-5.4.0-linux-x64.node-buildinfo.txt +0 -1
  107. package/build/Release/oracledb-5.4.0-win32-x64.node +0 -0
  108. package/build/Release/oracledb-5.4.0-win32-x64.node-buildinfo.txt +0 -1
package/lib/pool.js CHANGED
@@ -2,16 +2,23 @@
2
2
 
3
3
  //-----------------------------------------------------------------------------
4
4
  //
5
- // You may not use the identified files except in compliance with the Apache
6
- // License, Version 2.0 (the "License.")
5
+ // This software is dual-licensed to you under the Universal Permissive License
6
+ // (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
7
+ // 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose
8
+ // either license.
7
9
  //
10
+ // If you elect to accept the software under the Apache License, Version 2.0,
11
+ // the following applies:
12
+ //
13
+ // Licensed under the Apache License, Version 2.0 (the "License");
14
+ // you may not use this file except in compliance with the License.
8
15
  // You may obtain a copy of the License at
9
- // http://www.apache.org/licenses/LICENSE-2.0.
10
16
  //
11
- // Unless required by applicable law or agreed to in writing, software
12
- // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
- // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ // https://www.apache.org/licenses/LICENSE-2.0
14
18
  //
19
+ // Unless required by applicable law or agreed to in writing, software
20
+ // distributed under the License is distributed on an "AS IS" BASIS,
21
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
22
  // See the License for the specific language governing permissions and
16
23
  // limitations under the License.
17
24
  //
@@ -19,564 +26,746 @@
19
26
 
20
27
  'use strict';
21
28
 
29
+ const Connection = require('./connection.js');
22
30
  const EventEmitter = require('events');
31
+ const constants = require('./constants.js');
32
+ const errors = require('./errors.js');
33
+ const settings = require('./settings.js');
23
34
  const nodbUtil = require('./util.js');
24
- const util = require('util');
35
+ const impl = require('./impl');
25
36
  const PoolStatistics = require('./poolStatistics.js');
26
37
 
27
38
 
28
- //-----------------------------------------------------------------------------
29
- // _checkRequestQueue()
30
- // When a connection is returned to the pool, this method is called (via an
31
- // event handler) to determine when requests for connections should be
32
- // resumed and cancels any timeout that may have been associated with the
33
- // request. This method is also called from reconfigure() so that waiting
34
- // connection requests can be processed. Note the use of a local variable for
35
- // the number of connections out. This is because the connection requests will
36
- // not resume until after the loop is finished, and therefore the number of
37
- // connections the pool thinks is out will not be incremented.
38
- //-----------------------------------------------------------------------------
39
- function _checkRequestQueue() {
40
- let connectionsOut = this._connectionsOut;
41
- while (this._connRequestQueue.length > 0 && connectionsOut < this.poolMax) {
42
- connectionsOut += 1;
43
- const payload = this._connRequestQueue.shift();
44
- if (this._enableStatistics) {
45
- this._totalRequestsDequeued += 1;
46
- this._updateWaitStatistics(payload);
47
- }
48
- if (payload.timeoutHandle) {
49
- clearTimeout(payload.timeoutHandle);
39
+ class Pool extends EventEmitter {
40
+
41
+ constructor() {
42
+ super();
43
+ this._impl = new impl.PoolImpl();
44
+ this._queueMax = 0;
45
+ this._queueTimeout = 0;
46
+ this._enableStatistics = false;
47
+ this._timeOfReset = this._createdDate = Date.now();
48
+ this._sessionCallback = undefined;
49
+ this._connRequestQueue = [];
50
+ }
51
+
52
+ //---------------------------------------------------------------------------
53
+ // _checkPoolOpen()
54
+ //
55
+ // Check if the pool is open (not draining/reconfiguring/closed) and throw an
56
+ // appropriate exception if not.
57
+ //---------------------------------------------------------------------------
58
+ _checkPoolOpen(ignoreReconfiguring) {
59
+ if (this.status === constants.POOL_STATUS_DRAINING) {
60
+ errors.throwErr(errors.ERR_POOL_CLOSING);
61
+ } else if (this.status === constants.POOL_STATUS_CLOSED) {
62
+ errors.throwErr(errors.ERR_POOL_CLOSED);
63
+ } else if (!ignoreReconfiguring) {
64
+ if (this.status === constants.POOL_STATUS_RECONFIGURING) {
65
+ errors.throwErr(errors.ERR_POOL_RECONFIGURING);
66
+ }
50
67
  }
51
- // inform the waiter that processing can continue
52
- payload.resolve();
53
68
  }
54
- }
55
69
 
70
+ //---------------------------------------------------------------------------
71
+ // _checkRequestQueue()
72
+ //
73
+ // When a connection is returned to the pool, this method is called (via an
74
+ // event handler) to determine when requests for connections should be
75
+ // resumed and cancels any timeout that may have been associated with the
76
+ // request. This method is also called from reconfigure() so that waiting
77
+ // connection requests can be processed. Note the use of a local variable for
78
+ // the number of connections out. This is because the connection requests will
79
+ // not resume until after the loop is finished, and therefore the number of
80
+ // connections the pool thinks is out will not be incremented.
81
+ //---------------------------------------------------------------------------
82
+ _checkRequestQueue() {
83
+ let connectionsOut = this._connectionsOut;
84
+ while (this._connRequestQueue.length > 0 && connectionsOut < this.poolMax) {
85
+ connectionsOut += 1;
86
+ const payload = this._connRequestQueue.shift();
87
+ if (this._enableStatistics) {
88
+ this._totalRequestsDequeued += 1;
89
+ this._updateWaitStatistics(payload);
90
+ }
91
+ if (payload.timeoutHandle) {
92
+ clearTimeout(payload.timeoutHandle);
93
+ }
94
+ // inform the waiter that processing can continue
95
+ payload.resolve();
96
+ }
97
+ }
56
98
 
57
- //-----------------------------------------------------------------------------
58
- // getConnection()
59
- // Gets a connection from the pool and returns it to the caller. If there are
60
- // fewer connections out than the poolMax setting, then the request will
61
- // return immediately; otherwise, the request will be queued for up to
62
- // queueTimeout milliseconds.
63
- //-----------------------------------------------------------------------------
64
- async function getConnection(a1) {
65
- let poolMax;
66
- let options = {};
99
+ //---------------------------------------------------------------------------
100
+ // _enableStats (DEPRECATED)
101
+ //
102
+ // Property for whether statistics are enabled on the pool.
103
+ //---------------------------------------------------------------------------
104
+ get _enableStats() {
105
+ return this._enableStatistics;
106
+ }
67
107
 
68
- // check arguments
69
- nodbUtil.checkArgCount(arguments, 0, 1);
70
- if (arguments.length == 1) {
71
- nodbUtil.assert(nodbUtil.isObject(a1), 'NJS-005', 1);
72
- options = a1;
108
+ //---------------------------------------------------------------------------
109
+ // _resetStatistics()
110
+ // To initialize the counters/timers
111
+ //---------------------------------------------------------------------------
112
+ _resetStatistics() {
113
+ this._timeOfReset = Date.now();
114
+ this._totalConnectionRequests = 0;
115
+ this._totalRequestsEnqueued = 0;
116
+ this._totalRequestsDequeued = 0;
117
+ this._totalFailedRequests = 0;
118
+ this._totalRequestsRejected = 0;
119
+ this._totalRequestTimeouts = 0;
120
+ this._maximumQueueLength = this._connRequestQueue.length;
121
+ this._totalTimeInQueue = 0;
122
+ this._minTimeInQueue = 0;
123
+ this._maxTimeInQueue = 0;
73
124
  }
74
125
 
75
- // if pool is draining/closed, throw an appropriate error
76
- this._checkPoolOpen(true);
126
+ //---------------------------------------------------------------------------
127
+ // _setup()
128
+ //
129
+ // Sets up the pool instance with additional attributes used for logging
130
+ // statistics and managing the connection queue.
131
+ //---------------------------------------------------------------------------
132
+ _setup(options, poolAlias) {
133
+ this._queueTimeout = options.queueTimeout;
134
+ this._queueMax = options.queueMax;
135
+ this._enableStatistics = options.enableStatistics;
136
+ this._edition = options.edition;
137
+ this._eventsFlag = options.events;
138
+ this._externalAuth = options.externalAuth;
139
+ this._homogeneous = options.homogeneous;
140
+ this._user = options.user;
141
+ this._connectString = options.connectString;
142
+ this._status = constants.POOL_STATUS_OPEN;
143
+ this._connectionsOut = 0;
144
+ this._poolAlias = poolAlias;
145
+
146
+ // register event handler for when request queue should be checked
147
+ this.on('_checkRequestQueue', this._checkRequestQueue);
148
+
149
+ this._resetStatistics();
77
150
 
78
- // manage stats, if applicable
79
- if (this._enableStatistics) {
80
- this._totalConnectionRequests += 1;
81
151
  }
82
152
 
83
- // getting the poolMax setting on the pool may fail if the pool is no longer
84
- // valid
85
- try {
86
- poolMax = this.poolMax;
87
- } catch (err) {
88
- if (this._enableStatistics) {
89
- this._totalFailedRequests += 1;
153
+ //---------------------------------------------------------------------------
154
+ // _updateWaitStatistics()
155
+ //
156
+ // Update pool wait statistics after a connect request has spent some time in
157
+ // the queue.
158
+ //---------------------------------------------------------------------------
159
+ _updateWaitStatistics(payload) {
160
+ const waitTime = Date.now() - payload.enqueuedTime;
161
+ this._totalTimeInQueue += waitTime;
162
+ if (this._minTimeInQueue === 0) {
163
+ this._minTimeInQueue = waitTime;
164
+ } else {
165
+ this._minTimeInQueue = Math.min(this._minTimeInQueue, waitTime);
90
166
  }
91
- throw err;
167
+ this._maxTimeInQueue = Math.max(this._maxTimeInQueue, waitTime);
92
168
  }
93
169
 
94
- if (this._connectionsOut >= poolMax ||
95
- this.status === this._oracledb.POOL_STATUS_RECONFIGURING) {
170
+ //---------------------------------------------------------------------------
171
+ // _verifyGetConnectionOptions()
172
+ //
173
+ // Verify the getConnection() options are acceptable. Performs any
174
+ // transformations that are needed before returning the options to the
175
+ // caller.
176
+ //---------------------------------------------------------------------------
177
+ _verifyGetConnectionOptions(options) {
96
178
 
97
- // when the queue is huge, throw error early without waiting for queue timeout
98
- if (this._connRequestQueue.length >= this._queueMax &&
99
- this._queueMax >= 0) {
100
- if (this._enableStatistics) {
101
- this._totalRequestsRejected += 1;
102
- }
103
- throw new Error(nodbUtil.getErrorMessage('NJS-076', this._queueMax));
104
- }
179
+ // define normalized options (value returned to caller)
180
+ const outOptions = {};
105
181
 
106
- // if too many connections are out, wait until room is made available or the
107
- // queue timeout expires
108
- await new Promise((resolve, reject) => {
109
-
110
- // set up a payload which will be added to the queue for processing
111
- const payload = { resolve: resolve, reject: reject };
112
-
113
- // if using a queue timeout, establish the timeout so that when it
114
- // expires the payload will be removed from the queue and an exception
115
- // thrown
116
- if (this._queueTimeout !== 0) {
117
- payload.timeoutHandle = setTimeout(() => {
118
- const ix = this._connRequestQueue.indexOf(payload);
119
- if (ix >= 0) {
120
- this._connRequestQueue.splice(ix, 1);
121
- }
122
- if (this._enableStatistics) {
123
- this._totalRequestTimeouts += 1;
124
- this._updateWaitStatistics(payload);
125
- }
126
- reject(new Error(nodbUtil.getErrorMessage('NJS-040',
127
- this._queueTimeout)));
128
- }, this._queueTimeout);
129
- }
182
+ // only one of "user" and "username" may be specified (and must be strings)
183
+ if (options.user !== undefined) {
184
+ errors.assertParamPropValue(typeof options.user === 'string', 1, "user");
185
+ outOptions.user = options.user;
186
+ }
187
+ if (options.username !== undefined) {
188
+ errors.assert(outOptions.user === undefined, errors.ERR_DBL_USER);
189
+ errors.assertParamPropValue(typeof options.username === 'string', 1,
190
+ "username");
191
+ outOptions.user = options.username;
192
+ }
130
193
 
131
- // add payload to the queue
132
- this._connRequestQueue.push(payload);
133
- if (this._enableStatistics) {
134
- payload.enqueuedTime = Date.now();
135
- this._totalRequestsEnqueued += 1;
136
- this._maximumQueueLength = Math.max(this._maximumQueueLength,
137
- this._connRequestQueue.length);
138
- }
194
+ // password must be a string
195
+ if (options.password !== undefined) {
196
+ errors.assertParamPropValue(typeof options.password === 'string', 1,
197
+ "password");
198
+ outOptions.password = options.password;
199
+ }
139
200
 
140
- });
201
+ // tag must be a string
202
+ if (options.tag !== undefined) {
203
+ errors.assertParamPropValue(typeof options.tag === 'string', 1, "tag");
204
+ outOptions.tag = options.tag;
205
+ }
141
206
 
142
- // check if pool is draining/closed after delay has
143
- // completed and throw an appropriate error
144
- this._checkPoolOpen(true);
207
+ // matchAnyTag must be a boolean
208
+ if (options.matchAnyTag !== undefined) {
209
+ errors.assertParamPropValue(typeof options.matchAnyTag === 'boolean', 1,
210
+ "matchAnyTag");
211
+ outOptions.matchAnyTag = options.matchAnyTag;
212
+ }
145
213
 
146
- }
214
+ // shardingKey must be an array of values
215
+ if (options.shardingKey !== undefined) {
216
+ const value = options.shardingKey;
217
+ errors.assertParamPropValue(nodbUtil.isShardingKey(value), 1,
218
+ "shardingKey");
219
+ outOptions.shardingKey = options.shardingKey;
220
+ }
147
221
 
148
- // room is available in the queue, so proceed to acquire a connection from
149
- // the pool; adjust the connections out immediately in order to ensure that
150
- // another attempt doesn't proceed while this one is underway
151
- this._connectionsOut += 1;
152
- try {
222
+ // superShardingKey must be an array of values
223
+ if (options.superShardingKey !== undefined) {
224
+ const value = options.superShardingKey;
225
+ errors.assertParamPropValue(nodbUtil.isShardingKey(value), 1,
226
+ "superShardingKey");
227
+ outOptions.superShardingKey = options.superShardingKey;
228
+ }
153
229
 
154
- // acquire connection from the pool
155
- const conn = await this._getConnection(options);
230
+ return outOptions;
231
+ }
156
232
 
157
- // invoke tag fixup callback method if one has been specified and the
158
- // actual tag on the connection doesn't match the one requested, or the
159
- // connection is freshly created; if the callback fails, close the
160
- // connection and remove it from the pool
161
- const requestedTag = options.tag || "";
162
- if (typeof this.sessionCallback === 'function' &&
163
- (conn._newSession || conn.tag != requestedTag)) {
164
- try {
165
- await new Promise((resolve, reject) => {
166
- this.sessionCallback(conn, requestedTag, function(err) {
167
- if (err) {
168
- reject(err);
169
- } else {
170
- resolve();
171
- }
172
- });
173
- });
174
- } catch (err) {
175
- await conn.close({ drop: true });
176
- throw err;
233
+ //---------------------------------------------------------------------------
234
+ // close()
235
+ //
236
+ // Close the pool, optionally allowing for a period of time to pass for
237
+ // connections to "drain" from the pool.
238
+ //---------------------------------------------------------------------------
239
+ async close(a1) {
240
+ let drainTime = 0;
241
+ let forceClose = false;
242
+
243
+ // check arguments
244
+ errors.assertArgCount(arguments, 0, 1);
245
+ if (arguments.length == 1) {
246
+
247
+ // drain time must be a valid number; timeouts larger than a 32-bit signed
248
+ // integer are not supported
249
+ errors.assertParamValue(typeof a1 === 'number', 1);
250
+ if (a1 < 0 || isNaN(a1) || a1 > 2 ** 31) {
251
+ errors.throwErr(errors.ERR_INVALID_PARAMETER_VALUE, 1);
177
252
  }
178
- }
179
253
 
180
- // when connection is closed, check to see if another request should be
181
- // processed and update any stats, as needed
182
- conn.on('_afterConnClose', () => {
183
- this._connectionsOut -= 1;
184
- this.emit('_checkRequestQueue');
185
- if (this._connectionsOut == 0) {
186
- this.emit('_allCheckedIn');
254
+ // no need to worry about drain time if no connections are out!
255
+ forceClose = true;
256
+ if (this._connectionsOut > 0) {
257
+ drainTime = a1 * 1000;
187
258
  }
188
- });
189
-
190
- return (conn);
191
259
 
192
- } catch (err) {
193
- this._connectionsOut -= 1;
194
- if (this._enableStatistics) {
195
- this._totalFailedRequests += 1;
196
260
  }
197
- this.emit('_checkRequestQueue');
198
- throw err;
199
- }
200
261
 
201
- }
262
+ // if the pool is draining/reconfiguring/closed, throw an appropriate error
263
+ this._checkPoolOpen(false);
264
+
265
+ // wait for the pool to become empty or for the drain timeout to expire
266
+ // (whichever comes first)
267
+ if (drainTime > 0) {
268
+ this._status = constants.POOL_STATUS_DRAINING;
269
+ await new Promise(resolve => {
270
+ const timeout = setTimeout(() => {
271
+ this.removeAllListeners('_allCheckedIn');
272
+ resolve();
273
+ }, drainTime);
274
+ this.once('_allCheckedIn', () => {
275
+ clearTimeout(timeout);
276
+ resolve();
277
+ });
278
+ });
279
+ }
202
280
 
281
+ // close the pool
282
+ await this._impl.close({forceClose: forceClose});
283
+ this._status = constants.POOL_STATUS_CLOSED;
284
+ this.emit('_afterPoolClose');
203
285
 
204
- //-----------------------------------------------------------------------------
205
- // reconfigure()
206
- // Reconfigure the pool, change the value for given pool-properties.
207
- //-----------------------------------------------------------------------------
208
- async function reconfigure(options) {
286
+ }
209
287
 
210
- // check arguments
211
- nodbUtil.checkArgCount(arguments, 1, 1);
212
- nodbUtil.assert(nodbUtil.isObject(options));
288
+ //---------------------------------------------------------------------------
289
+ // connectionsInUse
290
+ //
291
+ // Property for the number of connections in use by the pool.
292
+ //---------------------------------------------------------------------------
293
+ get connectionsInUse() {
294
+ return this._impl.getConnectionsInUse();
295
+ }
213
296
 
214
- // reconfiguration can happen only when status is OPEN
215
- this._checkPoolOpen(false);
297
+ //---------------------------------------------------------------------------
298
+ // connectionsOpen
299
+ //
300
+ // Property for the number of connections opened by the pool.
301
+ //---------------------------------------------------------------------------
302
+ get connectionsOpen() {
303
+ return this._impl.getConnectionsOpen();
304
+ }
216
305
 
217
- if ((options.queueMax !== undefined) &&
218
- (typeof options.queueMax !== "number"))
219
- throw new Error(nodbUtil.getErrorMessage('NJS-004', "queueMax"));
306
+ //---------------------------------------------------------------------------
307
+ // connectString
308
+ //
309
+ // Property for the connect string used to create the pool.
310
+ //---------------------------------------------------------------------------
311
+ get connectString() {
312
+ return this._connectString;
313
+ }
220
314
 
221
- if ((options.queueTimeout !== undefined) &&
222
- (typeof options.queueTimeout !== "number"))
223
- throw new Error(nodbUtil.getErrorMessage('NJS-004', "queueTimeout"));
315
+ //---------------------------------------------------------------------------
316
+ // thin()
317
+ //
318
+ // return true, if driver mode is thin while creating pool
319
+ // return false, if driver mode is thick while creating pool
320
+ //---------------------------------------------------------------------------
321
+ get thin() {
322
+ return settings.thin;
323
+ }
224
324
 
225
- if ((options.enableStatistics !== undefined) &&
226
- (typeof options.enableStatistics !== "boolean"))
227
- throw new Error(nodbUtil.getErrorMessage('NJS-004', "enableStatistics"));
325
+ //---------------------------------------------------------------------------
326
+ // edition
327
+ //
328
+ // Property for the edition used to create the pool.
329
+ //---------------------------------------------------------------------------
330
+ get edition() {
331
+ return this._edition;
332
+ }
228
333
 
229
- if ((options.resetStatistics !== undefined) &&
230
- (typeof options.resetStatistics != "boolean"))
231
- throw new Error(nodbUtil.getErrorMessage('NJS-004', "resetStatistics"));
334
+ //---------------------------------------------------------------------------
335
+ // enableStatistics
336
+ //
337
+ // Property for whether statistics are enabled on the pool.
338
+ //---------------------------------------------------------------------------
339
+ get enableStatistics() {
340
+ return this._enableStatistics;
341
+ }
232
342
 
233
- this._status = this._oracledb.POOL_STATUS_RECONFIGURING;
234
- try {
235
- // poolMin/poolMax/poolIncrement/poolPingInterval/poolTimeout/
236
- // poolMaxPerShard/stmtCacheSize/sodaMetaDataCache parameters
237
- await this._reconfigure(options);
343
+ //---------------------------------------------------------------------------
344
+ // events
345
+ //
346
+ // Property for the events flag value used to create the pool.
347
+ //---------------------------------------------------------------------------
348
+ get events() {
349
+ return this._eventsFlag;
350
+ }
238
351
 
239
- // pool JS parameters: queueMax, queueTimeout, enableStatistics,
240
- // resetStatistics
352
+ //---------------------------------------------------------------------------
353
+ // externalAuth
354
+ //
355
+ // Property for the externalAuth flag value used to create the pool.
356
+ //---------------------------------------------------------------------------
357
+ get externalAuth() {
358
+ return this._externalAuth;
359
+ }
241
360
 
242
- // reset the statistics-metrics only if 'resetStatistics' is true or
243
- // 'enableStatistics' is being set to true
244
- if (options.resetStatistics == true || (options.enableStatistics == true &&
245
- this._enableStatistics == false)) {
246
- this._resetStatistics();
361
+ //---------------------------------------------------------------------------
362
+ // getConnection()
363
+ //
364
+ // Gets a connection from the pool and returns it to the caller. If there are
365
+ // fewer connections out than the poolMax setting, then the request will
366
+ // return immediately; otherwise, the request will be queued for up to
367
+ // queueTimeout milliseconds.
368
+ //---------------------------------------------------------------------------
369
+ async getConnection(a1) {
370
+ let poolMax;
371
+ let options = {};
372
+
373
+ // check arguments
374
+ errors.assertArgCount(arguments, 0, 1);
375
+ if (arguments.length == 1) {
376
+ errors.assertParamValue(nodbUtil.isObject(a1), 1);
377
+ options = this._verifyGetConnectionOptions(a1);
247
378
  }
379
+ settings.addToOptions(options, "connectionClass");
248
380
 
249
- if (options.queueMax !== undefined) {
250
- this._queueMax = options.queueMax;
251
- }
381
+ // if pool is draining/closed, throw an appropriate error
382
+ this._checkPoolOpen(true);
252
383
 
253
- if (options.queueTimeout !== undefined) {
254
- this._queueTimeout = options.queueTimeout;
384
+ // manage stats, if applicable
385
+ if (this._enableStatistics) {
386
+ this._totalConnectionRequests += 1;
255
387
  }
256
388
 
257
- if (options.enableStatistics !== undefined) {
258
- this._enableStatistics = options.enableStatistics;
389
+ // getting the poolMax setting on the pool may fail if the pool is no
390
+ // longer valid
391
+ try {
392
+ poolMax = this.poolMax;
393
+ } catch (err) {
394
+ if (this._enableStatistics) {
395
+ this._totalFailedRequests += 1;
396
+ }
397
+ throw err;
259
398
  }
260
- } finally {
261
- this._status = this._oracledb.POOL_STATUS_OPEN;
262
- }
263
- this.emit('_checkRequestQueue');
264
- }
265
399
 
400
+ if (this._connectionsOut >= poolMax ||
401
+ this.status === constants.POOL_STATUS_RECONFIGURING) {
266
402
 
267
- //-----------------------------------------------------------------------------
268
- // close()
269
- // Close the pool, optionally allowing for a period of time to pass for
270
- // connections to "drain" from the pool.
271
- //-----------------------------------------------------------------------------
272
- async function close(a1) {
273
- let drainTime = 0;
274
- let forceClose = false;
275
-
276
- // check arguments
277
- nodbUtil.checkArgCount(arguments, 0, 1);
278
- if (arguments.length == 1) {
279
-
280
- // drain time must be a valid number; timeouts larger than a 32-bit signed
281
- // integer are not supported
282
- nodbUtil.assert(typeof a1 === 'number', 'NJS-005', 1);
283
- if (a1 < 0 || isNaN(a1) || a1 > 2 ** 31) {
284
- throw new Error(nodbUtil.getErrorMessage('NJS-005', 1));
285
- }
286
-
287
- // no need to worry about drain time if no connections are out!
288
- forceClose = true;
289
- if (this._connectionsOut > 0) {
290
- drainTime = a1 * 1000;
291
- }
403
+ // when the queue is huge, throw error early without waiting for queue
404
+ // timeout
405
+ if (this._connRequestQueue.length >= this._queueMax &&
406
+ this._queueMax >= 0) {
407
+ if (this._enableStatistics) {
408
+ this._totalRequestsRejected += 1;
409
+ }
410
+ errors.throwErr(errors.ERR_QUEUE_MAX_EXCEEDED, this._queueMax);
411
+ }
292
412
 
293
- }
413
+ // if too many connections are out, wait until room is made available or
414
+ // the queue timeout expires
415
+ await new Promise((resolve, reject) => {
416
+
417
+ // set up a payload which will be added to the queue for processing
418
+ const payload = { resolve: resolve, reject: reject };
419
+
420
+ // if using a queue timeout, establish the timeout so that when it
421
+ // expires the payload will be removed from the queue and an exception
422
+ // thrown
423
+ if (this._queueTimeout !== 0) {
424
+ payload.timeoutHandle = setTimeout(() => {
425
+ const ix = this._connRequestQueue.indexOf(payload);
426
+ if (ix >= 0) {
427
+ this._connRequestQueue.splice(ix, 1);
428
+ }
429
+ if (this._enableStatistics) {
430
+ this._totalRequestTimeouts += 1;
431
+ this._updateWaitStatistics(payload);
432
+ }
433
+ try {
434
+ errors.throwErr(errors.ERR_CONN_REQUEST_TIMEOUT,
435
+ this._queueTimeout);
436
+ } catch (err) {
437
+ reject(err);
438
+ }
439
+ }, this._queueTimeout);
440
+ }
294
441
 
295
- // if the pool is draining/reconfiguring/closed, throw an appropriate error
296
- this._checkPoolOpen(false);
442
+ // add payload to the queue
443
+ this._connRequestQueue.push(payload);
444
+ if (this._enableStatistics) {
445
+ payload.enqueuedTime = Date.now();
446
+ this._totalRequestsEnqueued += 1;
447
+ this._maximumQueueLength = Math.max(this._maximumQueueLength,
448
+ this._connRequestQueue.length);
449
+ }
297
450
 
298
- // wait for the pool to become empty or for the drain timeout to expire
299
- // (whichever comes first)
300
- if (drainTime > 0) {
301
- this._status = this._oracledb.POOL_STATUS_DRAINING;
302
- await new Promise(resolve => {
303
- const timeout = setTimeout(() => {
304
- this.removeAllListeners('_allCheckedIn');
305
- resolve();
306
- }, drainTime);
307
- this.once('_allCheckedIn', () => {
308
- clearTimeout(timeout);
309
- resolve();
310
451
  });
311
- });
312
- }
313
452
 
314
- // close the pool
315
- await this._close({forceClose: forceClose});
316
- this._status = this._oracledb.POOL_STATUS_CLOSED;
317
- this.emit('_afterPoolClose');
453
+ // check if pool is draining/closed after delay has
454
+ // completed and throw an appropriate error
455
+ this._checkPoolOpen(true);
318
456
 
319
- }
457
+ }
320
458
 
459
+ // room is available in the queue, so proceed to acquire a connection from
460
+ // the pool; adjust the connections out immediately in order to ensure that
461
+ // another attempt doesn't proceed while this one is underway
462
+ this._connectionsOut += 1;
463
+ try {
464
+
465
+ // acquire connection from the pool
466
+ const conn = new Connection();
467
+ conn._impl = await this._impl.getConnection(options);
468
+ conn._pool = this;
469
+
470
+ // invoke tag fixup callback method if one has been specified and the
471
+ // actual tag on the connection doesn't match the one requested, or the
472
+ // connection is freshly created; if the callback fails, close the
473
+ // connection and remove it from the pool
474
+ const requestedTag = options.tag || "";
475
+ if (typeof this.sessionCallback === 'function' &&
476
+ (conn._impl._newSession || conn.tag != requestedTag)) {
477
+ try {
478
+ await new Promise((resolve, reject) => {
479
+ this.sessionCallback(conn, requestedTag, function(err) {
480
+ if (err) {
481
+ reject(err);
482
+ } else {
483
+ resolve();
484
+ }
485
+ });
486
+ });
487
+ } catch (err) {
488
+ await conn.close({ drop: true });
489
+ throw err;
490
+ }
491
+ }
321
492
 
322
- //-----------------------------------------------------------------------------
323
- // logStatistics()
324
- // Method to print statistical related information and pool related
325
- // information when enableStatistics is set to true.
326
- // NOTE: This function replaces the DEPRECATED _logStats() function
327
- //-----------------------------------------------------------------------------
328
- function logStatistics() {
329
- const stats = this.getStatistics();
330
- if (stats === null) {
331
- throw new Error(nodbUtil.getErrorMessage('NJS-083'));
332
- }
333
- stats.logStatistics();
334
- }
493
+ // when connection is closed, check to see if another request should be
494
+ // processed and update any stats, as needed
495
+ conn.on('_afterConnClose', () => {
496
+ this._connectionsOut -= 1;
497
+ this.emit('_checkRequestQueue');
498
+ if (this._connectionsOut == 0) {
499
+ this.emit('_allCheckedIn');
500
+ }
501
+ });
335
502
 
503
+ return (conn);
336
504
 
337
- //-----------------------------------------------------------------------------
338
- // getStatistics()
339
- // Method to obtain a JSON object with all statistical metrics and pool
340
- // properties
341
- //-----------------------------------------------------------------------------
342
- function getStatistics() {
343
- this._checkPoolOpen(false);
505
+ } catch (err) {
506
+ this._connectionsOut -= 1;
507
+ if (this._enableStatistics) {
508
+ this._totalFailedRequests += 1;
509
+ }
510
+ this.emit('_checkRequestQueue');
511
+ throw err;
512
+ }
344
513
 
345
- if (this._enableStatistics !== true) {
346
- return null;
347
514
  }
348
- return new PoolStatistics(this);
349
- }
350
515
 
516
+ //---------------------------------------------------------------------------
517
+ // getStatistics()
518
+ //
519
+ // Method to obtain a JSON object with all statistical metrics and pool
520
+ // properties
521
+ //---------------------------------------------------------------------------
522
+ getStatistics() {
523
+ this._checkPoolOpen(false);
351
524
 
352
- //-----------------------------------------------------------------------------
353
- // _setup()
354
- // Sets up the pool instance with additional attributes used for logging
355
- // statistics and managing the connection queue.
356
- //-----------------------------------------------------------------------------
357
- function _setup(poolAttrs, poolAlias, oracledb) {
358
- if (typeof poolAttrs.queueTimeout !== 'undefined') {
359
- this._queueTimeout = poolAttrs.queueTimeout;
360
- } else {
361
- this._queueTimeout = oracledb.queueTimeout;
525
+ if (this._enableStatistics !== true) {
526
+ return null;
527
+ }
528
+ return new PoolStatistics(this);
362
529
  }
363
530
 
364
- if (typeof poolAttrs.queueMax !== 'undefined') {
365
- this._queueMax = poolAttrs.queueMax;
366
- } else {
367
- this._queueMax = oracledb.queueMax;
531
+ //---------------------------------------------------------------------------
532
+ // homogeneous
533
+ //
534
+ // Property for the homogeneous flag value used to create the pool.
535
+ //---------------------------------------------------------------------------
536
+ get homogeneous() {
537
+ return this._homogeneous;
368
538
  }
369
539
 
370
- if (typeof poolAttrs.poolMaxPerShard !== 'undefined') {
371
- this.poolMaxPerShard = poolAttrs.poolMaxPerShard;
540
+ //---------------------------------------------------------------------------
541
+ // logStatistics()
542
+ //
543
+ // Method to print statistical related information and pool related
544
+ // information when enableStatistics is set to true.
545
+ //
546
+ // NOTE: This function replaces the DEPRECATED _logStats() function.
547
+ //---------------------------------------------------------------------------
548
+ logStatistics() {
549
+ const stats = this.getStatistics();
550
+ if (stats === null) {
551
+ errors.throwErr(errors.ERR_POOL_STATISTICS_DISABLED);
552
+ }
553
+ stats.logStatistics();
372
554
  }
373
555
 
374
- if (typeof poolAttrs.enableStatistics !== 'undefined') {
375
- this._enableStatistics = poolAttrs.enableStatistics;
376
- } else {
377
- this._enableStatistics = false; // default statistics is disabled.
556
+ //---------------------------------------------------------------------------
557
+ // poolAlias
558
+ //
559
+ // Property for the alias assigned to the pool.
560
+ // ---------------------------------------------------------------------------
561
+ get poolAlias() {
562
+ return this._poolAlias;
378
563
  }
379
564
 
380
- if (!this._enableStatistics) {
381
- // DEPRECATED property _enableStats.
382
- if (typeof poolAttrs._enableStats !== 'undefined') {
383
- this._enableStatistics = poolAttrs._enableStats;
384
- }
565
+ //---------------------------------------------------------------------------
566
+ // poolIncrement
567
+ //
568
+ // Property for the number of connections to create each time the pool needs
569
+ // to grow.
570
+ // ---------------------------------------------------------------------------
571
+ get poolIncrement() {
572
+ return this._impl.getPoolIncrement();
385
573
  }
386
574
 
387
- if (typeof poolAttrs.sessionCallback !== 'undefined') {
388
- if (typeof poolAttrs.sessionCallback === 'function' ||
389
- typeof poolAttrs.sessionCallback === 'string')
390
- this._sessionCallback = poolAttrs.sessionCallback;
391
- }
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
-
422
- // register event handler for when request queue should be checked
423
- this.on('_checkRequestQueue', this._checkRequestQueue);
424
-
425
- // Using Object.defineProperties to add properties to the Pool instance with
426
- // special properties, such as enumerable but not writable.
427
- Object.defineProperties(
428
- this,
429
- {
430
- queueMax: { // maximum number of pending pool connections that can be queued
431
- enumerable: true,
432
- get: function() {
433
- return (this._queueMax);
434
- },
435
- },
436
- queueTimeout: { // milliseconds a connection request can spend in queue before being failed
437
- enumerable: true,
438
- get: function() {
439
- return (this._queueTimeout);
440
- },
441
- },
442
- _enableStats: { // DEPRECATED. true means pool stats will be recorded
443
- get: function() {
444
- return (this._enableStatistics);
445
- }
446
- },
447
- enableStatistics: { // true means pool stats will be recorded
448
- enumerable: true,
449
- get: function() {
450
- return (this._enableStatistics);
451
- }
452
- },
453
- _connectionsOut: { // number of connections checked out from the pool. Must be inc/dec in the main thread in JS
454
- value: 0,
455
- writable: true
456
- },
457
- _connRequestQueue: {
458
- value: [],
459
- writable: true
460
- },
461
- _status: { // open/closing/closed
462
- value: oracledb.POOL_STATUS_OPEN,
463
- writable: true
464
- },
465
- poolAlias: {
466
- enumerable: true,
467
- get: function() {
468
- return (poolAlias);
469
- }
470
- },
471
- status: { // open/closing/closed
472
- enumerable: true,
473
- get: function() {
474
- return (this._status);
475
- }
476
- },
477
- sessionCallback: { // session callback
478
- enumerable: true,
479
- get: function() {
480
- return this._sessionCallback;
481
- }
482
- }
483
- }
484
- );
575
+ //---------------------------------------------------------------------------
576
+ // poolMax
577
+ //
578
+ // Property for the maximum number of connections allowed in the pool.
579
+ //---------------------------------------------------------------------------
580
+ get poolMax() {
581
+ return this._impl.getPoolMax();
582
+ }
583
+
584
+ //---------------------------------------------------------------------------
585
+ // poolMaxPerShard
586
+ //
587
+ // Property for the maximum number of connections allowed in the pool for
588
+ // each shard.
589
+ //---------------------------------------------------------------------------
590
+ get poolMaxPerShard() {
591
+ return this._impl.getPoolMaxPerShard();
592
+ }
485
593
 
486
- this._resetStatistics();
594
+ //---------------------------------------------------------------------------
595
+ // poolMin
596
+ //
597
+ // Property for the minimum number of connections allowed in the pool.
598
+ //---------------------------------------------------------------------------
599
+ get poolMin() {
600
+ return this._impl.getPoolMin();
601
+ }
487
602
 
488
- }
603
+ //---------------------------------------------------------------------------
604
+ // poolPingInterval
605
+ //
606
+ // Property for the ping interval to use for the pool.
607
+ //---------------------------------------------------------------------------
608
+ get poolPingInterval() {
609
+ return this._impl.getPoolPingInterval();
610
+ }
489
611
 
612
+ //---------------------------------------------------------------------------
613
+ // poolTimeout
614
+ //
615
+ // Property for the timeout associated with the pool.
616
+ //---------------------------------------------------------------------------
617
+ get poolTimeout() {
618
+ return this._impl.getPoolTimeout();
619
+ }
490
620
 
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
- }
621
+ //---------------------------------------------------------------------------
622
+ // queueMax
623
+ //
624
+ // Property for the maximum number of pending pool connections that can be
625
+ // queued.
626
+ //---------------------------------------------------------------------------
627
+ get queueMax() {
628
+ return this._queueMax;
629
+ }
501
630
 
631
+ //---------------------------------------------------------------------------
632
+ // queueTimeout
633
+ //
634
+ // Property for the milliseconds a connection request can spend in the queue
635
+ // before an exception is thrown.
636
+ //---------------------------------------------------------------------------
637
+ get queueTimeout() {
638
+ return this._queueTimeout;
639
+ }
502
640
 
503
- class Pool extends EventEmitter {
641
+ //---------------------------------------------------------------------------
642
+ // reconfigure()
643
+ //
644
+ // Reconfigure the pool, change the value for given pool-properties.
645
+ //---------------------------------------------------------------------------
646
+ async reconfigure(options) {
647
+
648
+ // check arguments
649
+ errors.assertArgCount(arguments, 1, 1);
650
+ errors.assertParamValue(nodbUtil.isObject(options));
651
+ errors.assertParamPropUnsignedInt(options, 1, "queueMax");
652
+ errors.assertParamPropUnsignedInt(options, 1, "queueTimeout");
653
+ errors.assertParamPropBool(options, 1, "enableStatistics");
654
+ errors.assertParamPropBool(options, 1, "resetStatistics");
655
+ errors.assertParamPropUnsignedInt(options, 1, "poolMin");
656
+ errors.assertParamPropUnsignedInt(options, 1, "poolMax");
657
+ errors.assertParamPropUnsignedInt(options, 1, "poolMaxPerShard");
658
+ errors.assertParamPropUnsignedInt(options, 1, "poolIncrement");
659
+ errors.assertParamPropInt(options, 1, "poolPingInterval");
660
+ errors.assertParamPropUnsignedInt(options, 1, "poolTimeout");
661
+ errors.assertParamPropUnsignedInt(options, 1, "stmtCacheSize");
662
+ errors.assertParamPropBool(options, 1, "sodaMetaDataCache");
663
+
664
+ // reconfiguration can happen only when status is OPEN
665
+ this._checkPoolOpen(false);
666
+
667
+ this._status = constants.POOL_STATUS_RECONFIGURING;
668
+ try {
669
+ // poolMin/poolMax/poolIncrement/poolPingInterval/poolTimeout/
670
+ // poolMaxPerShard/stmtCacheSize/sodaMetaDataCache parameters
671
+ await this._impl.reconfigure(options);
672
+
673
+ // pool JS parameters: queueMax, queueTimeout, enableStatistics,
674
+ // resetStatistics
675
+
676
+ // reset the statistics-metrics only if 'resetStatistics' is true or
677
+ // 'enableStatistics' is being set to true
678
+ if (options.resetStatistics == true ||
679
+ (options.enableStatistics == true &&
680
+ this._enableStatistics == false)) {
681
+ this._resetStatistics();
682
+ }
504
683
 
505
- _extend(oracledb) {
506
- this._oracledb = oracledb;
507
- this._setup = _setup;
508
- this._checkRequestQueue = _checkRequestQueue;
509
- this.close = nodbUtil.callbackify(close);
510
- this.getConnection = nodbUtil.callbackify(getConnection);
511
- this.reconfigure = nodbUtil.callbackify(reconfigure);
512
- this.setAccessToken = nodbUtil.callbackify(setAccessToken);
513
- this.logStatistics = logStatistics;
514
- this.getStatistics = getStatistics;
515
- this.terminate = this.close;
516
- this._queueMax = 0;
517
- this._queueTimeout = 0;
518
- this._enableStatistics = false;
519
- this._timeOfReset = this._createdDate = Date.now();
520
- this._sessionCallback = undefined;
684
+ if (options.queueMax !== undefined) {
685
+ this._queueMax = options.queueMax;
686
+ }
521
687
 
522
- // DEPRECATED alias
523
- this._logStats = this.logStatistics;
524
- }
688
+ if (options.queueTimeout !== undefined) {
689
+ this._queueTimeout = options.queueTimeout;
690
+ }
525
691
 
526
- // check if pool is draining/reconfiguring/closed and throw an
527
- // appropriate error
528
- _checkPoolOpen(ignoreReconfiguring) {
529
- // if already in reconfiguring status, nothing to do.
530
- if (this.status === this._oracledb.POOL_STATUS_DRAINING) {
531
- throw new Error(nodbUtil.getErrorMessage('NJS-064'));
532
- } else if (this.status === this._oracledb.POOL_STATUS_CLOSED) {
533
- throw new Error(nodbUtil.getErrorMessage('NJS-065'));
534
- } else if (!ignoreReconfiguring) {
535
- if (this.status === this._oracledb.POOL_STATUS_RECONFIGURING) {
536
- throw new Error(nodbUtil.getErrorMessage('NJS-082'));
692
+ if (options.enableStatistics !== undefined) {
693
+ this._enableStatistics = options.enableStatistics;
537
694
  }
695
+ } finally {
696
+ this._status = constants.POOL_STATUS_OPEN;
538
697
  }
698
+ this.emit('_checkRequestQueue');
539
699
  }
540
700
 
541
- // temporary method for determining if an object is a date until
542
- // napi_is_date() can be used (when Node-API v5 can be used)
543
- _isDate(val) {
544
- return (util.isDate(val));
701
+ //---------------------------------------------------------------------------
702
+ // sessionCallback
703
+ //
704
+ // Property for the session callback associated with the pool.
705
+ //---------------------------------------------------------------------------
706
+ get sessionCallback() {
707
+ return this._sessionCallback;
545
708
  }
546
709
 
547
710
  //---------------------------------------------------------------------------
548
- // _resetStatistics()
549
- // To initialize the counters/timers
711
+ // setAccessToken()
712
+ //
713
+ // Set parameters for token based authentication.
550
714
  //---------------------------------------------------------------------------
551
- _resetStatistics() {
552
- this._timeOfReset = Date.now();
553
- this._totalConnectionRequests = 0;
554
- this._totalRequestsEnqueued = 0;
555
- this._totalRequestsDequeued = 0;
556
- this._totalFailedRequests = 0;
557
- this._totalRequestsRejected = 0;
558
- this._totalRequestTimeouts = 0;
559
- this._maximumQueueLength = this._connRequestQueue.length;
560
- this._totalTimeInQueue = 0;
561
- this._minTimeInQueue = 0;
562
- this._maxTimeInQueue = 0;
715
+ async setAccessToken(options) {
716
+ errors.assertArgCount(arguments, 1, 1);
717
+ errors.assertParamValue(nodbUtil.isObject(options), 1);
718
+ errors.assertParamPropString(options, 1, "token");
719
+ errors.assertParamPropString(options, 1, "privateKey");
720
+ await this._impl.setAccessToken(options);
563
721
  }
564
722
 
723
+ //---------------------------------------------------------------------------
724
+ // sodaMetaDataCache
725
+ //
726
+ // Property for whether the SODA metadata cache is enabled or not.
727
+ //---------------------------------------------------------------------------
728
+ get sodaMetaDataCache() {
729
+ return this._impl.getSodaMetaDataCache();
730
+ }
565
731
 
566
- // update pool wait statistics after a connect request has spent some time in
567
- // the queue
568
- _updateWaitStatistics(payload) {
569
- const waitTime = Date.now() - payload.enqueuedTime;
570
- this._totalTimeInQueue += waitTime;
571
- if (this._minTimeInQueue === 0) {
572
- this._minTimeInQueue = waitTime;
573
- } else {
574
- this._minTimeInQueue = Math.min(this._minTimeInQueue, waitTime);
575
- }
576
- this._maxTimeInQueue = Math.max(this._maxTimeInQueue, waitTime);
732
+ //---------------------------------------------------------------------------
733
+ // status
734
+ //
735
+ // Property for the pool's status.
736
+ //---------------------------------------------------------------------------
737
+ get status() {
738
+ return this._status;
739
+ }
740
+
741
+ //---------------------------------------------------------------------------
742
+ // stmtCacheSize
743
+ //
744
+ // Property for the size of the statement cache to use when creating
745
+ // connections in the pool.
746
+ //---------------------------------------------------------------------------
747
+ get stmtCacheSize() {
748
+ return this._impl.getStmtCacheSize();
749
+ }
750
+
751
+ //---------------------------------------------------------------------------
752
+ // user
753
+ //
754
+ // Property for the user used to create the pool.
755
+ //---------------------------------------------------------------------------
756
+ get user() {
757
+ return this._user;
577
758
  }
578
759
 
579
760
  }
580
761
 
762
+ Pool.prototype.close = nodbUtil.callbackify(Pool.prototype.close);
763
+ Pool.prototype.getConnection = nodbUtil.callbackify(Pool.prototype.getConnection);
764
+ Pool.prototype.reconfigure = nodbUtil.callbackify(Pool.prototype.reconfigure);
765
+ Pool.prototype.setAccessToken = nodbUtil.callbackify(Pool.prototype.setAccessToken);
766
+
767
+ // DEPRECATED aliases
768
+ Pool.prototype.terminate = Pool.prototype.close;
769
+ Pool.prototype._logStats = Pool.prototype.logStatistics;
581
770
 
582
771
  module.exports = Pool;