|
soap tutorial | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectadriani.jws.template.db.ObjectPool
adriani.jws.template.db.JDBCConnectionPool
public class JDBCConnectionPool
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.
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 |
---|
protected java.lang.String con
DatabaseMetaData.getURL()
protected java.lang.String usr
protected java.lang.String pwd
protected java.lang.String alias
tnsnames.ora
file (if available).
protected boolean supportTns
true
this class can obtain SQL connection using the tnsnames.ora
file.
Constructor Detail |
---|
public JDBCConnectionPool(java.lang.String con, java.lang.String usr, java.lang.String pwd, int expirationTime)
JDBCConnectionPool
has already registered the JDBC
driver for the same type of database related to this connection pool.getDatabaseName()
to
ensure proper logging leading messages.
con
- the connection string of the db, e.g. jdbc:oracle:thin:@192.168.1.10:1533:mydbusr
- the user name for the connectionpwd
- the password for the connectionexpirationTime
- sleep time of the Cleaner Thread in secondspublic JDBCConnectionPool(java.lang.String driver, java.lang.String con, java.lang.String usr, java.lang.String pwd, int expirationTime)
driver
- the JDBC driver, e.g. oracle.jdbc.driver.OracleDrivercon
- the connection string of the db, e.g. jdbc:oracle:thin:@192.168.1.10:1533:mydbusr
- the user name for the connectionpwd
- the password for the connectionexpirationTime
- sleep time of the Cleaner Thread in secondsMethod Detail |
---|
public boolean setTnsName(java.lang.String tnsAlias)
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
tnsnames.ora
oracle file. For this reason, the
Database
class takes care to set the proper oracle.net.tns_admin
variable.
tnsAlias
- the tns alias of the datasource, for example @mydatabase
true
if this feature is supportedpublic java.sql.Connection getConnection() throws java.sql.SQLException
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.
super.checkOut()
method
java.sql.SQLException
public void returnConnection(java.sql.Connection connection)
super.checkIn()
method.
connection
- the connection to be returned in the unlocked hashtablepublic void shutdown()
shutdown
in class ObjectPool
CleanUpThread
public java.lang.Object create() throws java.sql.SQLException
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).
create
in class ObjectPool
java.sql.SQLException
public boolean validate(java.lang.Object object)
checkOut()
method of the parent class before checking out an
object from the unlocked pool.
validate
in class ObjectPool
object
- the connection to be validatedpublic void expire(java.lang.Object object)
expire
in class ObjectPool
object
- the connection to be destroyedpublic void setTNSEntryName(java.lang.String value)
public java.lang.String getTNSEntryName()
public boolean supportTnsNames()
protected java.lang.String getDatabaseName(java.lang.String tns)
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.
tns
- the tns string of the db, e.g. jdbc:oracle:thin:@192.168.3.12:1588:vardati
public boolean logConnection(java.sql.Connection connection)
|
Build 18/09/2012 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |