com.ibm.dse.services.jdbc
Class JDBCService

java.lang.Object
  |
  +--com.ibm.dse.base.DSENotifier
        |
        +--com.ibm.dse.base.Service
              |
              +--com.ibm.dse.services.jdbc.JDBCService
Direct Known Subclasses:
JDBCTable, Journal, Store

public abstract class JDBCService
extends Service
implements DatabaseConnect

The JDBCService provides the implementation of the DatabaseConnect interface. All JDBC services extend from this class inheriting all methods related with the connection to the database.

See Also:
Serialized Form

Field Summary
protected  boolean autoCommit
          Keeps the commit criteria the JDBCTable service must follow.
protected  Hashtable connectionProperties
          Keeps the details of the connection being used by the service.
protected  java.sql.Connection databaseConnection
          Each JDBCService instance must have its own connection to the database, so when the application commits or rolls back any database changes only the changes made but that application are affected.
protected  java.lang.String databaseURL
          The database URL.
protected  java.lang.String dataSourceName
          Keeps the name of the DataSource factory object in the naming system.
protected  java.sql.DatabaseMetaData metaData
          Each JDBCService instance must have its own connection to the database, so when the application commits or rolls back any database changes only the changes made but that application are affected.
protected  java.lang.String password
          The user password to connect to the database.
protected  java.lang.String poolName
          Keeps the name of the pool when using the connection pooling of WebSphere 2.0
protected  java.lang.String sharedConnection
          Keeps the alias of the connection to the database that the service instance would like to share with another service
protected  java.lang.String user
          The user identification to connect to the database.
protected  boolean waitRetry
          Keeps the waitRetry attribute used by the WebSphere 2.0 connection pooling.
 
Fields inherited from class com.ibm.dse.base.Service
externalizer
 
Fields inherited from class com.ibm.dse.base.DSENotifier
handlersList, name
 
Constructor Summary
JDBCService()
          * This constructor creates a JDBCService object.
JDBCService(java.lang.String aName)
          This constructor creates a JDBCService object.
 
Method Summary
protected  void buildConnectionProperties()
          Build the hashtable containing all details needed to request the database connection.
 void connect(java.lang.String aDatabaseURL)
          Connects to the Database.
 void connect(java.lang.String aDatabaseURL, Context aContext)
          Connects to the Database.
 void connect(java.lang.String aUser, java.lang.String aPassword)
          Connects to the Database set in the DataSource definition, with user identification aUser and password aPassword.
 void connect(java.lang.String aUser, java.lang.String aPassword, Context aContext)
          Connects to the Database set in the DataSource definition, with user identification aUser and password aPassword.
 void connect(java.lang.String aDatabaseURL, java.lang.String aUser, java.lang.String aPassword)
          Connects to the Database in the URL aDatabaseURL, with user identification aUser and password aPassword.
 void connect(java.lang.String aDatabaseURL, java.lang.String aUser, java.lang.String aPassword, Context aContext)
          Connects to the Database in the URL aDatabaseURL, with user identification aUser and password aPassword.
 void disconnect()
          Closes the Database connection.
 boolean getAutoCommit()
          Returns the autoCommit attribute value.
protected  JDBCServicesConnectionManager getConnectionManager()
          Returns the connection manager instance used by the service to request the connections.
protected  Hashtable getConnectionProperties()
          Returns the Hashtable containing the connection details.
protected  java.sql.Connection getDatabaseConnection()
          Returns the database connection being used by the service.
 java.lang.String getDatabaseURL()
          Returns the databaseURL attribute value.
 java.lang.String getDataSourceName()
          Returns the dataSourceName attribute value.
 java.lang.String getPassword()
          Returns the password attribute value.
 java.lang.String getPoolName()
          Returns the poolName attribute value.
 java.lang.String getSharedConnection()
          Returns the sharedConnection attribute value
 java.lang.String getUser()
          Returns the user attribute value.
 boolean isConnected()
          Returns true if there is a connection to the database or false if there is not.
 boolean isWaitRetry()
          Returns the waitRetry attribute value.
 void requestConnectionToConnectionManager(Hashtable connProperties)
          Request the connection to the connection manager defined in the operation root context.
 void requestConnectionToConnectionManager(Hashtable connProperties, Context aContext)
          Request the connection to the connection manager defined in the operation provided context.
 void setAutoCommit(boolean b)
          Sets the autoCommit attribute to a boolean.
protected  void setConnectionManager(JDBCServicesConnectionManager newConnectionManager)
          Sets the connectionManager attribute value with the JDBCServicesConnectionManager instance.
protected  void setConnectionProperties(Hashtable newConnectionProperties)
          Sets the connectionProperties attribute value with the newConnectionProperties Hashtable instance.
protected  void setDatabaseConnection(java.sql.Connection newDatabaseConnection)
          Sets the databaseConnection attribute to the newDatabaseConnection Connection instance
 void setDatabaseURL(java.lang.String s)
          Sets the databaseURL attribute to the string provided as an argument.
 void setDataSourceName(java.lang.String newDataSourceName)
          Sets the dataSourceName attribute value to newDataSourceName.
 void setPassword(java.lang.String s)
          Sets the password attribute to the string provided as an argument.
 void setPoolName(java.lang.String newPoolName)
          Sets the poolName attribute value to newPoolName.
 void setSharedConnection(java.lang.String newSharedConnection)
          Sets the sharedConnection attribute value to newSharedConnection.
 void setUser(java.lang.String s)
          Sets the user attribute to the string provided as an argument.
 void setWaitRetry(boolean newWaitRetry)
          Sets the waitRetry attribute value to newWaitRetry.
 boolean verifyConnection()
          Checks for the database connection availability by calling the connection manager.
 
Methods inherited from class com.ibm.dse.base.Service
externalizer, getExternalizer, getTagName, initializeFrom, readExternal, readExternal, readObject, removeExternal, setExternalizer, terminate, toString, toStrings, toTags, writeExternal, writeExternal
 
Methods inherited from class com.ibm.dse.base.DSENotifier
addHandler, getHandlersList, getName, removeHandler, setName, signalEvent, signalEvent, signalEvent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

databaseConnection

protected java.sql.Connection databaseConnection
Each JDBCService instance must have its own connection to the database, so when the application commits or rolls back any database changes only the changes made but that application are affected.

autoCommit

protected boolean autoCommit
Keeps the commit criteria the JDBCTable service must follow.

databaseURL

protected java.lang.String databaseURL
The database URL. It is only used if the autoConnect attribute is set to true.

user

protected java.lang.String user
The user identification to connect to the database. It is only used if the autoConnect attribute is set to true.

password

protected java.lang.String password
The user password to connect to the database. It is only used if the autoConnect attribute is set to true.

poolName

protected java.lang.String poolName
Keeps the name of the pool when using the connection pooling of WebSphere 2.0

waitRetry

protected boolean waitRetry
Keeps the waitRetry attribute used by the WebSphere 2.0 connection pooling. If it is 'true', the servlet can wait for a connection to become available if no one is immediately available; if the connection does not become available after the wait period, the exception IBMConnMgrException will be thrown. If it is 'false', the exception will be thrown right away.

dataSourceName

protected java.lang.String dataSourceName
Keeps the name of the DataSource factory object in the naming system. Needed if the application will use any implementation of the JDBC interface for the connection pooling

metaData

protected java.sql.DatabaseMetaData metaData
Each JDBCService instance must have its own connection to the database, so when the application commits or rolls back any database changes only the changes made but that application are affected.

sharedConnection

protected java.lang.String sharedConnection
Keeps the alias of the connection to the database that the service instance would like to share with another service

connectionProperties

protected Hashtable connectionProperties
Keeps the details of the connection being used by the service.
Constructor Detail

JDBCService

public JDBCService()
* This constructor creates a JDBCService object.

JDBCService

public JDBCService(java.lang.String aName)
            throws java.io.IOException
This constructor creates a JDBCService object. It sets the service name to be aName.
Parameters:
aName - java.lang.String
Method Detail

buildConnectionProperties

protected void buildConnectionProperties()
Build the hashtable containing all details needed to request the database connection. It is called by the initializeFrom() method

connect

public void connect(java.lang.String aDatabaseURL)
             throws DSEInternalErrorException,
                    DSEInvalidRequestException,
                    DSESQLException,
                    DSEObjectNotFoundException,
                    DSEException
Connects to the Database. A logon panel is shown by the database system where you can enter the user identification and password, which are needed to run any operation to the requested database. If the user and password are mandatory to attempt the database connection (as it occurs when using the JDBC DB2 net driver) then an exception (DSESQLException) is thrown.
Specified by:
connect in interface DatabaseConnect
Parameters:
aDatabaseURL - java.lang.String, the database URL
Throws:
DSEInvalidRequestException - if the request is not valid
DSEInternalErrorException - if an internal program error occurs
DSESQLException - if an SQLException is caught
DSEObjectNotFoundException - if the JDBCServicesConnectionManager cannot be found
DSEException - if an exception is thrown when calling the pool of connections manager

connect

public void connect(java.lang.String aDatabaseURL,
                    Context aContext)
             throws DSEInternalErrorException,
                    DSEInvalidRequestException,
                    DSESQLException,
                    DSEObjectNotFoundException,
                    DSEException
Connects to the Database. A logon panel is shown by the database system where you can enter the user identification and password, which are needed to run any operation to the requested database. If the user and password are mandatory to attempt the database connection (as it occurs when using the JDBC DB2 net driver) then an exception (DSESQLException) is thrown.
Specified by:
connect in interface DatabaseConnect
Parameters:
aDatabaseURL - java.lang.String, the database URL
aContext - com.ibm.dse.base.Context, the context where the JDBCServiceConnectionManager is defined
Throws:
DSEInvalidRequestException - if the request is not valid
DSEInternalErrorException - if an internal program error occurs
DSESQLException - if an SQLException is caught
DSEObjectNotFoundException - if the JDBCServicesConnectionManager cannot be found
DSEException - if an exception is thrown when calling the pool of connections manager

connect

public void connect(java.lang.String aUser,
                    java.lang.String aPassword)
             throws DSEInternalErrorException,
                    DSEInvalidRequestException,
                    DSESQLException,
                    DSEObjectNotFoundException,
                    DSEException
Connects to the Database set in the DataSource definition, with user identification aUser and password aPassword. Can only be used if the connection is requested to a pool of connections implemented as a DataSource with the database URL specified as part of the DataSource definition
Specified by:
connect in interface DatabaseConnect
Parameters:
aUser - java.lang.String, the user identification
aPassword - java.lang.String, the user password
Throws:
DSEInvalidRequestException - if the request is not valid
DSEInternalErrorException - if an internal program error occurs
DSESQLException - if an SQLException is caught
DSEObjectNotFoundException - if the JDBCServicesConnectionManager cannot be found
DSEException - if an exception is thrown when calling the pool of connections manager

connect

public void connect(java.lang.String aUser,
                    java.lang.String aPassword,
                    Context aContext)
             throws DSESQLException,
                    DSEInvalidRequestException,
                    DSEInternalErrorException,
                    DSEObjectNotFoundException,
                    DSEException
Connects to the Database set in the DataSource definition, with user identification aUser and password aPassword. Can only be used if the connection is requested to a pool of connections implemented as a DataSource with the database URL specified as part of the DataSource definition
Specified by:
connect in interface DatabaseConnect
Parameters:
aUser - java.lang.String, the user identification
aPassword - java.lang.String, the user password
aContext - com.ibm.dse.base.Context, the context where the JDBCServiceConnectionManager is defined
Throws:
DSEInvalidRequestException - if the request is not valid
DSEInternalErrorException - if an internal program error occurs
DSESQLException - if an SQLException is caught
DSEObjectNotFoundException - if the JDBCServicesConnectionManager cannot be found
DSEException - if an exception is thrown when calling the pool of connections manager

connect

public void connect(java.lang.String aDatabaseURL,
                    java.lang.String aUser,
                    java.lang.String aPassword)
             throws DSESQLException,
                    DSEInvalidRequestException,
                    DSEInternalErrorException,
                    DSEObjectNotFoundException,
                    DSEException
Connects to the Database in the URL aDatabaseURL, with user identification aUser and password aPassword.
Specified by:
connect in interface DatabaseConnect
Parameters:
aDatabaseURL - java.lang.String, the database URL
aUser - java.lang.String, the user identification
aPassword - java.lang.String, the user password
Throws:
DSEInvalidRequestException - if the request is not valid
DSEInternalErrorException - if an internal program error occurs
DSESQLException - if an SQLException is caught
DSEObjectNotFoundException - if the JDBCServicesConnectionManager cannot be found
DSEException - if an exception is thrown when calling the pool of connections manager

connect

public void connect(java.lang.String aDatabaseURL,
                    java.lang.String aUser,
                    java.lang.String aPassword,
                    Context aContext)
             throws DSESQLException,
                    DSEInvalidRequestException,
                    DSEInternalErrorException,
                    DSEObjectNotFoundException,
                    DSEException
Connects to the Database in the URL aDatabaseURL, with user identification aUser and password aPassword.
Specified by:
connect in interface DatabaseConnect
Parameters:
aDatabaseURL - java.lang.String, the database URL
aUser - java.lang.String, the user identification
aPassword - java.lang.String, the user password
aContext - com.ibm.dse.base.Context, the context where the JDBCServiceConnectionManager is defined
Throws:
DSEInvalidRequestException - if the request is not valid
DSEInternalErrorException - if an internal program error occurs
DSESQLException - if an SQLException is caught
DSEObjectNotFoundException - if the JDBCServicesConnectionManager cannot be found
DSEException - if an exception is thrown when calling the pool of connections manager

disconnect

public void disconnect()
                throws DSEInvalidRequestException,
                       DSESQLException,
                       DSEException
Closes the Database connection.
Specified by:
disconnect in interface DatabaseConnect
Throws:
DSESQLException - if a SQLException occurs
DSEException - if an exception is thrown when calling the pool of connections manager
DSEInvalidRequestException - if the database connection is null

getAutoCommit

public boolean getAutoCommit()
Returns the autoCommit attribute value.
Returns:
boolean

getConnectionManager

protected JDBCServicesConnectionManager getConnectionManager()
Returns the connection manager instance used by the service to request the connections.
Returns:
com.ibm.dse.services.jdbc.JDBCServicesConnectionManager

getConnectionProperties

protected Hashtable getConnectionProperties()
Returns the Hashtable containing the connection details.
Returns:
com.ibm.dse.base.Hashtable

getDatabaseConnection

protected java.sql.Connection getDatabaseConnection()
Returns the database connection being used by the service.
Returns:
java.sql.Connection

getDatabaseURL

public java.lang.String getDatabaseURL()
Returns the databaseURL attribute value.
Specified by:
getDatabaseURL in interface DatabaseConnect
Returns:
java.lang.String

getDataSourceName

public java.lang.String getDataSourceName()
Returns the dataSourceName attribute value.
Specified by:
getDataSourceName in interface DatabaseConnect
Returns:
java.lang.String

getPassword

public java.lang.String getPassword()
Returns the password attribute value.
Returns:
java.lang.String

getPoolName

public java.lang.String getPoolName()
Returns the poolName attribute value.
Specified by:
getPoolName in interface DatabaseConnect
Returns:
java.lang.String

getSharedConnection

public java.lang.String getSharedConnection()
Returns the sharedConnection attribute value
Specified by:
getSharedConnection in interface DatabaseConnect
Returns:
java.lang.String

getUser

public java.lang.String getUser()
Returns the user attribute value.
Returns:
java.lang.String

isConnected

public boolean isConnected()
                    throws DSEInvalidRequestException,
                           DSEInternalErrorException,
                           DSESQLException,
                           DSEObjectNotFoundException,
                           DSEException
Returns true if there is a connection to the database or false if there is not. If the autoConnect attribute has been set to true, it creates its own connection to the database if not yet created.
Specified by:
isConnected in interface DatabaseConnect
Returns:
boolean
Throws:
DSEInvalidRequestException - if the request is not valid
DSEInternalErrorException - if an internal program error occurs
DSESQLException - if an SQL Exception is caught

isWaitRetry

public boolean isWaitRetry()
Returns the waitRetry attribute value.
Specified by:
isWaitRetry in interface DatabaseConnect
Returns:
boolean

requestConnectionToConnectionManager

public void requestConnectionToConnectionManager(Hashtable connProperties)
                                          throws DSEInvalidRequestException,
                                                 DSESQLException,
                                                 DSEObjectNotFoundException,
                                                 DSEException
Request the connection to the connection manager defined in the operation root context.
Parameters:
connProperties - com.ibm.dse.base.Hashtable, the connection properties
Throws:
DSEInvalidRequestException - if the request is not valid
DSESQLException - if an SQLException is caught
DSEObjectNotFoundException - if the JDBCServicesConnectionManager cannot be found
DSEException - if an exception is thrown when calling the pool of connections manager

requestConnectionToConnectionManager

public void requestConnectionToConnectionManager(Hashtable connProperties,
                                                 Context aContext)
                                          throws DSEInvalidRequestException,
                                                 DSESQLException,
                                                 DSEObjectNotFoundException,
                                                 DSEException
Request the connection to the connection manager defined in the operation provided context.
Parameters:
connProperties - com.ibm.dse.base.Hashtable, the connection properties
aContext - com.ibm.dse.base.Context, the Context where to look for the connection manager
Throws:
DSEInvalidRequestException - if the request is not valid
DSESQLException - if an SQLException is caught
DSEObjectNotFoundException - if the JDBCServicesConnectionManager cannot be found
DSEException - if an exception is thrown when calling the pool of connections manager

setAutoCommit

public void setAutoCommit(boolean b)
Sets the autoCommit attribute to a boolean.
Parameters:
boolean -  

setConnectionManager

protected void setConnectionManager(JDBCServicesConnectionManager newConnectionManager)
Sets the connectionManager attribute value with the JDBCServicesConnectionManager instance.
Parameters:
newConnectionManager - com.ibm.dse.services.jdbc.JDBCServicesConnectionManager

setConnectionProperties

protected void setConnectionProperties(Hashtable newConnectionProperties)
Sets the connectionProperties attribute value with the newConnectionProperties Hashtable instance.
Parameters:
newConnectionProperties - com.ibm.dse.base.Hashtable

setDatabaseConnection

protected void setDatabaseConnection(java.sql.Connection newDatabaseConnection)
Sets the databaseConnection attribute to the newDatabaseConnection Connection instance
Parameters:
newDatabaseConnection - java.sql.Connection

setDatabaseURL

public void setDatabaseURL(java.lang.String s)
Sets the databaseURL attribute to the string provided as an argument.
Specified by:
setDatabaseURL in interface DatabaseConnect
Parameters:
s - java.lang.String

setDataSourceName

public void setDataSourceName(java.lang.String newDataSourceName)
Sets the dataSourceName attribute value to newDataSourceName.
Specified by:
setDataSourceName in interface DatabaseConnect
Parameters:
newDataSourceName - java.lang.String

setPassword

public void setPassword(java.lang.String s)
Sets the password attribute to the string provided as an argument.
Parameters:
s - java.lang.String

setPoolName

public void setPoolName(java.lang.String newPoolName)
Sets the poolName attribute value to newPoolName.
Specified by:
setPoolName in interface DatabaseConnect
Parameters:
newPoolName - java.lang.String

setSharedConnection

public void setSharedConnection(java.lang.String newSharedConnection)
Sets the sharedConnection attribute value to newSharedConnection.
Specified by:
setSharedConnection in interface DatabaseConnect
Parameters:
newSharedConnection - java.lang.String

setUser

public void setUser(java.lang.String s)
Sets the user attribute to the string provided as an argument.
Parameters:
s - java.lang.String

setWaitRetry

public void setWaitRetry(boolean newWaitRetry)
Sets the waitRetry attribute value to newWaitRetry.
Specified by:
setWaitRetry in interface DatabaseConnect
Parameters:
newWaitRetry - boolean

verifyConnection

public boolean verifyConnection()
                         throws DSESQLException,
                                DSEException
Checks for the database connection availability by calling the connection manager.
Returns:
boolean
Throws:
DSESQLException - if an SQLException is caught
DSEException - if an exception is thrown when calling the pool of connections manager