Database Reference
In-Depth Information
elsewhere, we need to get it in shape (validate and format it) before use. We trim the white space at the
head and tail of each argument and uppercase the concatenated key.
With that key in hand, we are ready to get the required connection string from connsHash , but recall
that the strings are encrypted. So we set appAuthCipherDES to decrypt mode using the shared secret
password key.
We then stack several calls together. We get the encrypted connection string from connsHash based
on our key. Then we get the byte array and pass it to the Cipher for decryption. We create a new String
based on the decrypted bytes, and pass the clear-text connection string to the setConnection() method,
which returns an OracleConnection .
By stacking our method calls in this way, we do not need to identify method member variables for
each step along the way. In this case, we could have an additional RAW , two byte arrays, and a String
member variable.
Get List of Connection Strings from Oracle Database to Client App
Although we may instruct the developers to call the getAppAuthConn() method, the getAppConnections()
method gets called behind the scene. Behind the scenes, we get the list of connection strings from the
Oracle database, then the application calls getAppAuthConn() to get individual Oracle connections based
on those strings. OracleJavaSecure does all the heavy lifting, decrypting the string and making the
connection to Oracle, before handing the connection to the application (Listings 10-40 through 10-44).
Start Our Method to Get Connection Strings from Oracle
Here again, we are in control of a procedure that the Java compiler warns us is unchecked and /or
unsafe. We cast the object we get from Oracle database as the connsHash HashMap without checking that it
fits the bill—if we were wrong, a ClassCastException would be thrown. Because we control both the
source and the receipt of this object, we are justified in ignoring that warning. We could use the
SuppressWarnings() annotation (see comment in Listing 10-40) to keep the compiler from complaining,
but the Oracle JVM compiler does not accept that, so we will live with the compile-time warning.
Listing 10-40. Get Connection Strings from Oracle, getAppConnections()
//@SuppressWarnings( "unchecked" )
public static void getAppConnections() {
OracleCallableStatement stmt = null;
try {
if( null == appVerConn ) setAppVerConnection() ;
Before we go any further, we check to see if we've got a connection to appver , calling
setAppVerConnection() to create one if needed.
Call Stored Procedure to Get Application List of Connection Strings
Our call from getAppConnections() to p_get_app_conns is easily one of the most complex Oracle stored
procedure calls we make, but only because of the variety and scope of data we are exchanging. There is
really nothing new here in Listing 10-41. There are a dozen arguments to the procedure: five IN and
seven OUT . But two of those OUT arguments are for error handling.
One of the IN parameters is a byte array representing the application ID class. We get this byte array
through two Streams classes, as we have seen before in this chapter. The other IN parameters are the
 
Search WWH ::




Custom Search