Skip to content

Commit 65cf9ca

Browse files
author
Roman Balayan
committed
Release 5.3.0
1 parent 8c4acb5 commit 65cf9ca

File tree

9 files changed

+333
-96
lines changed

9 files changed

+333
-96
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
# node-oracledb-prebuilt-for-lambda
22

33
- This module is forked from the currently un-maintained [node-oracledb-for-lambda](https://github.com/nalbion/node-oracledb-for-lambda).
4-
- Core oracledb libraries are derived from [node-oracledb](https://github.com/oracle/node-oracledb) v5.2.0
5-
- 5.2.0: Prebuilt for use with AWS Lambda nodejs12.x Runtime (Built using nodejsv12.18.3)
4+
- Core oracledb libraries are derived from [node-oracledb](https://github.com/oracle/node-oracledb) v5.3.0
5+
- 5.3.0: Prebuilt for use with AWS Lambda nodejs12.x Runtime (Built using nodejsv12.18.3)
66
- Also tested to work with AWS Lambda nodejs14.x Runtime
77

88
The scripts to reproduce the build process can be found at [node-oracledb-lambda-test](https://github.com/romanbalayan/node-oracledb-lambda-test).
99

1010
# Usage
1111

1212
```bash
13-
npm install --save oracledb-prebuilt-for-lambda@5.2.0
13+
npm install --save oracledb-prebuilt-for-lambda@5.3.0
1414
```
1515

1616
# Versioning
1717
- Changed release version to match that of underlying node-oracledb version.
18-
- i.e. for release based on oracledb 5.2.0, release will be oracledb-prebuilt-for-lambda@5.2.0
18+
- i.e. for release based on oracledb 5.3.0, release will be oracledb-prebuilt-for-lambda@5.3.0
1919

2020

2121
# Releases
2222
| node-oracledb | oracledb-prebuilt-for-lambda |
2323
| ------------------- | ---------- |
24+
| 5.3.0 | 5.3.0 |
2425
| 5.2.0 | 5.2.0 |
2526
| 5.1.0 | 5.1.0 |
2627
| 5.0.0 | 5.0.0 |
@@ -30,6 +31,7 @@ npm install --save oracledb-prebuilt-for-lambda@5.2.0
3031

3132

3233
# Changelog
34+
- v5.3.0: [node-oracledb v5.3.0 changelog](https://github.com/oracle/node-oracledb/blob/main/CHANGELOG.md#node-oracledb-v530-22-oct-2021)
3335
- v5.2.0: [node-oracledb v5.2.0 changelog](https://github.com/oracle/node-oracledb/blob/main/CHANGELOG.md#node-oracledb-v520-7-jun-2021)
3436
- v5.1.0: [node-oracledb v5.1.0 changelog](https://github.com/oracle/node-oracledb/blob/master/CHANGELOG.md#node-oracledb-v510-8-dec-2020)
3537
- v5.0.0: [node-oracledb v5.0.0 changelog](https://github.com/oracle/node-oracledb/blob/master/CHANGELOG.md#node-oracledb-v500-29-jun-2020)

build/Release/oracledb.node

14.8 KB
Binary file not shown.

lib/connection.js

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,145 @@ function buildDbObjectClass(schema, name, fqn) {
314314
return (DbObject);
315315
}
316316

317+
//-----------------------------------------------------------------------------
318+
// tpcBegin()
319+
// Starts a two-phase-commit transaction
320+
//----------------------------------------------------------------------------
321+
async function tpcBegin(xid, flag, timeout) {
322+
nodbUtil.checkArgCount(arguments, 1, 3);
323+
nodbUtil.assert(nodbUtil.isXid(xid), 'NJS-005', 1);
324+
325+
if (arguments.length < 3) {
326+
timeout = 60; // seconds
327+
} else {
328+
nodbUtil.assert(typeof timeout === 'number', 'NJS-005', 3);
329+
}
330+
331+
if (arguments.length < 2) {
332+
flag = this._oracledb.TPC_BEGIN_NEW;
333+
} else {
334+
nodbUtil.assert(typeof flag === 'number', 'NJS-005', 2);
335+
}
336+
await this._tpcBegin(xid, flag, timeout);
337+
}
338+
339+
340+
//-----------------------------------------------------------------------------
341+
// tpcCommit
342+
// Commit the two-phase-commit transaction
343+
//-----------------------------------------------------------------------------
344+
async function tpcCommit(xid, onePhase) {
345+
nodbUtil.checkArgCount(arguments, 0, 2);
346+
347+
if (arguments.length < 2) {
348+
onePhase = false;
349+
} else {
350+
nodbUtil.assert(typeof onePhase === 'boolean', 'NJS-005', 2);
351+
}
352+
if (arguments.length >= 1) {
353+
nodbUtil.assert(nodbUtil.isXid(xid), 'NJS-005', 1);
354+
}
355+
await this._tpcCommit(xid, onePhase);
356+
}
357+
358+
359+
//-----------------------------------------------------------------------------
360+
// tpcEnd
361+
// Ends the two-phase-commit transaction
362+
//-----------------------------------------------------------------------------
363+
async function tpcEnd(xid, flag) {
364+
nodbUtil.checkArgCount(arguments, 0, 2);
365+
366+
if (arguments.length < 2) {
367+
flag = this._oracledb.TPC_END_NORMAL;
368+
} else {
369+
nodbUtil.assert(typeof flag === 'number', 'NJS-005', 2);
370+
}
371+
372+
if (arguments.length >= 1) {
373+
nodbUtil.assert(nodbUtil.isXid(xid), 'NJS-005', 1);
374+
}
375+
376+
await this._tpcEnd(xid, flag);
377+
}
378+
379+
380+
//-----------------------------------------------------------------------------
381+
// tpcForget
382+
// causes the server to forget a heuristically completed global transaction.
383+
//-----------------------------------------------------------------------------
384+
async function tpcForget(xid) {
385+
386+
nodbUtil.checkArgCount(arguments, 1, 1);
387+
nodbUtil.assert(nodbUtil.isXid(xid), 'NJS-005', 1);
388+
389+
await this._tpcForget(xid);
390+
}
391+
392+
393+
//-----------------------------------------------------------------------------
394+
// tpcPrepare
395+
// prepares a global transaction for commit.
396+
//-----------------------------------------------------------------------------
397+
async function tpcPrepare(xid) {
398+
nodbUtil.checkArgCount(arguments, 0, 1);
399+
400+
if (arguments.length >= 1) {
401+
nodbUtil.assert(nodbUtil.isXid(xid), 'NJS-005', 1);
402+
}
403+
404+
return await this._tpcPrepare(xid);
405+
}
406+
407+
408+
//-----------------------------------------------------------------------------
409+
// tpcRecover
410+
// Returns a list of pending transactions
411+
//-----------------------------------------------------------------------------
412+
async function tpcRecover(asString) {
413+
nodbUtil.checkArgCount(arguments, 0, 1);
414+
415+
if (arguments.length == 1) {
416+
nodbUtil.assert(typeof asString === 'boolean', 'NJS-005', 1);
417+
} else {
418+
asString = true;
419+
}
420+
421+
const sqlStr = `
422+
SELECT
423+
formatid as "formatId",
424+
UTL_RAW.CAST_TO_VARCHAR2(globalid) as "globalTransactionId",
425+
UTL_RAW.CAST_TO_VARCHAR2(branchid) as "branchQualifier"
426+
FROM DBA_PENDING_TRANSACTIONS`;
427+
const sqlBuf = `
428+
SELECT
429+
formatid as "formatId",
430+
globalid as "globalTransactionId",
431+
branchid as "branchQualifier"
432+
FROM DBA_PENDING_TRANSACTIONS`;
433+
const options = {
434+
outFormat: this._oracledb.OUT_FORMAT_OBJECT,
435+
};
436+
437+
const result = await this._execute(asString ? sqlStr : sqlBuf, {}, options);
438+
return result.resultSet._getAllRows(options, result.metaData, false);
439+
}
440+
441+
442+
//-----------------------------------------------------------------------------
443+
// tpcRollback()
444+
// Rollbacks the current changes in two-phase-commit
445+
//-----------------------------------------------------------------------------
446+
async function tpcRollback(xid) {
447+
nodbUtil.checkArgCount(arguments, 0, 1);
448+
if (arguments.length == 1) {
449+
nodbUtil.assert(nodbUtil.isXid(xid), 'NJS-005', 1);
450+
}
451+
452+
await this._tpcRollback(xid);
453+
}
454+
455+
317456

318457
// define class
319458
class Connection extends EventEmitter {
@@ -344,6 +483,13 @@ class Connection extends EventEmitter {
344483
this.shutdown = nodbUtil.callbackify(nodbUtil.serialize(shutdown));
345484
this.startup = nodbUtil.callbackify(nodbUtil.serialize(startup));
346485
this.subscribe = nodbUtil.callbackify(nodbUtil.serialize(subscribe));
486+
this.tpcBegin = nodbUtil.callbackify(nodbUtil.serialize(tpcBegin));
487+
this.tpcCommit = nodbUtil.callbackify(nodbUtil.serialize(tpcCommit));
488+
this.tpcEnd = nodbUtil.callbackify(nodbUtil.serialize(tpcEnd));
489+
this.tpcForget = nodbUtil.callbackify(nodbUtil.serialize(tpcForget));
490+
this.tpcPrepare = nodbUtil.callbackify(nodbUtil.serialize(tpcPrepare));
491+
this.tpcRecover = nodbUtil.callbackify(nodbUtil.serialize(tpcRecover));
492+
this.tpcRollback = nodbUtil.callbackify(nodbUtil.serialize(tpcRollback));
347493
this.unsubscribe = nodbUtil.callbackify(nodbUtil.serialize(unsubscribe));
348494
}
349495

lib/oracledb.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const BaseDbObject = require('./dbObject.js');
4343
const Connection = require('./connection.js');
4444
const Lob = require('./lob.js');
4545
const Pool = require('./pool.js');
46+
const PoolStatistics = require('./poolStatistics.js');
4647
const ResultSet = require('./resultset.js');
4748
const SodaDatabase = require('./sodaDatabase.js');
4849
const SodaCollection = require('./sodaCollection.js');
@@ -99,11 +100,11 @@ class OracleDb {
99100
}
100101

101102
// 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);
107108
}
108109

109110
// temporary method for determining if an object is a date until
@@ -380,6 +381,7 @@ proto.BaseDbObject = BaseDbObject;
380381
proto.Connection = Connection;
381382
proto.Lob = Lob;
382383
proto.Pool = Pool;
384+
proto.PoolStatistics = PoolStatistics;
383385
proto.ResultSet = ResultSet;
384386
proto.SodaDatabase = SodaDatabase;
385387
proto.SodaCollection = SodaCollection;

lib/pool.js

Lines changed: 33 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
const EventEmitter = require('events');
2323
const nodbUtil = require('./util.js');
2424
const util = require('util');
25+
const PoolStatistics = require('./poolStatistics.js');
26+
2527

2628
//-----------------------------------------------------------------------------
2729
// _checkRequestQueue()
@@ -328,44 +330,7 @@ function logStatistics() {
328330
if (stats === null) {
329331
throw new Error(nodbUtil.getErrorMessage('NJS-083'));
330332
}
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();
369334
}
370335

371336

@@ -375,54 +340,12 @@ function logStatistics() {
375340
// properties
376341
//-----------------------------------------------------------------------------
377342
function getStatistics() {
378-
let averageTimeInQueue;
379-
let stats = { };
380-
381-
// if the pool is not OPEN, throw appropriate err
382343
this._checkPoolOpen(false);
383344

384345
if (this._enableStatistics !== true) {
385346
return null;
386347
}
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);
426349
}
427350

428351

@@ -467,6 +390,35 @@ function _setup(poolAttrs, poolAlias, oracledb) {
467390
this._sessionCallback = poolAttrs.sessionCallback;
468391
}
469392

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+
470422
// register event handler for when request queue should be checked
471423
this.on('_checkRequestQueue', this._checkRequestQueue);
472424

0 commit comments

Comments
 (0)