Class: OCI8::ConnectionPool
- Defined in:
- lib/oci8/connection_pool.rb,
ext/oci8/connection_pool.c
Overview
Connection pooling is the use of a group (the pool) of reusable physical connections by several sessions to balance loads. See: Oracle Call Interface Manual
This is equivalent to Oracle JDBC Driver OCI Connection Pooling.
Usage:
# Create a connection pool.
# username and password are required to establish an implicit primary session.
cpool = OCI8::ConnectionPool.new(1, 5, 2, username, password, database)
# Get a session from the pool.
# Pass the connection pool to the third argument.
conn1 = OCI8.new(username, password, cpool)
# Get another session.
conn2 = OCI8.new(username, password, cpool)
Instance Method Summary collapse
-
#busy_count ⇒ Object
call-seq: busy_count -> integer.
- #destroy ⇒ Object
-
#incr ⇒ Object
call-seq: incr -> integer.
-
#max ⇒ Object
call-seq: max -> integer.
-
#min ⇒ Object
call-seq: min -> integer.
-
#nowait=(val) ⇒ Object
call-seq: nowait = true or false.
-
#nowait? ⇒ Boolean
call-seq: nowait? -> true or false.
-
#open_count ⇒ Object
call-seq: open_count -> integer.
-
#reinitialize(min, max, incr) ⇒ Object
Changes the the number of minimum connections, the number of maximum connections and the connection increment parameter.
-
#timeout ⇒ Object
call-seq: timeout -> integer.
-
#timeout=(val) ⇒ Object
call-seq: timeout = integer.
Instance Method Details
#busy_count ⇒ Object
call-seq:
busy_count -> integer
Returns the number of busy physical connections.
78 79 80 |
# File 'lib/oci8/connection_pool.rb', line 78 def busy_count attr_get_ub4(OCI_ATTR_CONN_BUSY_COUNT) end |
#destroy ⇒ Object
115 116 117 |
# File 'lib/oci8/connection_pool.rb', line 115 def destroy free end |
#incr ⇒ Object
call-seq:
incr -> integer
Returns the connection increment parameter.
110 111 112 |
# File 'lib/oci8/connection_pool.rb', line 110 def incr attr_get_ub4(OCI_ATTR_CONN_INCR) end |
#max ⇒ Object
call-seq:
max -> integer
Returns the number of maximum physical connections.
102 103 104 |
# File 'lib/oci8/connection_pool.rb', line 102 def max attr_get_ub4(OCI_ATTR_CONN_MAX) end |
#min ⇒ Object
call-seq:
min -> integer
Returns the number of minimum physical connections.
94 95 96 |
# File 'lib/oci8/connection_pool.rb', line 94 def min attr_get_ub4(OCI_ATTR_CONN_MIN) end |
#nowait=(val) ⇒ Object
call-seq:
nowait = true or false
Changes the behavior when all the connections in the pool are busy and the number of connections has already reached the maximum.
70 71 72 |
# File 'lib/oci8/connection_pool.rb', line 70 def nowait=(val) attr_set_ub1(OCI_ATTR_CONN_NOWAIT, val ? 1 : 0) end |
#nowait? ⇒ Boolean
call-seq:
nowait? -> true or false
If true, an error is thrown when all the connections in the pool are busy and the number of connections has already reached the maximum. Otherwise the call waits till it gets a connection. The default value is false.
60 61 62 |
# File 'lib/oci8/connection_pool.rb', line 60 def nowait? attr_get_ub1(OCI_ATTR_CONN_NOWAIT) != 0 end |
#open_count ⇒ Object
call-seq:
open_count -> integer
Returns the number of open physical connections.
86 87 88 |
# File 'lib/oci8/connection_pool.rb', line 86 def open_count attr_get_ub4(OCI_ATTR_CONN_OPEN_COUNT) end |
#reinitialize(min, max, incr) ⇒ Object
Changes the the number of minimum connections, the number of maximum connections and the connection increment parameter.
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'ext/oci8/connection_pool.c', line 153
static VALUE oci8_cpool_reinitialize(VALUE self, VALUE conn_min, VALUE conn_max, VALUE conn_incr)
{
oci8_cpool_t *cpool = DATA_PTR(self);
OraText *pool_name;
sb4 pool_name_len;
/* check arguments */
Check_Type(conn_min, T_FIXNUM);
Check_Type(conn_max, T_FIXNUM);
Check_Type(conn_incr, T_FIXNUM);
chker2(OCIConnectionPoolCreate(oci8_envhp, oci8_errhp, cpool->base.hp.poolhp,
&pool_name, &pool_name_len, NULL, 0,
FIX2UINT(conn_min), FIX2UINT(conn_max),
FIX2UINT(conn_incr),
NULL, 0, NULL, 0, OCI_CPOOL_REINITIALIZE),
&cpool->base);
return self;
}
|
#timeout ⇒ Object
call-seq:
timeout -> integer
Connections idle for more than this time value (in seconds) are terminated, to maintain an optimum number of open connections. If it is zero, the connections are never timed out. The default value is zero.
Note: Shrinkage of the pool only occurs when there is a network round trip. If there are no operations, then the connections stay alive.
41 42 43 |
# File 'lib/oci8/connection_pool.rb', line 41 def timeout attr_get_ub4(OCI_ATTR_CONN_TIMEOUT) end |
#timeout=(val) ⇒ Object
call-seq:
timeout = integer
Changes the timeout in seconds to terminate idle connections.
49 50 51 |
# File 'lib/oci8/connection_pool.rb', line 49 def timeout=(val) attr_set_ub4(OCI_ATTR_CONN_TIMEOUT, val) end |