soap tutorial

adriani.jws.template.db
Class MockConnection

java.lang.Object
  extended by adriani.jws.template.db.MockConnection

public class MockConnection
extends java.lang.Object

Wrapper class for the java.sql.Connection object. These wrappers can be pooled using the MockConnectionPool class, in substitution of the couple "pure connections" pooled by the simple JDBCConnectionPool class.
Usually it should be not necessary to use these wrappers, since the JDBC connection pool guarantees the same behavior and performances. Selecting this "pool wrapper architecture" could be the best choice only in few situations, such as:


Field Summary
protected  java.sql.Connection connection
          The JDBC SQL connection object wrapped by this class.
protected static java.lang.String leadingName
          Beginning of each logging message produced by this class.
protected static WSLogger logger
          Retrieving the logger instance to be used for this class.
 
Constructor Summary
MockConnection(java.sql.Connection connection)
          Standard constructor.
MockConnection(java.lang.String alias, java.lang.String usr, java.lang.String pwd)
          Use this constructor if another class has already registered the JDBC driver for the same type of database hosting these connections.
 
Method Summary
 java.sql.Connection getConnection()
          Accessor method.
 java.sql.PreparedStatement getPreparedStatement(java.lang.String query)
          Use always this method to create a JDBC PreparedStatement from a xxxDAO class, in order to uncouple database pooling structure from DAO query logic.
 boolean returnPreparedStatement(java.sql.PreparedStatement pstmt)
          Use always this method to close a JDBC PreparedStatement from a xxxDBA class, in order to uncouple database pooling structure from DBA query logic.
 void setConnection(java.sql.Connection connection)
          Mutator method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

connection

protected java.sql.Connection connection
The JDBC SQL connection object wrapped by this class.


leadingName

protected static java.lang.String leadingName
Beginning of each logging message produced by this class.


logger

protected static WSLogger logger
Retrieving the logger instance to be used for this class.

Constructor Detail

MockConnection

public MockConnection(java.sql.Connection connection)
Standard constructor.

Parameters:
connection - the java.sql.Connection to be wrapped by this class

MockConnection

public MockConnection(java.lang.String alias,
                      java.lang.String usr,
                      java.lang.String pwd)
Use this constructor if another class has already registered the JDBC driver for the same type of database hosting these connections. This constructor retrieve a brand new connection from the DriverManager and stores it as a class field.

Parameters:
alias - the tns string of the db, e.g. jdbc:oracle:thin:@192.168.1.10:1533:my_database
usr - the user name for the connection
pwd - the password for the connection
Method Detail

getPreparedStatement

public java.sql.PreparedStatement getPreparedStatement(java.lang.String query)
                                                throws java.sql.SQLException
Use always this method to create a JDBC PreparedStatement from a xxxDAO class, in order to uncouple database pooling structure from DAO query logic.
This method takes care to inspect the Database class and then decide if the prepared statement must be produced brand new, or retrieved from the inner cache.

Parameters:
query - the original SQL query, filled with question marks ('?') characters
Returns:
the empty prepared statement. If mockup pool is enabled, the statement could be retrieved from the pool's cache. Otherwise the statement is retrieved directly from the connection (default behavior)
Throws:
java.sql.SQLException
See Also:
GeneralDAO, returnPreparedStatement(PreparedStatement pstmt)

returnPreparedStatement

public boolean returnPreparedStatement(java.sql.PreparedStatement pstmt)
Use always this method to close a JDBC PreparedStatement from a xxxDBA class, in order to uncouple database pooling structure from DBA query logic.
This method takes care to inspect the Database class and then decide if the prepared statement must be closed or cached in this class's inner hashtable.

Parameters:
pstmt - the PreparedStatement obtained using getPreparedStatement()
Returns:
true if the prepared statement has been closed (i.e. released)
See Also:
GeneralDAO, getPreparedStatement(String query)

setConnection

public void setConnection(java.sql.Connection connection)
Mutator method.


getConnection

public java.sql.Connection getConnection()
Accessor method.


Build 19/03/2014

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