soap tutorial

adriani.jws.template.db
Class JDBCConnectionPool

java.lang.Object
  extended by adriani.jws.template.db.ObjectPool
      extended by adriani.jws.template.db.JDBCConnectionPool
Direct Known Subclasses:
MockConnectionPool

public class JDBCConnectionPool
extends ObjectPool

JDBC oriented implementation of the ObjectPool general pool parent class.
Before ending or closing the application using the pool, the user should call the shutdown() method to properly terminate the cleaner thread.

See Also:
ObjectPool

Field Summary
protected  java.lang.String alias
          DB tns alias, defined in the tnsnames.ora file (if available).
protected  java.lang.String con
          Connect string, equal to the return value of DatabaseMetaData.getURL()
protected  java.lang.String pwd
          DB user password
protected  boolean supportTns
          If true this class can obtain SQL connection using the tnsnames.ora file.
protected  java.lang.String usr
          DB user name
 
Fields inherited from class adriani.jws.template.db.ObjectPool
expirationTime, leadingName, logger, maximum
 
Constructor Summary
JDBCConnectionPool(java.lang.String con, java.lang.String usr, java.lang.String pwd, int expirationTime)
          Use this constructor if another JDBCConnectionPool has already registered the JDBC driver for the same type of database related to this connection pool.
JDBCConnectionPool(java.lang.String driver, java.lang.String con, java.lang.String usr, java.lang.String pwd, int expirationTime)
          Standard constructor, to be used to register the JDBC drivers (only the first time).
 
Method Summary
 java.lang.Object create()
          Users should not call this method directly.
 void expire(java.lang.Object object)
          Method invoked by the parent class in two different situations: when the object is found invalid (during a check out operation) or when the Cleaner Thread discards the object (timeout).
 java.sql.Connection getConnection()
          Users should call this method each time a connection is needed.
protected  java.lang.String getDatabaseName(java.lang.String tns)
          Split the full tns string and return only the last token, describing the database name.
 java.lang.String getTNSEntryName()
          Accessor method.
 boolean logConnection(java.sql.Connection connection)
          WORK IN PROGRESS: NOT USED AT THE MOMENT
 void returnConnection(java.sql.Connection connection)
          Users should call this method each time a connection is not needed anymore.
 void setTNSEntryName(java.lang.String value)
          Mutator method.
 boolean setTnsName(java.lang.String tnsAlias)
          Set the tns alias for the target database, as defined in the tnsnames.ora oracle file.
 void shutdown()
          This method just terminates the cleaner thread.
 boolean supportTnsNames()
          Accessor method.
 boolean validate(java.lang.Object object)
          Method used by the checkOut() method of the parent class before checking out an object from the unlocked pool.
 
Methods inherited from class adriani.jws.template.db.ObjectPool
checkIn, checkOut, cleanUp, finalize, getPoolData, getPoolSize, printObject, setPoolSize
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

con

protected java.lang.String con
Connect string, equal to the return value of DatabaseMetaData.getURL()


usr

protected java.lang.String usr
DB user name


pwd

protected java.lang.String pwd
DB user password


alias

protected java.lang.String alias
DB tns alias, defined in the tnsnames.ora file (if available).


supportTns

protected boolean supportTns
If true this class can obtain SQL connection using the tnsnames.ora file.

Constructor Detail

JDBCConnectionPool

public JDBCConnectionPool(java.lang.String con,
                          java.lang.String usr,
                          java.lang.String pwd,
                          int expirationTime)
Use this constructor if another JDBCConnectionPool has already registered the JDBC driver for the same type of database related to this connection pool.

Remark: subclasses should override the method getDatabaseName() to ensure proper logging leading messages.

Parameters:
con - the connection string of the db, e.g. jdbc:oracle:thin:@192.168.1.10:1533:mydb
usr - the user name for the connection
pwd - the password for the connection
expirationTime - sleep time of the Cleaner Thread in seconds

JDBCConnectionPool

public JDBCConnectionPool(java.lang.String driver,
                          java.lang.String con,
                          java.lang.String usr,
                          java.lang.String pwd,
                          int expirationTime)
Standard constructor, to be used to register the JDBC drivers (only the first time).

Parameters:
driver - the JDBC driver, e.g. oracle.jdbc.driver.OracleDriver
con - the connection string of the db, e.g. jdbc:oracle:thin:@192.168.1.10:1533:mydb
usr - the user name for the connection
pwd - the password for the connection
expirationTime - sleep time of the Cleaner Thread in seconds
Method Detail

setTnsName

public boolean setTnsName(java.lang.String tnsAlias)
Set the tns alias for the target database, as defined in the tnsnames.ora oracle file. This method can be used only with the Oracle database and a JDBC driver 10.2 or higher. The tnsnames files should be configured in a path like the following:

C:\\Oracle\\product\\10.1.0\\Client\\NETWORK\\ADMIN

This approach allow to get a JDBC connection using only the logical name of the datasource, which must match one of the entries defined in the tnsnames.ora oracle file. For this reason, the Database class takes care to set the proper oracle.net.tns_admin variable.

Parameters:
tnsAlias - the tns alias of the datasource, for example @mydatabase
Returns:
true if this feature is supported

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
Users should call this method each time a connection is needed. The method relies on the mechanism written in the parent ObjectPool class for checking out a valid object from the pool. If the super method throws an exception, this is caught, casted into a SQLException type and re-throw.

This approach should preserve all the information stored in the original general exception, hence, if the upper layers gets an "empty exception" (i.e. without a stack trace) probably there is something wrong in the object itself (in this case the Oracle connection).

Returns:
a connection obtained from the super.checkOut() method
Throws:
java.sql.SQLException

returnConnection

public void returnConnection(java.sql.Connection connection)
Users should call this method each time a connection is not needed anymore. This method forwards action to the parent super.checkIn() method.

Parameters:
connection - the connection to be returned in the unlocked hashtable

shutdown

public void shutdown()
This method just terminates the cleaner thread.

Overrides:
shutdown in class ObjectPool
See Also:
CleanUpThread

create

public java.lang.Object create()
                        throws java.sql.SQLException
Users should not call this method directly. It's the checkOut() method of the parent class that will invoke this method ONLY IF there isn't any unlocked object in the pool, in order to create a new one. Notice that this is the only code-block creating the objects managed by this pool class (in this case a Connection object).

Specified by:
create in class ObjectPool
Returns:
an object representing a brand new connection in the pool
Throws:
java.sql.SQLException

validate

public boolean validate(java.lang.Object object)
Method used by the checkOut() method of the parent class before checking out an object from the unlocked pool.

Specified by:
validate in class ObjectPool
Parameters:
object - the connection to be validated

expire

public void expire(java.lang.Object object)
Method invoked by the parent class in two different situations: when the object is found invalid (during a check out operation) or when the Cleaner Thread discards the object (timeout).

Specified by:
expire in class ObjectPool
Parameters:
object - the connection to be destroyed

setTNSEntryName

public void setTNSEntryName(java.lang.String value)
Mutator method.


getTNSEntryName

public java.lang.String getTNSEntryName()
Accessor method.


supportTnsNames

public boolean supportTnsNames()
Accessor method.


getDatabaseName

protected java.lang.String getDatabaseName(java.lang.String tns)
Split the full tns string and return only the last token, describing the database name. This method is used only to obtain a user-friendly name for logging messages.

Parameters:
tns - the tns string of the db, e.g. jdbc:oracle:thin:@192.168.3.12:1588:vardati
Returns:
the last part of the database name, e.g. vartdati

logConnection

public boolean logConnection(java.sql.Connection connection)
WORK IN PROGRESS: NOT USED AT THE MOMENT


Build 19/03/2014

Morpheus Technologies - making the Zion software
Copyright © 2009-2014 Morpheus Technologies. All Rights Reserved