soap tutorial

adriani.jws.template.db
Class Database

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

public class Database
extends java.lang.Object

The data-bridge class used to retrieve and return JDBC connection from the database. To obtain a connection, users should use a code block like this:


                Connection connection = Database.getMockConnection(targetDB) ;
                // Perform your SQL operations here
                Database.returnMockConnection(targetDB, this.mock[targetDB]) ;
 

By this mechanism this class will always return a MockConnection, which in general is not actually a mock connection, but it's just a wrapper for a normal java SQL connection.

Moreover this class holds some static reference labels and parameters common to all databases.
Example: the Database.DB_01, Database.DB_02 labels and the Database.DB_NUMBER parameter.


Field Summary
static int DB_01
          Reference code for the DB_01 database.
static int DB_02
          Reference code for the DB_02 database (Placeholder)
static int DB_NUMBER
          Total number of databases handled by this class.
protected static java.lang.String driver
          Name of the current JDBC driver (for testing or debug).
static java.lang.String jdbc_prefix
          The JDBC prefix used to build the complete connect string.
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.
protected static int maximum
          Maximum allowed number of connections for ALL the JDBC pools.
protected static boolean mock
          Specifies if connections are retrieved from a pure JDBC pool (the JDBCConnectionPool class) or from a mocked connection pool (the MockConnectionPool class).
protected static JDBCConnectionPool[] pool
          Array of JDBC connection pool for the databases handled by this class.
protected static int timeout
          Sleep time for the cleaning thread for ALL the JDBC pools (in seconds).
protected static java.lang.String tns_property
          Name of the Java Property where to set the reference to the tnsnames.ora file.
protected static java.lang.String tnsnames
          Absolute path of the tnsnames.ora (if used).
 
Constructor Summary
Database()
           
 
Method Summary
static JDBCConnectionPool getJDBCPool(int targetDB)
          Return the JDBCConnectionPool object managing all the JDBC connections to the database specified in input, according to the static fields reference defined by this class.
static java.lang.StringBuffer getMetaData(java.sql.Connection connection)
          Produce the meta-data information about the input database's connection object and format this data into a StringBuffer object.
static MockConnection getMockConnection(int targetDB)
          Return a new MockConnection wrapper containing the SQL connection, by retrieving it from the proper pool (pure or mocked).
static void logMetaData()
          Print in the LOG file and on the STDOUT some meta-data information about ALL the databases used by this project.
static void logMetaData(int target)
          Print in the LOG file and on the STDOUT some meta-data information about the database selected by the input parameter, according to the static fields reference defined by this class.
static void logPoolsData()
          Logs some information about the status of the JDBC pools used by this database class.
static void returnMockConnection(int targetDB, MockConnection wrapper)
          Release an already opened SQL connection, wrapped by a MockConnection object, returning it in the pool that originally produced such connection.
static java.lang.StringBuffer showMetaData(int target)
          Produces a formatted string containing some meta-data information about the database selected by the input target parameter, according to the static fields reference defined by this class.
static boolean usesMockedPool()
          Specifies if connections are retrieved from the pure JDBC pool (i.e. the JDBCConnectionPool) or from the MockConnectionPool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DB_01

public static final int DB_01
Reference code for the DB_01 database.

See Also:
Constant Field Values

DB_02

public static final int DB_02
Reference code for the DB_02 database (Placeholder)

See Also:
Constant Field Values

DB_NUMBER

public static final int DB_NUMBER
Total number of databases handled by this class.

See Also:
Constant Field Values

mock

protected static boolean mock
Specifies if connections are retrieved from a pure JDBC pool (the JDBCConnectionPool class) or from a mocked connection pool (the MockConnectionPool class).


pool

protected static JDBCConnectionPool[] pool
Array of JDBC connection pool for the databases handled by this class.


timeout

protected static int timeout
Sleep time for the cleaning thread for ALL the JDBC pools (in seconds).


maximum

protected static int maximum
Maximum allowed number of connections for ALL the JDBC pools.


driver

protected static java.lang.String driver
Name of the current JDBC driver (for testing or debug).


jdbc_prefix

public static java.lang.String jdbc_prefix
The JDBC prefix used to build the complete connect string.


tnsnames

protected static java.lang.String tnsnames
Absolute path of the tnsnames.ora (if used).


tns_property

protected static java.lang.String tns_property
Name of the Java Property where to set the reference to the tnsnames.ora file.


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

Database

public Database()
Method Detail

usesMockedPool

public static boolean usesMockedPool()
Specifies if connections are retrieved from the pure JDBC pool (i.e. the JDBCConnectionPool) or from the MockConnectionPool. Notice that all other information about the pool (timeout, maximum limit etc.) can be retrieved by inspecting the proper pool instance as obtained by the method getJDBCPool(int targetDB) method.

Returns:
true if this class relies on an instance of the MockConnectionPool, false if the standard JDBCConnectionPool is used

getJDBCPool

public static JDBCConnectionPool getJDBCPool(int targetDB)
Return the JDBCConnectionPool object managing all the JDBC connections to the database specified in input, according to the static fields reference defined by this class.
The returned pool can be a pure JDBCConnectionPool object or another valid subclass, for example a MockConnectionPool class.

Example: getJDBCPool(Datase.DB_01) will return the JDBC pool for the DB_01 database.

Parameters:
targetDB - a reference to the database (see static class field definitions)
Returns:
the instance of the JDBCConnectionPool for the input database
See Also:
usesMockedPool(), JDBCConnectionPool, MockConnectionPool

getMockConnection

public static MockConnection getMockConnection(int targetDB)
                                        throws java.sql.SQLException
Return a new MockConnection wrapper containing the SQL connection, by retrieving it from the proper pool (pure or mocked).

Parameters:
targetDB - a reference to the database (see static class field definitions)
Returns:
the instance of the JDBCConnectionPool for the input database
Throws:
java.sql.SQLException

returnMockConnection

public static void returnMockConnection(int targetDB,
                                        MockConnection wrapper)
Release an already opened SQL connection, wrapped by a MockConnection object, returning it in the pool that originally produced such connection.

Parameters:
targetDB - a reference to the database (see static class field definitions)
wrapper - the MockConnection wrapper to be released

logMetaData

public static void logMetaData()
Print in the LOG file and on the STDOUT some meta-data information about ALL the databases used by this project.


logMetaData

public static void logMetaData(int target)
Print in the LOG file and on the STDOUT some meta-data information about the database selected by the input parameter, according to the static fields reference defined by this class.

Example: logMetaData(Datase.DB_01) will show meta-data about the DB_01 database.

Parameters:
target - a reference to the database (see static class field definitions)

showMetaData

public static java.lang.StringBuffer showMetaData(int target)
Produces a formatted string containing some meta-data information about the database selected by the input target parameter, according to the static fields reference defined by this class.

Example: showMetaData(Datase.DB_01) will produce meta-data about the DB_01 database.

Parameters:
target - a reference to the database (see static class field definitions)

getMetaData

public static java.lang.StringBuffer getMetaData(java.sql.Connection connection)
                                          throws java.sql.SQLException
Produce the meta-data information about the input database's connection object and format this data into a StringBuffer object.

Returns:
a printable string containing meta-data information about the database
Throws:
java.sql.SQLException

logPoolsData

public static void logPoolsData()
Logs some information about the status of the JDBC pools used by this database class.
In current implementation this method is executed when the web service receive the command 00000011.

See Also:
GeneralService.manageService(int key)

Build 18/09/2012

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