Database Reference
In-Depth Information
Configure the Pool
The first step we must take is to establish the connection pool through an OracleOCIConnectionPool
class. We set the URL (connection string), user, and password ( appusrConnURL , appusrConnUser ,
appusrConnPassword ) that all connections in the pool will have, as shown in Listing 8-11. They will all
connect as appusr .
Be sure to edit the code in OraSSOTests.java to correctly identify your host, port, instance and
network domain (in SERVICE_NAME ). Notice that the connection URL is specified as “jdbc:oracle:oci:”.
That is the designation of a heavyweight, OCI connection type. The connection string is specified in
TNSNames (transparent network substrate) format, appusrConnOCIURL .
Listing 8-11. Configure OCI Connection Pool
private String appusrConnOCIURL =
"jdbc:oracle: oci :@(description=(address=(host=" +
"127.0.0.1)(protocol=tcp)(port=1521))(connect_data=" +
"(INSTANCE_NAME=orcl)(SERVICE_NAME=orcl)))";
// Or
//"(INSTANCE_NAME=orcl)(SERVICE_NAME=orcl.org.com)))";
private String appusrConnUser = "appusr";
private String appusrConnPassword = "password";
OracleOCIConnectionPool cpool = new OracleOCIConnectionPool();
cpool.setURL(appusrConnOCIURL);
cpool.setUser(appusrConnUser);
cpool.setPassword(appusrConnPassword);
Properties prop = new Properties();
prop.put (OracleOCIConnectionPool.CONNPOOL_MIN_LIMIT, "2");
prop.put (OracleOCIConnectionPool.CONNPOOL_MAX_LIMIT, "10");
prop.put (OracleOCIConnectionPool.CONNPOOL_INCREMENT, "1");
cpool. setPoolConfig (prop);
Next, we configure the connection pool by building a Properties object with the basic parameters:
the minimum pool size (also initial size), maximum pool size, and growth increment. We pass the
Properties to our connection pool through the setPoolConfig() method. Note that these properties
apply to the pool itself, not to any specific connection.
Get the Proxy Connection
We add one more parameter to the existing (for convenience) Properties object—the PROXY_USER_NAME .
When we get a connection from the pool, we specifically want a proxy connection. All connections in the
pool connect as appusr , but each proxy connection coming from the pool can be associated with a
different user connecting through appusr . We set the PROXY_USER_NAME for this connection to userName ,
the OS user identity that we got from NTSystem or UnixSystem . When we request a proxy connection from
the cpool.getProxyConnection() method, Listing 8-12, we pass the Properties with the PROXY_USER_NAME
in our request.
 
Search WWH ::




Custom Search