[关闭]
@WrRan 2016-11-17T08:55:02.000000Z 字数 3351 阅读 1352

node-oracledb

6. Pool Class

A connection Pool object is created by calling the
createPool() method of the Oracledb object.

The Pool object obtains connections to the Oracle database using the
getConnection() method to "check them out" from the pool. Internally
OCI Session Pooling
is used.

After the application finishes using a connection pool, it should
release all connections and terminate the connection pool by calling
the close() method on the Pool object.

See Connection Pooling for more information.

6.1 Pool Properties

The Pool object properties may be read to determine the current
values.

6.1.1 connectionsInUse

  1. readonly Number connectionsInUse

The number of currently active connections in the connection pool
i.e. the number of connections currently checked-out using
getConnection().

6.1.2 connectionsOpen

  1. readonly Number connectionsOpen

The number of currently open connections in the underlying connection
pool.

6.1.3 poolAlias

  1. readonly Number poolAlias

The alias of this pool in the connection pool cache. An alias cannot be changed once the pool has been created.

6.1.4 poolIncrement

  1. readonly Number poolIncrement

The number of connections that are opened whenever a connection
request exceeds the number of currently open connections.

6.1.5 poolMax

  1. readonly Number poolMax

The maximum number of connections that can be open in the connection
pool.

6.1.6 poolMin

  1. readonly Number poolMin

The minimum number of connections a connection pool maintains, even
when there is no activity to the target database.

6.1.7 poolTimeout

  1. readonly Number poolTimeout

The time (in seconds) after which the pool terminates idle connections
(unused in the pool). The number of connections does not drop below
poolMin.

6.1.8 queueRequests

  1. readonly Boolean queueRequests

Determines whether requests for connections from the pool are queued
when the number of connections "checked out" from the pool has reached
the maximum number specified by poolMax.

6.1.9 queueTimeout

  1. readonly Number queueTimeout

The time (in milliseconds) that a connection request should wait in
the queue before the request is terminated.

6.1.10 stmtCacheSize

  1. readonly Number stmtCacheSize

The number of statements to be cached in the
statement cache of each connection.

6.2 Pool Methods

6.2.1 close()

Prototype

Callback:

  1. close(function(Error error){});

Promise:

  1. promise = close();
Description

This call terminates the connection pool.

Any open connections should be released with connection.close()
before pool.close() is called.

If the pool is in the connection pool cache it will be removed from the cache.

Parameters
  1. function(Error error)

The parameters of the callback function are:

Callback function parameter Description
Error error If close() succeeds, error is NULL. If an error occurs, then error contains the error message.

6.2.2 getConnection()

Prototype

Callback:

  1. getConnection(function(Error error, Connection conn){});

Promise:

  1. promise = getConnection();
Description

This method obtains a connection from the connection pool.

If a previously opened connection is available in the pool, that
connection is returned. If all connections in the pool are in use, a
new connection is created and returned to the caller, as long as the
number of connections does not exceed the specified maximum for the
pool. If the pool is at its maximum limit, the getConnection() call
results in an error, such as ORA-24418: Cannot open further sessions.

See Connection Handling for more information on
connections.

Parameters
  1. function(Error error, Connection conn)

The parameters of the callback function are:

Callback function parameter Description
Error error If getConnection() succeeds, error is NULL. If an error occurs, then error contains the error message.
Connection connection The newly created connection. If getConnection() fails, connection will be NULL. See Connection class for more details.

6.2.3 terminate()

An alias for pool.close().

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注