soap tutorial

adriani.jws.template.db
Class MockConnectionPool

java.lang.Object
  extended by adriani.jws.template.db.ObjectPool
      extended by adriani.jws.template.db.JDBCConnectionPool
          extended by adriani.jws.template.db.MockConnectionPool

public class MockConnectionPool
extends JDBCConnectionPool

Mock oriented implementation of the ObjectPool parent class.
This class is different from the JDBCConnectionPool pool because here the objects in the pool are not "java plain old" SQL connections, but instances of the MockConnection wrapper.
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, MockConnection

Field Summary
 
Fields inherited from class adriani.jws.template.db.JDBCConnectionPool
alias, con, pwd, supportTns, usr
 
Fields inherited from class adriani.jws.template.db.ObjectPool
expirationTime, leadingName, logger, maximum
 
Constructor Summary
MockConnectionPool(java.lang.String con, java.lang.String usr, java.lang.String pwd, int expirationTime)
          Use this constructor if the JDBC driver has been already registered.
MockConnectionPool(java.lang.String driver, java.lang.String con, java.lang.String usr, java.lang.String pwd, int expirationTime)
          Use this constructor when it's necessary to register the JDBC driver (only the first time).
 
Method Summary
 java.lang.Object create()
          Users should not call this method directly.
 void expire(java.lang.Object object)
          Method used by the ObjectPool 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 getConnectionFromMock(java.lang.Object object)
          Cast the input object into a MockConnection wrapper and the retrieves the java.sql.Connection stored in the wrapper.
protected  java.lang.String getDatabaseName(java.lang.String tns)
          Split the full connect string and return only the last token, describing the database name.
 MockConnection getMockConnection()
          Users should call this method each time a mock connection is needed.
 void returnMockConnection(MockConnection mock)
          Users should call this method each time a mock is not needed anymore.
 boolean validate(java.lang.Object object)
          Method used by the checkOut() method of the ObjectPool class before checking out an object from the unlocked pool.
 
Methods inherited from class adriani.jws.template.db.JDBCConnectionPool
getConnection, getTNSEntryName, logConnection, returnConnection, setTNSEntryName, setTnsName, shutdown, supportTnsNames
 
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
 

Constructor Detail

MockConnectionPool

public MockConnectionPool(java.lang.String con,
                          java.lang.String usr,
                          java.lang.String pwd,
                          int expirationTime)
Use this constructor if the JDBC driver has been already registered.
Current implementation just calls the super constructor (i.e. JDBCConnectionPool), which forwards action to the super-super class (i.e. ObjectPool) that takes care to create and run the cleaner thread.

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

MockConnectionPool

public MockConnectionPool(java.lang.String driver,
                          java.lang.String con,
                          java.lang.String usr,
                          java.lang.String pwd,
                          int expirationTime)
Use this constructor when it's necessary to register the JDBC driver (only the first time).
Current implementation just calls the super constructor, which is responsible for creating and registering the proper Driver class.

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:db_name
usr - the user name for the SQL connection
pwd - the password for the SQL connection
expirationTime - sleep time of the Cleaner Thread in seconds
Method Detail

getMockConnection

public MockConnection getMockConnection()
                                 throws java.sql.SQLException
Users should call this method each time a mock connection is needed.

Remark: DO NOT USE the getConnection() method inherited from the super class, since any java.sql.Connection object stored in a MockConnectionPool class is always null.

Returns:
a mock obtained from the super.checkOut() method
Throws:
java.sql.SQLException
See Also:
ObjectPool.checkOut()

returnMockConnection

public void returnMockConnection(MockConnection mock)
Users should call this method each time a mock is not needed anymore.

Remark: DO NOT USE the returnConnection() method inherited from the super class, since any java.sql.Connection object stored in a MockConnectionPool class is always null.

Parameters:
mock - the MockConnection to be returned in the unlocked hashtable (using super.checkIn())
See Also:
ObjectPool.checkIn(Object obj)

create

public java.lang.Object create()
                        throws java.sql.SQLException
Users should not call this method directly. It's the checkOut() method of the ObjectPool 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 codeblock creating the objects managed by this pool class (in this case a MockConnection object).

Overrides:
create in class JDBCConnectionPool
Returns:
an object representing a brand new MockConnection to the database
Throws:
java.sql.SQLException

validate

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

Overrides:
validate in class JDBCConnectionPool
Parameters:
object - the MockConnection to be validated

expire

public void expire(java.lang.Object object)
Method used by the ObjectPool 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).

Overrides:
expire in class JDBCConnectionPool
Parameters:
object - the MockConnection to be destroyed

getConnectionFromMock

public java.sql.Connection getConnectionFromMock(java.lang.Object object)
Cast the input object into a MockConnection wrapper and the retrieves the java.sql.Connection stored in the wrapper.

Parameters:
object - an object managed by this pool class (i.e. a MockConnection instance)
Returns:
the java.sql.Connection stored in the MockConnection wrapper

getDatabaseName

protected java.lang.String getDatabaseName(java.lang.String tns)
Split the full connect 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.

Overrides:
getDatabaseName in class JDBCConnectionPool
Parameters:
tns - the connect string of the database, e.g. jdbc:oracle:thin:@192.168.3.12:1588:db_name
Returns:
the last part of the database name, e.g. db_name

Build 18/09/2012

Morpheus Quality Technologies - Making the Zion software
Copyright © 2009-2013 Morpheus Quality Technologies. All Rights Reserved