|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.ibm.websphere.advanced.cm.factory.DataSourceFactory
DataSourceFactory is the factory used to create WebSphere DataSources programatically. This is the only supported mechanism for creating a DataSource outside of the systems management GUI.
Creating a DataSource requires creating a Properties object, setting the correct properties inside it, and creating the DataSource with the factory. Some properties are allowed on all databases; there are static attributes for each of those on this class. There are also properties that vary based on the database vendor; there are not static attributes for these properties. In the example which follows, a DataSource is created which specifies a description, user, and password which are all DataSource properties which always exist, and databaseName, which DB2 supports:
java.util.Properties props = new java.util.Properties(); props.setProperty(DataSourceFactory.NAME, "MyDataSource"); // required props.setProperty(DataSourceFactory.DATASOURCE_CLASS_NAME, // required "COM.ibm.db2.jdbc.DB2ConnectionPoolDataSource"); props.setProperty(DataSourceFactory.DESCRIPTION, "My great data source"); props.setProperty(DataSourceFactory.USER, "db2admin"); props.setProperty(DataSourceFactory.PASSWORD, "db2admin"); props.setProperty("databaseName", "SAMPLEDB"); javax.sql.DataSource dataSource = DataSourceFactory.getDataSource(props); DataSourceFactory.bindDataSource(dataSource);
Note that the NAME and DATASOURCE_CLASS_NAME properties are required.
After the DataSource is created, it is bound into JNDI. By default DataSources
are placed under the "jdbc" subcontext, but this can be overriden by the bind
method which takes a javax.naming.Context
parameter.
Inner Class Summary | |
static class |
DataSourceFactory.ResourceReferenceObjectFactory
A javax.naming.spi.ObjectFactory implementation for re-constituting data source references that are looked up in JNDI name space. |
Field Summary | |
static java.lang.String |
CONN_TIMEOUT
Specifies the maximum number of seconds that an application will wait for a connection from the pool before timing out and throwing a ConnectionTimeoutException to the application. |
static java.lang.String |
DATASOURCE_CLASS_NAME
The name of underlying database-vendor class used to communicate to the database; it must implement javax.sql.ConnectionPoolDataSource
or javax.sql.XADataSource This is a required property. |
static int |
DEFAULT_CONN_TIMEOUT
The default connection timeout in seconds. |
static java.lang.String |
DEFAULT_DATASOURCE_CONTEXT_NAME
The name of the JNDI subcontext where all DataSources are bound |
static java.lang.String |
DEFAULT_DESCRIPTION
The default description of the datasource. |
static boolean |
DEFAULT_DISABLE_2PHASE
The default setting for disabling 2-phase commit. |
static boolean |
DEFAULT_DISABLE_AUTO_CONN_CLEANUP
The default setting for disabling auto connection cleanup. |
static java.util.Hashtable |
DEFAULT_ERROR_MAP
The default error map for the datasource. |
static int |
DEFAULT_IDLE_TIMEOUT
The default idle timeout in seconds. |
static int |
DEFAULT_INFORMIX_LOCK_MODE_WAIT
The default value for informixLockModeWait . |
static int |
DEFAULT_MAX_POOL_SIZE
The default maximum number of connections in the connection pool. |
static java.lang.String |
DEFAULT_MERANT_OEM_ID
The default oemId for Merant. |
static int |
DEFAULT_MIN_POOL_SIZE
The default minimum number of connections in the connection pool. |
static int |
DEFAULT_ORPHAN_TIMEOUT
The default orphan timeout in seconds. |
static java.lang.String |
DEFAULT_PASSWORD
The default password to create connections with. |
static int |
DEFAULT_STATEMENT_CACHE_SIZE
The default prepared statement cache size. |
static java.lang.String |
DEFAULT_USER
The default user to create connections with. |
static java.lang.String |
DESCRIPTION
The description of the datasource. |
static java.lang.String |
DISABLE_2PHASE
If a datasource supports both 1-phase and 2-phase commit protocols, setting this property to "true" will disable 2-phase commit; by default 2-phase commit is always used with such datasources. |
static java.lang.String |
DISABLE_AUTO_CONN_CLEANUP
Specifies whether or not the connection will be closed at the end of a transaction. |
static java.lang.String |
ERROR_MAP
Not to be used by most applications. |
static java.lang.String |
IDLE_TIMEOUT
Specifies the number of seconds that a connection can remain free in the pool before the connection is marked to be cleansed from the pool. |
static java.lang.String |
INFORMIX_LOCK_MODE_WAIT
This property is only used for Informix at the moment. |
static java.lang.String |
MAX_POOL_SIZE
Specifies the maximum number of connections the connection pool can hold. |
static java.lang.String |
MIN_POOL_SIZE
Specifies the minimum number of connections the connection pool will hold. |
static java.lang.String |
NAME
The name of the DataSource; used to determine where the DataSource is bound into JNDI. |
static java.lang.String |
OEM_ID
For Merant only, the oemId to be set on the Connection object. |
static java.lang.String |
ORPHAN_TIMEOUT
Specifies the number of seconds that an application is allowed to hold an inactive connection. |
static java.lang.String |
PASSWORD
The password to create connections with if not supplied on the getConnection call; must be set if the user is also set. |
static java.lang.String |
STATEMENT_CACHE_SIZE
Specifies the number of cached preparedStatements to keep for an entire connection pool. |
static java.lang.String |
USER
The user to create connections with if not supplied on the getConnection call. |
Constructor Summary | |
DataSourceFactory()
|
Method Summary | |
static void |
bindDataSource(javax.naming.Context ctx,
javax.sql.DataSource ds)
Binds the given DataSource into caller provided JNDI Context. |
static void |
bindDataSource(javax.sql.DataSource ds)
Binds the given DataSource into the given JNDI Context. |
javax.sql.DataSource |
createJDBCDataSource(Attributes a)
Deprecated. As of Websphere Release 4.0 applications should use getDataSource(java.util.Properties) to create a DataSource |
javax.sql.DataSource |
createJTADataSource(Attributes a)
Deprecated. As of Websphere Release 4.0 applications should use getDataSource(java.util.Properties) to create a DataSource |
static javax.naming.Referenceable |
getBindableObject(java.util.Properties properties)
Constructs a representation of a data source that is suitable for binding into a JNDI name space. |
static javax.sql.DataSource |
getDataSource(com.ibm.ejs.cm.CMProperties cmProps)
Returns a datasource with the properties which are given. |
static javax.sql.DataSource |
getDataSource(java.util.Properties properties)
Returns a datasource with the properties which are given. |
static boolean |
isJTAEnabled(com.ibm.ejs.cm.CMProperties cmProps)
Determines if the datasource which is created from the given properties object is JTA-enabled or not. |
static boolean |
isJTAEnabled(java.util.Properties props)
Determines if the datasource which is created from the given properties object is JTA-enabled or not. |
static void |
rebindDataSource(javax.naming.Context ctx,
javax.sql.DataSource ds)
Rebinds the given DataSource into caller provided JNDI Context. |
static void |
rebindDataSource(javax.sql.DataSource ds)
Rebinds the given DataSource into the given JNDI Context. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final java.lang.String DEFAULT_DATASOURCE_CONTEXT_NAME
public static final java.lang.String NAME
The value of this constant is "name".
public static final java.lang.String DATASOURCE_CLASS_NAME
javax.sql.ConnectionPoolDataSource
or javax.sql.XADataSource
This is a required property.
The value of this constant is "dataSourceClassName".
public static final java.lang.String DESCRIPTION
The value of this constant is "description".
public static final java.lang.String DEFAULT_DESCRIPTION
The value of this constant is null
.
public static final java.lang.String MIN_POOL_SIZE
The value of this constant is "minimumPoolSize".
public static final int DEFAULT_MIN_POOL_SIZE
The value of this constant is 1.
public static final java.lang.String MAX_POOL_SIZE
The value of this constant is "maximumPoolSize".
public static final int DEFAULT_MAX_POOL_SIZE
The value of this constant is 10.
public static final java.lang.String CONN_TIMEOUT
The value of this constant is "connectionTimeout".
public static final int DEFAULT_CONN_TIMEOUT
The value of this constant is 180.
public static final java.lang.String IDLE_TIMEOUT
The value of this constant is "idleTimeout".
public static final int DEFAULT_IDLE_TIMEOUT
The value of this constant is 1800.
public static final java.lang.String ORPHAN_TIMEOUT
The value of this constant is "orphanTimeout".
public static final int DEFAULT_ORPHAN_TIMEOUT
The value of this constant is 1800.
public static final java.lang.String STATEMENT_CACHE_SIZE
The value of this constant is "statementCacheSize".
public static final int DEFAULT_STATEMENT_CACHE_SIZE
The value of this constant is 100.
public static final java.lang.String USER
getConnection
call.
The value of this constant is "user".
public static final java.lang.String DEFAULT_USER
The value of this constant is null
.
public static final java.lang.String PASSWORD
getConnection
call; must be set if the user is also set.
The value of this constant is "password".
public static final java.lang.String DEFAULT_PASSWORD
The value of this constant is null
.
public static final java.lang.String DISABLE_AUTO_CONN_CLEANUP
The value of this constant is "disableAutoConnectionCleanup".
public static final boolean DEFAULT_DISABLE_AUTO_CONN_CLEANUP
The value of this constant is false
.
public static final java.lang.String ERROR_MAP
The value of this constant is "errorMap".
public static final java.util.Hashtable DEFAULT_ERROR_MAP
The value of this constant is null
.
public static final java.lang.String OEM_ID
The value of this constant is "oemId".
public static final java.lang.String DEFAULT_MERANT_OEM_ID
The value of this constant is "WebSphereSequeLinkClient".
public static final java.lang.String INFORMIX_LOCK_MODE_WAIT
public static final int DEFAULT_INFORMIX_LOCK_MODE_WAIT
informixLockModeWait
.
The default value is 0
.
public static final java.lang.String DISABLE_2PHASE
The value of this constant is "disable2Phase".
public static final boolean DEFAULT_DISABLE_2PHASE
The value of this constant is false
.
Constructor Detail |
public DataSourceFactory()
Method Detail |
public javax.sql.DataSource createJDBCDataSource(Attributes a)
getDataSource(java.util.Properties)
to create a DataSource
a
- A properly-initialized Attributes object specifiying the
desired properties for the DataSource.public javax.sql.DataSource createJTADataSource(Attributes a)
getDataSource(java.util.Properties)
to create a DataSource
a
- A properly-initialized Attributes object specifiying the
desired properties for the DataSource.public static void bindDataSource(javax.sql.DataSource ds) throws javax.naming.NamingException
ds
- A DataSource instance obtained from createJDBCDataSource() or
createJTADataSource().javax.naming.NamingException
- bind failed.public static void bindDataSource(javax.naming.Context ctx, javax.sql.DataSource ds) throws javax.naming.NamingException
ctx
- A JNDI binding context.ds
- A DataSource instance obtained from createJDBCDataSource() or
createJTADataSource().javax.naming.NamingException
- bind failed.public static void rebindDataSource(javax.sql.DataSource ds) throws javax.naming.NamingException
ds
- A DataSource instance obtained from createJDBCDataSource() or
createJTADataSource().javax.naming.NamingException
- rebind failed.public static void rebindDataSource(javax.naming.Context ctx, javax.sql.DataSource ds) throws javax.naming.NamingException
ctx
- A JNDI binding context.ds
- A DataSource instance obtained from createJDBCDataSource() or
createJTADataSource().javax.naming.NamingException
- rebind failed.public static javax.naming.Referenceable getBindableObject(java.util.Properties properties)
properties
- - a Properties
object that describes
the attributes of the data source.Object
an object that is suitable for binding
into JNDI (e.g. a javax.naming.Reference).getDataSource for a list of properties
public static javax.sql.DataSource getDataSource(java.util.Properties properties) throws java.lang.ClassNotFoundException, CMFactoryException
DataSourceFactory.NAME
and
DataSourceFactory.DATASOURCE_CLASS_NAME
are required. If a
datasource with the same NAME has already been created in this JVM, it will
be returned. If a datasource with the same NAME has not yet been created
a new datasource is created and returned.
Note that all applications using the same datasource share a connection pool and so benefit from reusing connections.
cmProps
- a set of properties that defines the data sourcejava.lang.ClassNotFoundException
- if the DATASOURCE_CLASS_NAME property
cannot be loadedMissingRequiredPropertyException
- if a required property has not been providedCMFactoryException
- if any other problem occurredpublic static javax.sql.DataSource getDataSource(com.ibm.ejs.cm.CMProperties cmProps) throws java.lang.ClassNotFoundException, CMFactoryException
DataSourceFactory.NAME
and
DataSourceFactory.DATASOURCE_CLASS_NAME
are required. If a
datasource with the same NAME has already been created in this JVM, it will
be returned. If a datasource with the same NAME has not yet been created
a new datasource is created and returned.
Note that all applications using the same datasource share a connection pool and so benefit from reusing connections.
cmProps
- a set of properties that defines the data sourcejava.lang.ClassNotFoundException
- if the DATASOURCE_CLASS_NAME property
cannot be loadedMissingRequiredPropertyException
- if a required property has not been providedCMFactoryException
- if any other problem occurredpublic static boolean isJTAEnabled(java.util.Properties props) throws java.lang.ClassNotFoundException, CMFactoryException
props
- a list of Properties for the datasourcejava.lang.ClassNotFoundException
- if the class specified by the CMProperties'
dataSourceClassName could not be foundMissingRequiredPropertyException
- if a required property is missingCMFactoryException
- if any other CM exception occurspublic static boolean isJTAEnabled(com.ibm.ejs.cm.CMProperties cmProps) throws java.lang.ClassNotFoundException, CMFactoryException
cmProps
- a list of CMProperties for the datasourcejava.lang.ClassNotFoundException
- if the class specified by the CMProperties'
dataSourceClassName could not be foundMissingRequiredPropertyException
- if a required property is missingCMFactoryException
- if any other CM exception occurs
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |