Skip to content

Commit 2ab23e2

Browse files
committed
Added JavaScript wrapper around C++ classes. Added connection pool queue
1 parent af9cb2a commit 2ab23e2

13 files changed

+1602
-160
lines changed

doc/api.md

+173-39
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ limitations under the License.
4949
- 3.2.11 [poolMin](#propdbpoolmin)
5050
- 3.2.12 [poolTimeout](#propdbpooltimeout)
5151
- 3.2.13 [prefetchRows](#propdbprefetchrows)
52-
- 3.2.14 [stmtCacheSize](#propdbstmtcachesize)
53-
- 3.2.15 [version](#propdbversion)
52+
- 3.2.14 [queueRequests](#propdbqueuerequests)
53+
- 3.2.15 [queueTimeout](#propdbqueuetimeout)
54+
- 3.2.16 [stmtCacheSize](#propdbstmtcachesize)
55+
- 3.2.17 [version](#propdbversion)
5456
- 3.3 [Oracledb Methods](#oracledbmethods)
5557
- 3.3.1 [createPool()](#createpool)
5658
- 3.3.2 [getConnection()](#getconnectiondb)
@@ -85,7 +87,9 @@ limitations under the License.
8587
- 6.1.4 [poolMax](#proppoolpoolmax)
8688
- 6.1.5 [poolMin](#proppoolpoolmin)
8789
- 6.1.6 [poolTimeout](#proppoolpooltimeout)
88-
- 6.1.7 [stmtCacheSize](#proppoolstmtcachesize)
90+
- 6.1.7 [queueRequests](#proppoolqueuerequests)
91+
- 6.1.8 [queueTimeout](#proppoolqueueTimeout)
92+
- 6.1.9 [stmtCacheSize](#proppoolstmtcachesize)
8993
- 6.2 [Pool Methods](#poolmethods)
9094
- 6.2.1 [getConnection()](#getconnectionpool)
9195
- 6.2.2 [terminate()](#terminate)
@@ -102,6 +106,7 @@ limitations under the License.
102106
- 8.1.2 [Net Service Names for Connection Strings](#tnsnames)
103107
- 8.1.3 [JDBC and Node-oracledb Connection Strings Compared](#notjdbc)
104108
- 8.2 [Connection Pooling](#connpooling)
109+
- 8.2.1 [Connection Pool Monitoring](#connpoolmonitor)
105110
- 8.3 [Database Resident Connection Pooling (DRCP)](#drcp)
106111
- 8.4 [External Authentication](#extauth)
107112
9. [SQL Execution](#sqlexecution)
@@ -564,7 +569,7 @@ request exceeds the number of currently open connections.
564569

565570
The default value is 1.
566571

567-
This property may be overridden when creating a connection pool.
572+
This property may be overridden when [creating a connection pool](#createpool).
568573

569574
##### Example
570575

@@ -583,7 +588,7 @@ The maximum number of connections to which a connection pool can grow.
583588

584589
The default value is 4.
585590

586-
This property may be overridden when creating the connection pool.
591+
This property may be overridden when [creating a connection pool](#createpool).
587592

588593
##### Example
589594

@@ -603,7 +608,7 @@ when there is no activity to the target database.
603608

604609
The default value is 0.
605610

606-
This property may be overridden when creating a connection pool.
611+
This property may be overridden when [creating a connection pool](#createpool).
607612

608613
##### Example
609614

@@ -625,7 +630,7 @@ connections are never terminated.
625630

626631
The default value is 60.
627632

628-
This property may be overridden when creating a connection pool.
633+
This property may be overridden when [creating a connection pool](#createpool).
629634

630635
##### Example
631636

@@ -664,7 +669,55 @@ var oracledb = require('oracledb');
664669
oracledb.prefetchRows = 100;
665670
```
666671

667-
#### <a name="propdbstmtcachesize"></a> 3.2.14 stmtCacheSize
672+
#### <a name="propdbqueuerequests"></a> 3.2.14 queueRequests
673+
674+
```
675+
Boolean queueRequests
676+
```
677+
678+
If this property is *true* and the number of connections "checked out"
679+
from the pool has reached the number specified by
680+
[`poolMax`](#propdbpoolmax), then new requests for connections are
681+
queued until in-use connections are released.
682+
683+
If this property is *false* and a request for a connection is made
684+
from a pool where the number of "checked out" connections has reached
685+
`poolMax`, then an *ORA-24418* error indicating that further sessions
686+
cannot be opened will be returned.
687+
688+
The default value is *true*.
689+
690+
This property may be overridden when [creating a connection pool](#createpool).
691+
692+
##### Example
693+
694+
```javascript
695+
var oracledb = require('oracledb');
696+
oracledb.queueRequests = false;
697+
```
698+
699+
#### <a name="propdbqueuetimeout"></a> 3.2.15 queueTimeout
700+
701+
```
702+
Number queueTimeout
703+
```
704+
705+
The number of milliseconds after which connection requests waiting in
706+
the connection request queue are terminated. If `queueTimeout` is
707+
0, then queued connection requests are never terminated.
708+
709+
The default value is 60000.
710+
711+
This property may be overridden when [creating a connection pool](#createpool).
712+
713+
##### Example
714+
715+
```javascript
716+
var oracledb = require('oracledb');
717+
oracledb.queueTimeout = 3000; // 3 seconds
718+
```
719+
720+
#### <a name="propdbstmtcachesize"></a> 3.2.16 stmtCacheSize
668721

669722
```
670723
Number stmtCacheSize
@@ -691,7 +744,7 @@ var oracledb = require('oracledb');
691744
oracledb.stmtCacheSize = 30;
692745
```
693746

694-
#### <a name="propdbversion"></a> 3.2.15 version
747+
#### <a name="propdbversion"></a> 3.2.17 version
695748
```
696749
readonly Number version
697750
```
@@ -783,10 +836,10 @@ name of a local Oracle database instance. See
783836
Boolean externalAuth
784837
```
785838

786-
If this optional property is *true* then the pool's connections will
787-
be established using [External Authentication](#extauth).
839+
Indicate whether to connections should be established using
840+
[External Authentication](#extauth).
788841

789-
This property overrides the *Oracledb*
842+
This optional property overrides the *Oracledb*
790843
[`externalAuth`](#propdbisexternalauth) property.
791844

792845
The `user` and `password` properties should not be set when
@@ -800,49 +853,72 @@ Number stmtCacheSize
800853
```
801854

802855
The number of statements to be cached in the
803-
[statement cache](#stmtcache) of each connection. This optional
804-
property may be used to override the
805-
[stmtCacheSize](#propdbstmtcachesize) property of the *Oracledb*
806-
object.
856+
[statement cache](#stmtcache) of each connection.
857+
858+
This optional property overrides the *Oracledb*
859+
[`stmtCacheSize`](#propdbstmtcachesize) property.
807860

808861
```
809862
Number poolMax
810863
```
811864

812865
The maximum number of connections to which a connection pool can grow.
813866

814-
This optional property may be used to override the corresponding
815-
property in the *Oracledb* object.
867+
This optional property overrides the *Oracledb*
868+
[`poolMax`](#propdbpoolmax) property.
816869

817870
```
818871
Number poolMin
819872
```
820873

821874
The minimum number of connections a connection pool maintains, even
822-
when there is no activity to the target database. This optional
823-
property may be used to override the corresponding property in the
824-
*Oracledb* object.
875+
when there is no activity to the target database.
876+
877+
This optional property overrides the *Oracledb*
878+
[`poolMin`](#propdbpoolmin) property.
825879

826880
```
827881
Number poolIncrement
828882
```
829883

830884
The number of connections that are opened whenever a connection
831-
request exceeds the number of currently open connections. This
832-
optional property may be used to override the corresponding property
833-
in the *Oracledb* object.
885+
request exceeds the number of currently open connections.
886+
887+
This optional property overrides the *Oracledb*
888+
[`poolIncrement`](#propdbpoolincrement) property.
834889

835890
```
836891
Number poolTimeout
837892
```
838893

839894
The number of seconds after which idle connections (unused in the
840895
pool) may be terminated. Idle connections are terminated only when
841-
the pool is accessed. If the `poolTimeout` is set to 0, then idle
896+
the pool is accessed. If `poolTimeout` is set to 0, then idle
842897
connections are never terminated.
843898

844-
This optional property may be used to override the corresponding
845-
property in the *Oracledb* object.
899+
This optional property overrides the *Oracledb*
900+
[`poolTimeout`](#propdbpooltimeout) property.
901+
902+
```
903+
Boolean queueRequests
904+
```
905+
906+
Indicate whether [`pool.getConnection()`](#getconnectionpool) calls
907+
should be queued when all available connections are in currently use.
908+
909+
This optional property overrides the *Oracledb*
910+
[`queueRequests`](#propdbqueuerequests) property.
911+
912+
```
913+
Number queueTimeout
914+
```
915+
916+
The number of milliseconds after which connection requests waiting in the
917+
connection request queue are terminated. If `queueTimeout` is
918+
set to 0, then queued connection requests are never terminated.
919+
920+
This optional property overrides the *Oracledb*
921+
[`queueTimeout`](#propdbqueuetimeout) property.
846922

847923
```
848924
function(Error error, Pool pool)
@@ -1533,10 +1609,29 @@ readonly Number poolTimeout
15331609
```
15341610

15351611
The time (in seconds) after which the pool terminates idle connections
1536-
(unused in the pool). The number of connection does not drop below
1612+
(unused in the pool). The number of connections does not drop below
15371613
poolMin.
15381614

1539-
#### <a name="proppoolstmtcachesize"></a> 6.1.7 stmtCacheSize
1615+
#### <a name="proppoolqueuerequests"></a> 6.1.7 queueRequests
1616+
1617+
```
1618+
readonly Boolean queueRequests
1619+
```
1620+
1621+
Determines whether requests for connections from the pool are queued
1622+
when the number of connections "checked out" from the pool has reached
1623+
the maximum number specified by [`poolMax`](#propdbpoolmax).
1624+
1625+
#### <a name="proppoolqueueTimeout"></a> 6.1.8 queueTimeout
1626+
1627+
```
1628+
readonly Number queueTimeout
1629+
```
1630+
1631+
The time (in milliseconds) that a connection request should wait in
1632+
the queue before the request is terminated.
1633+
1634+
#### <a name="proppoolstmtcachesize"></a> 6.1.9 stmtCacheSize
15401635

15411636
```
15421637
readonly Number stmtCacheSize
@@ -1545,9 +1640,6 @@ readonly Number stmtCacheSize
15451640
The number of statements to be cached in the
15461641
[statement cache](#stmtcache) of each connection.
15471642

1548-
The default is the [`stmtCacheSize`](#propdbstmtcachesize) property of
1549-
the *Oracledb* object when the pool is created.
1550-
15511643
### <a name="poolmethods"></a> 6.2 Pool Methods
15521644

15531645
#### <a name="getconnectionpool"></a> 6.2.1 getConnection()
@@ -1911,7 +2003,7 @@ object. Internally
19112003
[OCI Session Pooling](https://docs.oracle.com/database/121/LNOCI/oci09adv.htm#LNOCI16617)
19122004
is used.
19132005
1914-
Connection are returned with the *Pool*
2006+
A connection is returned with the *Pool*
19152007
[`getConnection()`](#getconnectionpool) function:
19162008
19172009
```javascript
@@ -1959,9 +2051,51 @@ The Pool attribute [`stmtCacheSize`](#propconnstmtcachesize) can be
19592051
used to set the statement cache size used by connections in the pool,
19602052
see [Statement Caching](#stmtcache).
19612053
1962-
A pool can be monitored by looking at the Pool attributes
1963-
[`connectionsInUse`](#proppoolconnectionsinuse) and
1964-
[`connectionsOpen`](#proppoolconnectionsopen).
2054+
#### <a name="connpoolmonitor"></a> 8.2.1 Connection Pool Monitoring
2055+
2056+
Connection pool usage can be monitored to choose the appropriate
2057+
connection pool settings for your workload.
2058+
2059+
The Pool attributes [`connectionsInUse`](#proppoolconnectionsinuse)
2060+
and [`connectionsOpen`](#proppoolconnectionsopen) provide basic
2061+
information about an active pool.
2062+
2063+
When using a [pool queue](#propdbqueuerequests), further statistics
2064+
can be enabled by setting the [`createPool()`](#createpool)
2065+
`poolAttrs` parameter `_enableStats` to *true*. Statistics
2066+
can be output to the console by calling the *Pool* `_logStats()`
2067+
method. The underscore prefixes indicate that these are private
2068+
attributes and methods. As such, this functionality may be altered or
2069+
enhanced in the future.
2070+
2071+
Queue statistics include the number of `getConnection()` requests that
2072+
were queued waiting for an available connection. The sum and average
2073+
time spent in the queue are also recorded. If the pool queue is
2074+
heavily used, consider increasing the connection pool
2075+
[`poolMax`](#proppoolpoolmax) value.
2076+
2077+
To enable recording of queue statistics:
2078+
2079+
```javascript
2080+
oracledb.createPool (
2081+
{
2082+
queueRequests : true, // default is true
2083+
_enableStats : true, // default is false
2084+
user : "hr",
2085+
password : "welcome",
2086+
connectString : "localhost/XE"
2087+
},
2088+
function(err, pool)
2089+
{
2090+
. . .
2091+
```
2092+
2093+
The application can later, on some developer-chosen event, display the
2094+
current statistics to the console by calling:
2095+
2096+
```javascript
2097+
pool._logStats();
2098+
```
19652099
19662100
Node worker threads executing database statements on a connection will
19672101
commonly wait for round-trips between node-oracledb and the database
@@ -2038,7 +2172,7 @@ to validate user access. One of the benefits is that database
20382172
credentials do not need to be hard coded in the application.
20392173
20402174
To use external authentication, set the *Oracledb*
2041-
[`externalAuth`](propdbextauth) property to *true*. This property can
2175+
[`externalAuth`](#propdbisexternalauth) property to *true*. This property can
20422176
also be set in the `connAttrs` or `poolAttrs` parameters of the
20432177
*Oracledb* [`getConnection()`](#getconnectiondb) or
20442178
[`createPool()`](#createpool) calls, respectively. The `user` and
@@ -2118,7 +2252,7 @@ less overhead.
21182252
21192253
A result set is created when the `execute()` option property
21202254
[`resultSet`](#executeoptions) is `true`. Result set rows can be
2121-
fetched using [`getRow()`](#getrow) or [`getRows()`](getrows) on the
2255+
fetched using [`getRow()`](#getrow) or [`getRows()`](#getrows) on the
21222256
`execute()` callback function's `result.resultSet` parameter property.
21232257
21242258
For result sets the [`maxRows`](#propdbmaxrows) limit is ignored. All
@@ -3154,7 +3288,7 @@ If the `WHERE` clause matches no rows, the output would be:
31543288
Oracle REF CURSORS can be fetched in node-oracledb by binding a
31553289
`CURSOR` to a PL/SQL call. The resulting bind variable becomes a
31563290
[`ResultSet`](#resultsetclass), allowing rows to be fetched using
3157-
[`getRow()`](#getrow) or [`getRows()`](getrows). When all rows have
3291+
[`getRow()`](#getrow) or [`getRows()`](#getrows). When all rows have
31583292
been fetched, or the application does not want to continue getting
31593293
more rows, then the result set must be freed using
31603294
[`close()`](#close). If the REF cursor is not set to any value, or is

index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = require('./lib/oracledb');
1+
module.exports = require('./lib/oracledb.js');

0 commit comments

Comments
 (0)