|
soap tutorial | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectadriani.jws.template.db.GeneralDAO
public abstract class GeneralDAO
GeneralDAO - general class used to provide some common methods to all database accessors (DAO classes).
This class defines some general purposes objects: class fields, double quoting methods, introspection methods,
standard accessors and benchmark analysis. The core utilities of this class is a set of methods wrapping
the more common SQL statements: retrieving one single record, retrieving a result set, calling a PL/SQL
function or procedure, calling a pipelined PL/SQL function etc.
All connections issues SHOULD NOT be implemented at this level, but should be left to the children classes,
in order to reflect the detailed requirements of the business logic.
Field Summary | |
---|---|
static int |
AUTO
Reference to the "auto-type" feature allowing to inspect column's datatypes. |
protected long |
chronStart
Long timestamp used to evaluate performance time when the ANALYSIS mode is used. |
protected static java.text.SimpleDateFormat |
db_timestamp
DateFormat static reference for conversion from the format YYYY-MM-DD HH-MM-SS.M. |
static java.lang.String |
DOUBLE_QUOTES
Static final String value stored as class fields to improve performances. |
protected static java.lang.String |
EMPTY
Static final String value stored as class fields to improve performances. |
protected static java.lang.String |
ERROR
The message to print in the case of a general Java Exception . |
protected java.lang.String |
leadingName
The leading name of each message logged by this class. |
protected static WSLogger |
logger
Retrieving the logger instance to be used for this class. |
protected static int |
NO_DATA_FOUND
The integer storing the Oracle error code ORA-01403: no data found. |
protected static java.lang.String |
NO_DATA_MSG
The message to print if the query returned no data at all. |
static java.lang.String |
PERCENT
Static final String value stored as class fields to improve performances. |
protected static java.lang.String |
PSTMT_NOK
The message to print if preparation of the prepared statement failed. |
protected static java.lang.String |
QUERY_NOK
The message to print in the case of a SQLException . |
static java.lang.String |
QUOTE
Static final String value stored as class fields to improve performances. |
protected static java.lang.String |
ROLLBACK_NOK
The message to print in the case of a rollback failure. |
protected int |
status
Status of the DAO after execution of the last SQL statement. |
static int |
VARCHAR
Reference to the "auto-type" feature allowing to inspect column's datatypes (default value) |
Constructor Summary | |
---|---|
GeneralDAO()
Empty constructor. |
Method Summary | |
---|---|
void |
collectStatus(int statusValue)
Subclasses SHOULD override this method in order to log the final execution status of a general SQL statement. |
boolean |
compareSB(java.lang.StringBuffer first,
java.lang.StringBuffer second)
Helper method, used to compare StringBuffer contents. |
java.lang.String |
doubleQuote(java.lang.String input)
Adds double quotation marks to the input String to avoid SQL error. |
void |
endQuery(java.lang.String msg)
Log performances data on the Performances Analyser and flush the relative Handler. |
int |
executeUpdate(int targetDB,
java.lang.String label,
java.lang.String query)
Execute the general UPDATE query passed in input. |
int |
executeUpdate(java.sql.PreparedStatement pstmt,
java.lang.String label)
Executes a PreparedStatement to the target database, returning an integer number describing
the number of affected rows. |
java.lang.String |
fetchColumnData(java.sql.ResultSet rs,
int col)
Fetch the column data automatically. |
void |
finalize()
Method useful for debug and testing, used to verify the scope of the children classes. |
void |
flushLogger(java.util.logging.Logger logger)
Flush the handler bound to the given Logger . |
java.lang.String |
getColumnData(java.sql.ResultSet rs,
int col,
int type)
Return an String containing data of the input indexed column,
read using the proper method for the column java.sql.Types type. |
int |
getColumnType(java.sql.ResultSet rs,
int col)
Inspect the ResultSetMetaData for the input indexed column, and return a formatted
StringBuffer object containing the column's metadata. |
abstract java.sql.Connection |
getConnection(int targetDB)
Return the connection currently opened through the target database, for example: targetDB = DB_01 --> get the connection opened to the DB_01 database. |
java.lang.StringBuffer[] |
getFunction(int targetDB,
java.lang.String label,
java.lang.String query,
java.lang.Object[] param)
Executes a PL/SQL FUNCTION on the target database, returning a single record wrapped by a StringBuffer array. |
java.lang.StringBuffer[] |
getFunction(int targetDB,
java.lang.String label,
java.lang.String query,
java.lang.Object[] param,
int type)
Executes a PL/SQL FUNCTION on the target database, returning a single record wrapped by a StringBuffer array. |
java.lang.StringBuffer[][] |
getFunctionPipe(int targetDB,
java.lang.String label,
java.lang.String query,
int cols)
Executes a PL/SQL FUNCTION on the target database, returning a set of records described by an array whose elements are others StringBuffer arrays:StringBuffer[n][i] contains the i-th column of the n-th record. |
java.lang.StringBuffer[] |
getPreparedRecord(java.sql.PreparedStatement pstmt,
java.lang.String label,
int cols)
Executes a PreparedStatement to the target database, returning a single record
described by a StringBuffer array. |
java.lang.StringBuffer[][] |
getPreparedRecordSet(java.sql.PreparedStatement pstmt,
java.lang.String label,
int cols)
Executes a PreparedStatement to the target database, returning a set of records
described by an array which elements are others StringBuffer arrays, where:StringBuffer[n][i] contains the i-th column of the n-th record. |
java.lang.StringBuffer[] |
getProcedure(int targetDB,
java.lang.String label,
java.lang.String query,
java.lang.Object[] param,
int cols,
int[] inout)
Executes a PL/SQL PROCEDURE call to the target database, returning a single record described by a StringBuffer array. |
java.lang.StringBuffer[] |
getRecord(int targetDB,
java.lang.String label,
java.lang.String query,
int cols)
Executes a SELECT query to the target database, returning a single record described by a StringBuffer array. |
java.lang.StringBuffer[] |
getRecord(int targetDB,
java.lang.String label,
java.lang.String query,
int cols,
int type)
Executes a SELECT query to the target database, returning a single record described by a StringBuffer array. |
java.lang.StringBuffer[][] |
getRecordSet(int targetDB,
java.lang.String label,
java.lang.String query,
int cols)
Executes a SELECT query to the target database, returning a set of records described by an array whose elements are others StringBuffer arrays:StringBuffer[n][i] contains the i-th column of the n-th record. |
java.lang.StringBuffer[][] |
getRecordSet(int targetDB,
java.lang.String label,
java.lang.String query,
int cols,
int type)
Executes a SELECT query to the target database, returning a set of records described by an array whose elements are others StringBuffer arrays:StringBuffer[n][i] contains the i-th column of the n-th record. |
static int |
getRowCount(java.sql.ResultSet set)
Determines the number of rows in a ResultSet . |
int |
getStatus()
Return an int code describing the status of the DAO after execution of the last SQL-oriented label. |
java.lang.StringBuffer |
inspectColumn(java.sql.ResultSet rs,
int col)
Inspect the ResultSetMetaData for the input indexed column, and return a formatted
StringBuffer object containing the column's metadata. |
java.lang.StringBuffer |
inspectResultSet(java.sql.ResultSet rs)
This method can be invoked immediately after the stmt.executeQuery(query) call
to inspect the retrieved ResultSet . |
java.lang.String |
quote(java.lang.String input)
Execute a doubleQuote() method on the input string, then surround the result with
a pair of single quotes. |
void |
startQuery(java.lang.String msg)
Log performances data on the Performances Analyser and flush the relative Handler. |
protected int |
valueOfString(java.lang.String string,
int no_value)
Parse the string value of the input String into an integer value. |
protected java.sql.Timestamp |
valueOfTimestamp(java.lang.String string)
Parse the string value of the input String into a timestamp value. |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected int status
protected long chronStart
protected static final java.lang.String EMPTY
String
value stored as class fields to improve performances.
public static final java.lang.String QUOTE
String
value stored as class fields to improve performances.
public static final java.lang.String PERCENT
String
value stored as class fields to improve performances.
public static final java.lang.String DOUBLE_QUOTES
String
value stored as class fields to improve performances.
protected static final java.lang.String ERROR
Exception
.
protected static final java.lang.String QUERY_NOK
SQLException
.
protected static final java.lang.String ROLLBACK_NOK
protected static final java.lang.String PSTMT_NOK
protected static final java.lang.String NO_DATA_MSG
protected static final int NO_DATA_FOUND
public static final int VARCHAR
public static final int AUTO
protected static java.text.SimpleDateFormat db_timestamp
protected static WSLogger logger
protected java.lang.String leadingName
Constructor Detail |
---|
public GeneralDAO()
Method Detail |
---|
public void finalize()
finalize
in class java.lang.Object
public abstract java.sql.Connection getConnection(int targetDB)
JDBCConnectionPool
included in this package.
targetDB
- the number of the database offering the connection
public void startQuery(java.lang.String msg)
chronStart
class field.
msg
- the string text name of the query that is going to be executedSettings.BENCHMARK
public void endQuery(java.lang.String msg)
msg
- the string text name of the query that has just been terminatedSettings.BENCHMARK
public void flushLogger(java.util.logging.Logger logger)
Logger
. Notice that the benchmark
feature relies always on the SystemLogger
class, never on the Log4j mechanism.
logger
- the key string reference to the logger object to be flushedSystemLogger
public void collectStatus(int statusValue)
ServiceAnalyzer
mechanism
for collecting statistics about SQL execution status, implementation of this method could be
something like:serviceMacro.getServiceAnalyzer().collect(status) ;
statusValue
- the integer status as defined by the ErrorMessage
class fieldsServiceAnalyzer
,
ErrorMessage
public java.lang.StringBuffer[] getRecord(int targetDB, java.lang.String label, java.lang.String query, int cols)
StringBuffer
array. The length of the array is defined by the cols
input parameter, representing the number of columns to be retrieved from the database.
This method just forward action to the full-signature getRecord()
method, assuming
as default return types the VARCHAR
type (for all columns).
targetDB
- the number of the database where to execute the querylabel
- the logical name of the statement, only for logging purposesquery
- the SQL statement to be executed, already filled with parameterscols
- the number of columns to be retrieved from the database
StringBuffer
array containing the selected columns (from the same record)getRecord(int targetDB, String label, String query, int cols, int type)
public java.lang.StringBuffer[][] getRecordSet(int targetDB, java.lang.String label, java.lang.String query, int cols)
StringBuffer
arrays:StringBuffer[n][i]
getRecordSet()
method, assuming
as default return types the VARCHAR
type (for all columns).
targetDB
- the number of the database where to execute the querylabel
- the logical name of the statement, only for logging purposesquery
- the SQL statement to be executed, already filled with parameterscols
- the number of columns to be retrieved from the database
StringBuffer
2D array containing all the matching recordspublic java.lang.StringBuffer[] getRecord(int targetDB, java.lang.String label, java.lang.String query, int cols, int type)
StringBuffer
array. The length of the array is defined by the cols
input parameter, representing the number of columns to be retrieved from the database.
targetDB
- the number of the database where to execute the querylabel
- the logical name of the statement, only for logging purposesquery
- the SQL statement to be executed, already filled with parameterscols
- the number of columns to be retrieved from the databasetype
- a reference to the criterion used to evaluate columns types
StringBuffer
array containing the selected columns (from the same record)public java.lang.StringBuffer[][] getRecordSet(int targetDB, java.lang.String label, java.lang.String query, int cols, int type)
StringBuffer
arrays:StringBuffer[n][i]
targetDB
- the number of the database where to execute the querylabel
- the logical name of the statement, only for logging purposesquery
- the SQL statement to be executed, already filled with parameterscols
- the number of columns to be retrieved from the databasetype
- a reference to the criterion used to evaluate columns types
StringBuffer
2D array containing all the matching recordspublic java.lang.StringBuffer[] getFunction(int targetDB, java.lang.String label, java.lang.String query, java.lang.Object[] param)
StringBuffer
array.getFunction()
method, assuming
as default return type the VARCHAR
type.
targetDB
- the number of the database where to execute the querylabel
- the logical name of the statement, only for logging purposesquery
- the prepared call statement to be executed, not yet filled with parametersparam
- the Object
array containing the input parameters
StringBuffer
array containing the selected columnsgetFunction(int targetDB, String label, String query, Object[] param, int type)
public java.lang.StringBuffer[] getFunction(int targetDB, java.lang.String label, java.lang.String query, java.lang.Object[] param, int type)
StringBuffer
array.{? = call FUNCTION(?, ?, ?, ....)}
syntax,
because is generally more performing than the alternative approaches:SELECT FUNCTION(x, y, z, ...) FROM DUAL
(ordinary plain old java).SELECT FUNCTION(?, ?, ?, ...) FROM DUAL
(JDBC prepared statement).
targetDB
- the number of the database where to execute the querylabel
- the logical name of the statement, only for logging purposesquery
- the prepared call statement to be executed, not yet filled with parametersparam
- the Object
array containing the input parameterstype
- the java.sql.Types
output type
StringBuffer
array containing the selected columnspublic java.lang.StringBuffer[][] getFunctionPipe(int targetDB, java.lang.String label, java.lang.String query, int cols)
StringBuffer
arrays:StringBuffer[n][i]
getRecordSet()
method, since the best way
to execute a function returning a pipe is to use an ordinary SELECT statement.
targetDB
- the number of the database where to execute the querylabel
- the logical name of the statement, only for logging purposesquery
- the SQL statement to be executed, already filled with parameterscols
- the number of columns to be retrieved from the database
StringBuffer
2D array containing all the matching recordspublic java.lang.StringBuffer[] getProcedure(int targetDB, java.lang.String label, java.lang.String query, java.lang.Object[] param, int cols, int[] inout)
StringBuffer
array. The length of the output array is defined by the
cols
input parameter (number of columns to be retrieved from the record).
param
array must be null.
If the procedure requires some IN OUT parameters, the index of these parameters MUST BE specified in
the inout
input integer array.
If there are no IN OUT parameters, the inout
array MUST BE null
.FOO(a IN, b IN OUT, c IN, d IN OUT, e OUT)
this method must be invoked using:param = {1,2,3,4} ; cols = 3 ; inout = {2,4}
.
targetDB
- the number of the database where to execute the querylabel
- the logical name of the statement, only for logging purposesquery
- the SQL statement to be executed, not yet filled with parametersparam
- the Object
array containing the input parameterscols
- the number of output columns to be retrieved from the databaseinout
- an int array specifying the index of the IN OUT parameters (null if there are no IN OUT params)
StringBuffer
array containing the selected columnspublic java.lang.StringBuffer[] getPreparedRecord(java.sql.PreparedStatement pstmt, java.lang.String label, int cols)
PreparedStatement
to the target database, returning a single record
described by a StringBuffer
array. The length of the array is defined by the cols
input parameter, i.e. the number of columns to be retrieved from the database.Database
class the choice
to eventually close or cache the prepared statement (after usage).
pstmt
- the PreparedStatement
to be executed, already filled with parameterslabel
- the logical name of the statement, only for logging purposescols
- the number of columns to be retrieved from the database
StringBuffer
array containing the selected columnspublic java.lang.StringBuffer[][] getPreparedRecordSet(java.sql.PreparedStatement pstmt, java.lang.String label, int cols)
PreparedStatement
to the target database, returning a set of records
described by an array which elements are others StringBuffer
arrays, where:StringBuffer[n][i]
Database
class the choice
to eventually close or cache the prepared statement (after usage).
pstmt
- the PreparedStatement
to be executed, already filled with parameterslabel
- the logical name of the statement, only for logging purposescols
- the number of columns to be retrieved from the database
StringBuffer
double array containing all the matching recordspublic int executeUpdate(int targetDB, java.lang.String label, java.lang.String query)
targetDB
- the number of the database where to execute the querylabel
- the logical name of the statement, only for logging purposesquery
- the query that must be executed
public int executeUpdate(java.sql.PreparedStatement pstmt, java.lang.String label)
PreparedStatement
to the target database, returning an integer number describing
the number of affected rows.
pstmt
- the PreparedStatement
to be executed, already filled with parameterslabel
- the logical name of the statement, only for logging purposes
public int getStatus()
public java.lang.String fetchColumnData(java.sql.ResultSet rs, int col) throws java.sql.SQLException
ResultSetMetaData
for the input indexed column, and returning a formatted StringBuffer
object containing
the column's data. This is just a shortcut to invocation of following methods:
int colType = getColumnType(result, n) ;
return getColumnData(result, n, colType) ;
rs
- the ResultSet
as returned by the databasecol
- the index of the column to be inspected
String
representation of the column's content
java.sql.SQLException
getColumnType(ResultSet rs, int col)
,
throws SQLException
public int getColumnType(java.sql.ResultSet rs, int col)
ResultSetMetaData
for the input indexed column, and return a formatted
StringBuffer
object containing the column's metadata.
rs
- the ResultSet
as returned by the databasecol
- the index of the column to be inspected
java.sql.Types
column typepublic java.lang.String getColumnData(java.sql.ResultSet rs, int col, int type) throws java.sql.SQLException
String
containing data of the input indexed column,
read using the proper method for the column java.sql.Types
type.
rs
- the ResultSet
as returned by the databasecol
- the index of the column to be readtype
- the java.sql.Types
describing the column
String
representation of the column's content
java.sql.SQLException
public java.lang.String doubleQuote(java.lang.String input)
input
- the string that can contain single quote characters
public java.lang.String quote(java.lang.String input)
doubleQuote()
method on the input string, then surround the result with
a pair of single quotes.
input
- the string that can contain single quote characters
protected int valueOfString(java.lang.String string, int no_value)
String
into an integer value.
The no_value
parameter represent the default integer value to be returned if
the parsing is not successful.
string
- the input string objectno_value
- the integer value to be returned if conversion fails
no_value
number)protected java.sql.Timestamp valueOfTimestamp(java.lang.String string)
String
into a timestamp value.
string
- the input string object
public boolean compareSB(java.lang.StringBuffer first, java.lang.StringBuffer second)
first
- a StringBuffer
objectsecond
- another StringBuffer
object
true
if the two string object contains the same textpublic java.lang.StringBuffer inspectResultSet(java.sql.ResultSet rs)
stmt.executeQuery(query)
call
to inspect the retrieved ResultSet
. The obtained meta data are returned as a
StringBuffer
object.
rs
- the ResultSet
as returned by the database
StringBuffer
object containing meta data information about the result setpublic static int getRowCount(java.sql.ResultSet set) throws java.sql.SQLException
ResultSet
. Upon exit, if the cursor was not
currently on a row, it is just before the first row in the result set (a call to
ResultSet.next()
will go to the first row).
set
- The ResultSet
to check (must be scrollable).
java.sql.SQLException
- If the ResultSet
is not scrollable.public java.lang.StringBuffer inspectColumn(java.sql.ResultSet rs, int col)
ResultSetMetaData
for the input indexed column, and return a formatted
StringBuffer
object containing the column's metadata.
rs
- the ResultSet
as returned by the databasecol
- the index of the column to be inspected
StringBuffer
object containing meta data information about the column
|
Build 19/03/2014 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |