|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.ibm.db.DatabaseConnection
DatabaseConnection represents a connection to the database.
Statement
, Serialized FormField Summary | |
protected DatabaseConnectionAfterListener |
aDatabaseConnectionAfterListener
|
protected DatabaseConnectionBeforeListener |
aDatabaseConnectionBeforeListener
|
protected DatabaseConnection |
connection
|
private static java.lang.String |
copyright
|
protected java.lang.String |
databaseName
|
private boolean |
externallyManaged
|
protected boolean |
fieldAutoCommit
|
protected DatabaseConnectionSpec |
fieldConnectionSpec
|
protected boolean |
fieldPromptUID
|
protected int |
fieldTransactionIsolation
|
static int |
POOL_TYPE_NONE
Do not use connection pools |
static int |
POOL_TYPE_WEBSPHERE
Use WebSphere connection pools |
protected java.beans.PropertyChangeSupport |
propertyChange
|
(package private) static long |
serialVersionUID
|
protected boolean |
supportsMixedCaseIdentifiers
|
protected boolean |
supportsMixedCaseQuotedIdentifiers
|
protected boolean |
supportsPositionedDelete
|
protected boolean |
supportsPositionedUpdate
|
static int |
TRANSACTION_DEFAULT
Use default transaction isolation level for database. |
Constructor Summary | |
|
DatabaseConnection()
Constructs a new DatabaseConnection. |
|
DatabaseConnection(java.sql.Connection jdbcConnection)
Constructs a new DatabaseConnection with the specified JDBC connection. |
protected |
DatabaseConnection(DatabaseConnectionSpec connectionSpec)
Constructs a new DatabaseConnection with the specified DatabaseConnectionSpec. |
Method Summary | |
void |
addDatabaseConnectionAfterListener(DatabaseConnectionAfterListener listener)
Adds a listener to the DatabaseConnectionAfter event set. |
void |
addDatabaseConnectionBeforeListener(DatabaseConnectionBeforeListener listener)
Adds a listener to the DatabaseConnectionBefore event set. |
void |
commit()
Commits changes to the database. |
boolean |
connect()
Attempts to establish a connection to the database. |
void |
disconnect()
Closes the JDBC connection for further use by this DatabaseConnection object. |
protected void |
fireAboutToCommit(DataEvent event)
Method to support listener events. |
protected void |
fireAboutToConnect(DataEvent event)
Method to support listener events. |
protected void |
fireAboutToDisconnect(DataEvent event)
Method to support listener events. |
protected void |
fireAboutToRollback(DataEvent event)
Method to support listener events. |
protected void |
fireCommitted(DataEvent event)
Method to support listener events. |
protected void |
fireConnected(DataEvent event)
Method to support listener events. |
protected void |
fireDisconnected(DataEvent event)
Method to support listener events. |
protected void |
fireRolledBack(DataEvent event)
Method to support listener events. |
boolean |
getAutoCommit()
Returns true if changes to the database are automatically committed as soon as they are made. |
protected DatabaseConnection |
getConnection()
Returns the underlying com.ibm.db.base.DatabaseConnection associated with this DatabaseConnection. |
java.lang.String |
getConnectionAlias()
Returns the alias name that is associated with this DatabaseConnection. |
int |
getConnectionPoolType()
Deprecated. Use setJndiDataSource() to use a WebSphere datasource to make a connection. |
DatabaseConnectionSpec |
getConnectionSpec()
Returns the DatabaseConnectionSpec associated with this DatabaseConnection. |
java.lang.String |
getDataSourceName()
Returns the URL used when establishing a connection to the database. |
java.lang.String |
getDriverName()
Returns the JDBC driver used when establishing a connection to the database. |
java.lang.String |
getInitialContextFactory()
Returns the InitialContextFactory used to locate the JDBC 2.0 DataSource. |
java.sql.DatabaseMetaData |
getJDBCMetaData()
Returns the java.sql.DatabaseMetaData associated with this DatabaseConnection. |
java.lang.String |
getJndiDataSource()
Returns the name of the JDBC 2.0 DataSource used to obtain a connection to the database. |
private java.lang.String |
getPassword()
Returns the password used when establishing a connection to the database. |
boolean |
getPromptUID()
Returns true if before a database connection is made, a logon dialog will be displayed to obtain the userid and password for the connection. |
java.util.Properties |
getProperties()
Returns the properties for this DatabaseConnection. |
java.lang.String |
getProviderURL()
Returns the Provider URL for the InitialContextFactory. |
int |
getTransactionIsolation()
Returns the current setting for the transacation isolation level for this DatabaseConnection. |
java.lang.String |
getUserID()
Returns the userid used when establishing a connection to the database. |
protected static void |
handleSQLException(java.sql.SQLException ex)
This method was created by a SmartGuide. |
private void |
initialize()
Initiazes the class. |
boolean |
isConnected()
Returns true if the DatabaseConnection is associated with an active JDBC connection. |
boolean |
isExternallyManaged()
Returns true if the associated JDBC connection is considered to be externally managed. |
protected void |
obtainConnectionMetaDataInfo()
This method was created in VisualAge. |
private void |
readObject(java.io.ObjectInputStream in)
This method was reads in the serialized object and restores the following static/transient fields: propertyChange - contains a reference to a PropertyChangeSupport instance. |
void |
removeDatabaseConnectionAfterListener(DatabaseConnectionAfterListener listener)
Removes a listener from the DatabaseConnectionAfter event set. |
void |
removeDatabaseConnectionBeforeListener(DatabaseConnectionBeforeListener listener)
Removes a listener from the DatabaseConnectionBefore event set. |
void |
rollback()
Rollback changes in the database. |
void |
setAutoCommit(boolean autoCommit)
If true, any changes to the database are automatically committed as soon as they are made. |
void |
setConnectionAlias(java.lang.String alias)
Sets the connection alias name used when a connect is invoked on
this DatabaseConnection. |
void |
setConnectionPoolType(int aConnectionPoolType)
Deprecated. Use setJndiDataSource() to use a WebSphere datasource to make a connection. |
protected void |
setConnectionSpec(DatabaseConnectionSpec connectionSpec)
Associates a DatabaseConnectionSpec with this DatabaseConnection. |
void |
setDataSourceName(java.lang.String dataSourceName)
Sets the URL used when establishing a connection to the database. |
void |
setDriverName(java.lang.String driverName)
Sets the JDBC driver used when establishing a connection to the database. |
void |
setInitialContextFactory(java.lang.String initialContextFactory)
Sets the InitialContextFactory used to find the DataSource specified in the JndiDataSource property. |
void |
setJndiDataSource(java.lang.String dataSource)
Sets the JNDI DataSource used when establishing a connection to the database. |
void |
setPassword(java.lang.String password)
Sets the password used when establishing a connection to the database. |
void |
setPassword(java.lang.String password,
boolean decode)
Decodes the specified password if requested, and sets the password used when establishing a connection to the database. |
void |
setPromptUID(boolean promptUID)
If true, before a database connection is made, a logon dialog will be displayed to obtain the userid and password for the connection. |
void |
setProperties(java.util.Properties properties)
Sets the properties to use when establishing a connection. |
void |
setProviderURL(java.lang.String providerURL)
Sets the Provider URL for the InitialContext factory. |
void |
setTransactionIsolation(int isolation)
Sets the transaction isolation level for the connection. |
void |
setUserID(java.lang.String userid)
Sets the userid used when establishing a connection to the database. |
Methods inherited from class java.lang.Object |
|
Field Detail |
protected DatabaseConnectionSpec fieldConnectionSpec
protected boolean fieldAutoCommit
protected boolean fieldPromptUID
protected int fieldTransactionIsolation
protected transient DatabaseConnection connection
protected transient java.beans.PropertyChangeSupport propertyChange
protected transient DatabaseConnectionBeforeListener aDatabaseConnectionBeforeListener
protected transient DatabaseConnectionAfterListener aDatabaseConnectionAfterListener
private boolean externallyManaged
protected transient java.lang.String databaseName
protected transient boolean supportsPositionedUpdate
protected transient boolean supportsPositionedDelete
protected transient boolean supportsMixedCaseIdentifiers
protected transient boolean supportsMixedCaseQuotedIdentifiers
public static final int POOL_TYPE_NONE
public static final int POOL_TYPE_WEBSPHERE
public static final int TRANSACTION_DEFAULT
static final long serialVersionUID
private static final java.lang.String copyright
Constructor Detail |
public DatabaseConnection()
protected DatabaseConnection(DatabaseConnectionSpec connectionSpec)
connectionSpec
- the connectionSpec for the connectionDatabaseConnectionSpec
public DatabaseConnection(java.sql.Connection jdbcConnection) throws DataException
connect
method against an externally managed DatabaseConnection.
When you issue the disconnect
method against an externally managed
DatabaseConnection, the JDBC connection remains open, but is closed for use by
this DatabaseConnection object.jdbcConnection
- open java.sql.ConnectionisExternallyManaged()
Method Detail |
public void addDatabaseConnectionAfterListener(DatabaseConnectionAfterListener listener)
connect
,
disconnect
, commit
, or rollback
.listener
- DatabaseConnectionAfterListenerDatabaseConnectionAfterListener
,
removeDatabaseConnectionAfterListener(com.ibm.db.DatabaseConnectionAfterListener)
public void addDatabaseConnectionBeforeListener(DatabaseConnectionBeforeListener listener)
connect
,
disconnect
, commit
, or rollback
.listener
- DatabaseConnectionBeforeListenerDatabaseConnectionBeforeListener
,
removeDatabaseConnectionBeforeListener(com.ibm.db.DatabaseConnectionBeforeListener)
public void commit() throws DataException
The events aboutToCommit
and committed
are triggered by
this method.
setAutoCommit(boolean)
,
rollback()
public boolean connect() throws DataException
If a connection already exists for the specified connectionAlias, no new connection is made and the existing connection is shared. If the value of connectionAlias is null, a new connection is always established.
If a JndiDataSource was specified, the DataSource object is obtained from the specified name server and used to obtain a connection. Otherwise, the connection is obtained from the JDBC DriverManager using the URL that was specified in the DataSourceName property. The JDBC driver specified by DriverName is registered prior to attempting to make the connection.
If a URL and DriverName are specified and the connectionPoolType property is POOL_TYPE_WEBSPHERE, the connection is obtained from the WebSphere 2.0 style connection pools. If no connection pool currently exists, a new connection pool with default settings is created based on the specified URL. Then the connection is obtained from the new pool. NOTE: This is a deprecated interface. To use WebSphere 3.0 style connection pools, you should specifiy the WebSphere DataSource name in the JndiDataSource property.
If the connectionPoolType property is POOL_TYPE_NONE, a new connection is obtained directly from the JDBC DriverManager.
The events aboutToConnect
and connected
are triggered by
this method.
disconnect()
,
setConnectionPoolType(int)
public void disconnect() throws DataException
If the connection is externally managed or is being shared by another DatabaseConnection object, the association between the JDBC connection and the DatabaseConnection object is removed, but the JDBC connection itself is not closed.
If the connection was obtained from a Webshpere 2.0 connection pool and is not externally managed, the JDBC connection is simply released back to the connection pool.
If the connection is not externally managed, is not from a Webshpere 2.0 connection pool, and is not being shared with another DatabaseConnection object, the JDBC connection is closed, releasing the JDBC resources associated with the connection.
If a connection was obtained from a DataSource, closing the connection may simply return the connection to a connection pool, if connection pooling is implemented by the DataSource.
The events aboutToDisconnect
and disconnected
are triggered by
this method.
connect()
,
setConnectionPoolType(int)
protected void fireAboutToCommit(DataEvent event)
event
- DataEventprotected void fireAboutToConnect(DataEvent event)
event
- DataEventprotected void fireAboutToDisconnect(DataEvent event)
event
- DataEventprotected void fireAboutToRollback(DataEvent event)
event
- DataEventprotected void fireCommitted(DataEvent event)
event
- DataEventprotected void fireConnected(DataEvent event)
event
- DataEventprotected void fireDisconnected(DataEvent event)
event
- DataEventprotected void fireRolledBack(DataEvent event)
event
- DataEventpublic boolean getAutoCommit()
setAutoCommit(boolean)
protected DatabaseConnection getConnection()
#setConnection
public java.lang.String getConnectionAlias()
setConnectionAlias(java.lang.String)
public int getConnectionPoolType()
setConnectionPoolType(int)
,
setJndiDataSource(java.lang.String)
public DatabaseConnectionSpec getConnectionSpec()
DatabaseConnectionSpec
public java.lang.String getDataSourceName()
setDataSourceName(java.lang.String)
public java.lang.String getDriverName()
setDriverName(java.lang.String)
public java.lang.String getInitialContextFactory()
setInitialContextFactory(java.lang.String)
public java.sql.DatabaseMetaData getJDBCMetaData() throws DataException
public java.lang.String getJndiDataSource()
setJndiDataSource(java.lang.String)
private java.lang.String getPassword()
setPassword(java.lang.String)
public boolean getPromptUID()
setPromptUID(boolean)
public java.util.Properties getProperties()
setProperties(java.util.Properties)
,
setUserID(java.lang.String)
,
setPassword(java.lang.String)
public java.lang.String getProviderURL()
setProviderURL(java.lang.String)
public int getTransactionIsolation()
setTransactionIsolation(int)
public java.lang.String getUserID()
setUserID(java.lang.String)
protected static void handleSQLException(java.sql.SQLException ex) throws DataException
private void initialize()
public boolean isConnected() throws DataException
public boolean isExternallyManaged()
connect
is not allowed for an externally managed
connection. When you issue the disconnect
method for an externally managed
connection, the JDBC connection remains open, but is closed for use by
this DatabaseConnection object.protected void obtainConnectionMetaDataInfo() throws DataException
private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException
in
- ObjectInputStreampublic void removeDatabaseConnectionAfterListener(DatabaseConnectionAfterListener listener)
connect
,
disconnect
, commit
, or rollback
.listener
- DatabaseConnectionAfterListenerDatabaseConnectionAfterListener
,
addDatabaseConnectionAfterListener(com.ibm.db.DatabaseConnectionAfterListener)
public void removeDatabaseConnectionBeforeListener(DatabaseConnectionBeforeListener listener)
connect
,
disconnect
, commit
, or rollback
.listener
- DatabaseConnectionBeforeListenerDatabaseConnectionBeforeListener
,
addDatabaseConnectionBeforeListener(com.ibm.db.DatabaseConnectionBeforeListener)
public void rollback() throws DataException
The events aboutToRollback
and rolledBack
are triggered by
this method.
commit()
,
setAutoCommit(boolean)
public void setAutoCommit(boolean autoCommit) throws DataException
commit
is issued.
The default value of this property is true.
autoCommit
- true - automatically commit changes;
false - don't automatically commit changesgetAutoCommit()
public void setConnectionAlias(java.lang.String alias)
connect
is invoked on
this DatabaseConnection. If a connection to the database has already been
established for this alias name, no new connection is made and the existing
connection is shared.alias
- the alias name for the connectiongetConnectionAlias()
public void setConnectionPoolType(int aConnectionPoolType) throws DataException
connect
method the connection is obtained
from the WebSphere 2.0 connection pools. If no connection pool currently exists, a new
connection pool with default settings is created based on the specified URL, and the
connection is obtained from the new pool.
If the connectionPoolType property is POOL_TYPE_NONE, a new connection is obtained directly from the JDBC DriverManager or from a DataSource.
This interface is deprecated. You should use setJndiDataSource() to use DataSources to make a database connection.
aConnectionPoolType
- POOL_TYPE_NONE indicates WebSphere 2.0 connection
pools are not used. POOL_TYPE_WEBSPHERE indicates WebSphere 2.0 connection pools are used,
if no JndiDataSourceName was specified.getConnectionPoolType()
,
setJndiDataSource(java.lang.String)
protected void setConnectionSpec(DatabaseConnectionSpec connectionSpec)
connectionSpec
- the associated DatabaseConnectionSpecgetConnectionSpec()
public void setDataSourceName(java.lang.String dataSourceName)
jdbc:subprotocol:subname
, where
subprotocol
and subname
identify the data source for
the connection. The value of subprotocol
depends on the JDBC driver used.
For example, for the DB2 application JDBC driver, subprotocol
is
db2
; for the Oracle thin driver, subprotocol
is thin
.
The value of subname
depends on the subprotocol
specification;
the subname
value provides information to locate the database. For example,
a full URL specification for an application accessing a local database named sample
through the DB2 application JDBC driver is: jdbc:db2:sample
.
By comparison, a full URL specification for an applet using the Sybase jConnect driver
to access a database named sample, on a remote server named myserv, through port
number 88 on the internet is: jdbc:sybase:Tds:myserver:88/sample
.
Here, the subname value includes the database server name, port number, and database name.
This property is only used if the JndiDataSource property is null. If the JndiDataSource property is not null, then this field is ignored and the connection is obtained using the DataSource specified in the JndiDataSource property.
dataSourceName
- The URL for the connection.getDataSourceName()
public void setDriverName(java.lang.String driverName)
COM.ibm.db2.jdbc.appDB2Driver
.
This property is only used if the JndiDataSource property is null. If the JndiDataSource property is not null, then this field is ignored and the connection is obtained using the DataSource specified in the JndiDataSource property.
driverName
- the JDBC driver name for the connectiongetDriverName()
public void setInitialContextFactory(java.lang.String initialContextFactory)
initialContextFactory
- The InitialContextFactory to used find the DataSource.getInitialContextFactory()
public void setJndiDataSource(java.lang.String dataSource)
dataSource
- The JNDI DataSource to used to obtain the connectiongetJndiDataSource()
public void setPassword(java.lang.String password)
password
- the password for the connectionsetPromptUID(boolean)
public void setPassword(java.lang.String password, boolean decode) throws DataException
This method is provided for use by VisualAge for Java in its generated code. Because the
encoding/decoding algorithm is proprietary, you should use the method with signature
setPassword(String)
in code that you write yourself.
password
- the password for the connectiondecode
- true - decode password; false - password
is not encoded.setPromptUID(boolean)
public void setPromptUID(boolean promptUID)
The default value of this property is false.
promptUID
- true -display logon dialog;
false - don't display logon dialoggetPromptUID()
public void setProperties(java.util.Properties properties)
properties
- the properties for the connectiongetProperties()
,
setPassword(java.lang.String)
,
setUserID(java.lang.String)
public void setProviderURL(java.lang.String providerURL)
providerURL
- The provider URL for the InitialContextFactory.getProviderURL()
public void setTransactionIsolation(int isolation) throws DataException
isolation
- the transaction isolation levelgetTransactionIsolation()
public void setUserID(java.lang.String userid)
userid
- the userid for the connectiongetUserID()
,
setPromptUID(boolean)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |