Database Reference
In-Depth Information
Listing 8-22.
Add Proxy Features to Existing Connection, setProxyConnection()
OracleJavaSecure.setProxyConnection( conn );
The results will be the sameāthe original
OracleConnection
,
conn
now has the proxy features.
If we were passing the URL only, we would call this method, which returns an
OracleConnection
with proxy session and client identifier:
OracleConnection conn = OracleJavaSecure.setConnection( urlString );
Close the Proxy Connection
We want to allow for the possibility that these connections may come from a connection pool, and we
want to be sure to close the proxy session in that case, so we will instruct the developers to call a method
to close the connection, like this:
OracleJavaSecure.closeConnection();
Updates to OracleJavaSecure
The generic
Connection
class does not support proxy connections nor setting the client identifier. We
will be using instances of
OracleConnection
from here out. Our static class member,
conn
is now an
OracleConnection
, see Listing 8-23. Also our static initializer for
conn
casts the
Connection
as an
OracleConnection
.
Listing 8-23.
OracleJavaSecure Static OracleConnection
private static OracleConnection conn;
static {
try {
// The following throws an exception when not running within an Oracle Database
conn = (
OracleConnection
)(new OracleDriver().defaultConnection());
} catch( Exception x ) {}
}
Update setConnection() Method
We are going to overload the
setConnection()
method (see Listing 8-24), retaining one that takes a
Connection
parameter and adding one that takes an
OracleConnection
. The first will call the second so
that both configure a proxy connection with the client identifier set. The OS user identity from
NTSystem
or
UnixSystem
is used for proxying and in the client identifier:
Listing 8-24.
Set Internal Connection in OracleJavaSecure and Configure, setConnection()
public static final OracleConnection
setConnection
(
Connection
c ) {
return
setConnection
( (OracleConnection)c );
}
public static final OracleConnection
setConnection
(
OracleConnection
c ) {