soap tutorial

adriani.jws.template.db
Class ServiceDAO

java.lang.Object
  extended by adriani.jws.template.db.GeneralDAO
      extended by adriani.jws.template.db.ServiceDAO

public class ServiceDAO
extends GeneralDAO

The class wrapping all the SQL queries and statement necessary to retrieve data from the database(s). This class stores the necessary references to the database connections. These fields are not present in the GeneralDAO parent class because usually it's better to avoid storing DB connection as class fields. Here we store the connections to improve performances by sharing the same connection only when invoking a sequence of queries from the ServiceMacro, usually during the same SOAP call.

The connections are obtained from the Database class using the MockConnection wrapper, which allows to perform some specific test/debug operations and could improve performances when using prepared statements in a connection pooling environment.
Note that it's up to the Database class to manage the connections pooling (if used), in order to keep uncoupled the implementation of this class from the management of connections: no matter which pool class is used, a DAO class should always retrieve connections just calling:

Database.getMockConnection(targetDB)

and returning them by calling:

Database.returnMockConnection(targetDB, this.mock[targetDB])


Field Summary
protected static java.lang.String GET_CUSTOMER
          SAMPLE query in string format used to create the corresponding prepared statement.
protected static java.lang.String GET_ENTITY_TIME
          SAMPLE query in string format used to create the corresponding prepared statement.
protected static WSLogger logger
          Retrieving the logger instance to be used for this class.
protected  MockConnection[] mock
          The array of mock connections for the necessary database(s) (accessed by this DAO).
protected static java.lang.StringBuffer ONE
          Static final String value stored as class fields to improve performances.
protected  ServiceMacro serviceMacro
          A reference to the ServiceMacro object which created this DA0.
 
Fields inherited from class adriani.jws.template.db.GeneralDAO
AUTO, chronStart, db_timestamp, DOUBLE_QUOTES, EMPTY, ERROR, leadingName, NO_DATA_FOUND, NO_DATA_MSG, PERCENT, PSTMT_NOK, QUERY_NOK, QUOTE, ROLLBACK_NOK, status, VARCHAR
 
Constructor Summary
ServiceDAO()
          This constructor DOES NOT require (nor create) the serviceMacro object, hence the configuration files and properties will NOT be loaded.
ServiceDAO(ServiceMacro macro)
          Stateful constructor.
 
Method Summary
 void closeConnection(int targetDB)
          Close the connection specified by the input target parameter, for example:

targetDB = DB_01 --> close the connection to the DB_01 database.
 void collectStatus(int statusValue)
          We override the parent (empty) method in order to register the execution status of a general SQL statement in the ServiceAnalyzer class, by calling:

serviceMacro.getServiceAnalyzer().collect(status) ;

 java.sql.Connection getConnection(int targetDB)
          Return the connection currently opened through the target database, for example:

targetDB = DB_01 --> close the connection to the DB_01 database.
 CustomerDTO[] getCustomerData(java.lang.StringBuffer number, java.lang.StringBuffer customer)
          Sample basic query: remove this method when developing actual DAO method.
 java.lang.StringBuffer[][] getDummyQuery(java.lang.StringBuffer[] param, int howMany, int cols)
          Produces a StringBuffer[][] object created from some hard-coded data for a general SOAP method.
 EntityTimeDTO getEntityTime(int id)
          Sample basic query: remove this method when developing actual DAO method.
 boolean openConnection(int targetDB)
          Open the connection to the target database.
 java.lang.StringBuffer testPreparedStatement(int number)
          Dummy query used to test the mocked pool mechanism if there is not any query using the prepared statement approach.
 
Methods inherited from class adriani.jws.template.db.GeneralDAO
compareSB, doubleQuote, endQuery, executeUpdate, executeUpdate, fetchColumnData, finalize, flushLogger, getColumnData, getColumnType, getFunction, getFunction, getFunctionPipe, getPreparedRecord, getPreparedRecordSet, getProcedure, getRecord, getRecord, getRecordSet, getRecordSet, getRowCount, getStatus, inspectColumn, inspectResultSet, quote, startQuery, valueOfString, valueOfTimestamp
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mock

protected MockConnection[] mock
The array of mock connections for the necessary database(s) (accessed by this DAO).


serviceMacro

protected ServiceMacro serviceMacro
A reference to the ServiceMacro object which created this DA0.


GET_CUSTOMER

protected static final java.lang.String GET_CUSTOMER
SAMPLE query in string format used to create the corresponding prepared statement.

See Also:
Constant Field Values

GET_ENTITY_TIME

protected static final java.lang.String GET_ENTITY_TIME
SAMPLE query in string format used to create the corresponding prepared statement.

See Also:
Constant Field Values

ONE

protected static final java.lang.StringBuffer ONE
Static final String value stored as class fields to improve performances.


logger

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

Constructor Detail

ServiceDAO

public ServiceDAO()
This constructor DOES NOT require (nor create) the serviceMacro object, hence the configuration files and properties will NOT be loaded. Default values (hard coded) will be used instead, as defined in the Settings class.


ServiceDAO

public ServiceDAO(ServiceMacro macro)
Stateful constructor.

Parameters:
macro - the ServiceMacro class creating and using this DAO
Method Detail

openConnection

public boolean openConnection(int targetDB)
Open the connection to the target database. The connection to be opened is selected by the input targetDB parameter, for example:

targetDB = DB_01 --> open a connection to the DB_01 database.
targetDB = DB_02 --> open a connection to the DB_02 database.
etc...

Connections are retrieved from the Database class using the getMockConnection mechanism, which allowS to retrieve both simple connections or wrapped connections.
Current implementation immediately QUIT execution if we get an error opening the connection, logging a SEVERE error message and returning false. Usually this means that the web service will not produce a valid response: the client could receive a SOAP response containing a message like "database not found".

Parameters:
targetDB - the reference code of the database where to open the connection
Returns:
true if the connection has been opened successfully
See Also:
Database.getMockConnection(int targetDB)

closeConnection

public void closeConnection(int targetDB)
Close the connection specified by the input target parameter, for example:

targetDB = DB_01 --> close the connection to the DB_01 database.
targetDB = DB_02 --> close the connection to the DB_02 database.
etc...

Current implementation DOES NOT quit execution if we get an error returning the connection. This means that the web service could provide a valid output, but connections to the database are left "hanged up" and could cause a database crash. For this reasn such a situation is logged as a SEVERE error by the log system.

Parameters:
targetDB - the number of the database where to return the connection

getConnection

public java.sql.Connection getConnection(int targetDB)
Return the connection currently opened through the target database, for example:

targetDB = DB_01 --> close the connection to the DB_01 database.
targetDB = DB_02 --> close the connection to the DB_02 database.
etc...

Specified by:
getConnection in class GeneralDAO
Parameters:
targetDB - the number of the database offering the connection
Returns:
the currently opened connection to the target database

getCustomerData

public CustomerDTO[] getCustomerData(java.lang.StringBuffer number,
                                     java.lang.StringBuffer customer)
Sample basic query: remove this method when developing actual DAO method. Usually we should have one method like this for each query (or group of similar queries).

Parameters:
number - the whole telephone number (without the international prefix)
customer - the customer ID reference number (optional)
Returns:
the customer (name, surname) pair as found in the database

getEntityTime

public EntityTimeDTO getEntityTime(int id)
Sample basic query: remove this method when developing actual DAO method. Usually we should have one method like this for each query (or group of similar queries).

Parameters:
id - the entity id reference
Returns:
the DTO wrapping end time for the entity_time matching the input entity_id

collectStatus

public void collectStatus(int statusValue)
We override the parent (empty) method in order to register the execution status of a general SQL statement in the ServiceAnalyzer class, by calling:

serviceMacro.getServiceAnalyzer().collect(status) ;

Overrides:
collectStatus in class GeneralDAO
Parameters:
statusValue - the integer status as defined by the ErrorMessage class fields
See Also:
ErrorMessage

getDummyQuery

public java.lang.StringBuffer[][] getDummyQuery(java.lang.StringBuffer[] param,
                                                int howMany,
                                                int cols)
Produces a StringBuffer[][] object created from some hard-coded data for a general SOAP method. This method should be used only during development to obtain an output from a SOAP method as long as the actual database is not available.

Parameters:
param - the array containing all the input data
howMany - the number of record to be retrieved
cols - the number of columns for each record
Returns:
a StringBuffer[][] object obtained from hard-coded data

testPreparedStatement

public java.lang.StringBuffer testPreparedStatement(int number)
Dummy query used to test the mocked pool mechanism if there is not any query using the prepared statement approach.

Returns:
current sysdate from the database

Build 18/09/2012

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