7.3. Configuring JDBC DataSources
jboss-service.xml MBean services deployment descriptor using a XSL transform applied by the org.jboss.deployment.XSLSubDeployer included in the jboss-jca.sar deployment. The simplified configuration descriptor is deployed the same as other deployable components. The descriptor must be named using a *-ds.xml pattern in order to be recognized by the XSLSubDeployer.
*-ds.xml configuration deployment file is shown in Figure 7.5, “The simplified JCA DataSource configuration descriptor top-level schema elements”.

Figure 7.5. The simplified JCA DataSource configuration descriptor top-level schema elements
- mbean: Any number mbean elements may be specified to define MBean services that should be included in the
jboss-service.xmldescriptor that results from the transformation. This may be used to configure services used by the datasources. - no-tx-datasource: This element is used to specify the (
org.jboss.resource.connectionmanager)NoTxConnectionManagerservice configuration.NoTxConnectionManageris a JCA connection manager with no transaction support. Theno-tx-datasourcechild element schema is given in Figure 7.6, “The non-transactional DataSource configuration schema”. - local-tx-datasource: This element is used to specify the (
org.jboss.resource.connectionmanager)LocalTxConnectionManagerservice configuration.LocalTxConnectionManagerimplements aConnectionEventListenerthat implementsXAResourceto manage transactions through the transaction manager. To ensure that all work in a local transaction occurs over the sameManagedConnection, it includes a xid toManagedConnectionmap. When a Connection is requested or a transaction started with a connection handle in use, it checks to see if aManagedConnectionalready exists enrolled in the global transaction and uses it if found. Otherwise, a freeManagedConnectionhas itsLocalTransactionstarted and is used. Thelocal-tx-datasourcechild element schema is given in Figure 7.7, “The non-XA DataSource configuration schema” - xa-datasource: This element is used to specify the (
org.jboss.resource.connectionmanager)XATxConnectionManagerservice configuration.XATxConnectionManagerimplements aConnectionEventListenerthat obtains theXAResourceto manage transactions through the transaction manager from the adaptorManagedConnection. To ensure that all work in a local transaction occurs over the sameManagedConnection, it includes a xid toManagedConnectionmap. When aConnectionis requested or a transaction started with a connection handle in use, it checks to see if aManagedConnectionalready exists enrolled in the global transaction and uses it if found. Otherwise, a freeManagedConnectionhas itsLocalTransactionstarted and is used. Thexa-datasourcechild element schema is given in Figure 7.8, “The XA DataSource configuration schema”. - ha-local-tx-datasource: This element is identical to
local-tx-datasource, with the addition of the datasource failover capability allowing JBoss to failover to an alternate database in the event of a database failure. - ha-xa-datasource: This element is identical to
xa-datasource, with the addition of the datasource failover capability allowing JBoss to failover to an alternate database in the event of a database failure.

Figure 7.6. The non-transactional DataSource configuration schema

Figure 7.7. The non-XA DataSource configuration schema

Figure 7.8. The XA DataSource configuration schema

Figure 7.9. The schema for the experimental non-XA DataSource with failover

Figure 7.10. The schema for the experimental XA Datasource with failover
- jndi-name: The JNDI name under which the
DataSourcewrapper will be bound. Note that this name is relative to thejava:/context, unlessuse-java-contextis set to false.DataSourcewrappers are not usable outside of the server VM, so they are normally bound under thejava:/, which isn't shared outside the local VM. - use-java-context: If this is set to false the the datasource will be bound in the global JNDI context rather than the
java:context. - user-name: This element specifies the default username used when creating a new connection. The actual username may be overridden by the application code
getConnectionparameters or the connection creation context JAAS Subject. - password: This element specifies the default password used when creating a new connection. The actual password may be overridden by the application code
getConnectionparameters or the connection creation context JAAS Subject. - application-managed-security: Specifying this element indicates that connections in the pool should be distinguished by application code supplied parameters, such as from
getConnection(user, pw). - security-domain: Specifying this element indicates that connections in the pool should be distinguished by JAAS Subject based information. The content of the
security-domainis the name of the JAAS security manager that will handle authentication. This name correlates to the JAASlogin-config.xmldescriptorapplication-policy/nameattribute. - security-domain-and-application: Specifying this element indicates that connections in the pool should be distinguished both by application code supplied parameters and JAAS Subject based information. The content of the
security-domainis the name of the JAAS security manager that will handle authentication. This name correlates to the JAASlogin-config.xmldescriptorapplication-policy/nameattribute. - min-pool-size: This element specifies the minimum number of connections a pool should hold. These pool instances are not created until an initial request for a connection is made. This default to 0.
- max-pool-size: This element specifies the maximum number of connections for a pool. No more than the
max-pool-sizenumber of connections will be created in a pool. This defaults to 20. - blocking-timeout-millis: This element specifies the maximum time in milliseconds to block while waiting for a connection before throwing an exception. Note that this blocks only while waiting for a permit for a connection, and will never throw an exception if creating a new connection takes an inordinately long time. The default is 30000.
- idle-timeout-minutes: This element specifies the maximum time in minutes a connection may be idle before being closed. The actual maximum time depends also on the
IdleRemoverscan time, which is 1/2 the smallest idle-timeout-minutes of any pool. - new-connection-sql: This is a SQL statement that should be executed when a new connection is created. This can be used to configure a connection with database specific settings not configurable via connection properties.
- check-valid-connection-sql: This is a SQL statement that should be run on a connection before it is returned from the pool to test its validity to test for stale pool connections. An example statement could be:
select count(*) from x. - exception-sorter-class-name: This specifies a class that implements the
org.jboss.resource.adapter.jdbc.ExceptionSorterinterface to examine database exceptions to determine whether or not the exception indicates a connection error. Current implementations include:- org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter
- org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter
- org.jboss.resource.adapter.jdbc.vendor.SybaseExceptionSorter
- org.jboss.resource.adapter.jdbc.vendor.InformixExceptionSorte
- valid-connection-checker-class-name: This specifies a class that implements the
org.jboss.resource.adapter.jdbc.ValidConnectionCheckerinterface to provide aSQLException isValidConnection(Connection e)method that is called with a connection that is to be returned from the pool to test its validity. This overrides thecheck-valid-connection-sqlwhen present. The only provided implementation isorg.jboss.resource.adapter.jdbc.vendor.OracleValidConnectionChecker. - track-statements: This boolean element specifies whether to check for unclosed statements when a connection is returned to the pool. If true, a warning message is issued for each unclosed statement. If the log4j category
org.jboss.resource.adapter.jdbc.WrappedConnectionhas trace level enabled, a stack trace of the connection close call is logged as well. This is a debug feature that can be turned off in production. - prepared-statement-cache-size: This element specifies the number of prepared statements per connection in an LRU cache, which is keyed by the SQL query. Setting this to zero disables the cache.
- depends: The
dependselement specifies the JMXObjectNamestring of a service that the connection manager services depend on. The connection manager service will not be started until the dependent services have been started. - type-mapping: This element declares a default type mapping for this datasource. The type mapping should match a
type-mapping/nameelement fromstandardjbosscmp-jdbc.xml.
no-tx-datasource and local-tx-datasource include:
- connection-url: This is the JDBC driver connection URL string, for example,
jdbc:hsqldb:hsql://localhost:1701. - driver-class: This is the fully qualified name of the JDBC driver class, for example,
org.hsqldb.jdbcDriver. - connection-property: The
connection-propertyelement allows you to pass in arbitrary connection properties to thejava.sql.Driver.connect(url, props)method. Eachconnection-propertyspecifies a string name/value pair with the property name coming from the name attribute and the value coming from the element content.
local-tx-datasource and xa-datasource are:
- transaction-isolation: This element specifies the
java.sql.Connectiontransaction isolation level to use. The constants defined in the Connection interface are the possible element content values and include:- TRANSACTION_READ_UNCOMMITTED
- TRANSACTION_READ_COMMITTED
- TRANSACTION_REPEATABLE_READ
- TRANSACTION_SERIALIZABLE
- TRANSACTION_NONE
- no-tx-separate-pools: The presence of this element indicates that two connection pools are required to isolate connections used with JTA transaction from those used without a JTA transaction. The pools are lazily constructed on first use. Its use case is for Oracle (and possibly other vendors) XA implementations that don't like using an XA connection with and without a JTA transaction.
xa-datasource child elements are:
- track-connection-by-tx: Specifying a true value for this element makes the connection manager keep an xid to connection map and only put the connection back in the pool when the transaction completes and all the connection handles are closed or disassociated (by the method calls returning). As a side effect, we never suspend and resume the xid on the connection's
XAResource. This is the same connection tracking behavior used for local transactions.The XA spec implies that any connection may be enrolled in any transaction using any xid for that transaction at any time from any thread (suspending other transactions if necessary). The original JCA implementation assumed this and aggressively delisted connections and put them back in the pool as soon as control left the EJB they were used in or handles were closed. Since some other transaction could be using the connection the next time work needed to be done on the original transaction, there is no way to get the original connection back. It turns out that mostXADataSourcedriver vendors do not support this, and require that all work done under a particular xid go through the same connection. - xa-datasource-class: The fully qualified name of the
javax.sql.XADataSourceimplementation class, for example,com.informix.jdbcx.IfxXADataSource. - xa-datasource-property: The
xa-datasource-propertyelement allows for specification of the properties to assign to theXADataSourceimplementation class. Each property is identified by the name attribute and the property value is given by thexa-datasource-propertyelement content. The property is mapped onto theXADataSourceimplementation by looking for a JavaBeans style getter method for the property name. If found, the value of the property is set using the JavaBeans setter with the element text translated to the true property type using thejava.beans.PropertyEditorfor the type. - isSameRM-override-value: A boolean flag that allows one to override the behavior of the
javax.transaction.xa.XAResource.isSameRM(XAResource xaRes)method behavior on the XA managed connection. If specified, this value is used unconditionally as theisSameRM(xaRes)return value regardless of thexaResparameter.
ha-xa-datasource and ha-local-tx-datasource are:
- url-delimeter: This element specifies a character used to separate multiple JDBC URLs.
- url-property: In the case of XA datasources, this property specifies the name of the
xa-datasource-propertythat contains the list of JDBC URLs to use.
JBOSS_DIST/docs/examples/jca directory. Current example configurations include:
- asapxcess-jb3.2-ds.xml
- cicsr9s-service.xml
- db2-ds.xml
- db2-xa-ds.xml
- facets-ds.xml
- fast-objects-jboss32-ds.xml
- firebird-ds.xml
- firstsql-ds.xml
- firstsql-xa-ds.xml
- generic-ds.xml
- hsqldb-ds.xml
- informix-ds.xml
- informix-xa-ds.xml
- jdatastore-ds.xml
- jms-ds.xml
- jsql-ds.xml
- lido-versant-service.xml
- mimer-ds.xml
- mimer-xa-ds.xml
- msaccess-ds.xml
- mssql-ds.xml
- mssql-xa-ds.xml
- mysql-ds.xml
- oracle-ds.xml
- oracle-xa-ds.xml
- postgres-ds.xml
- sapdb-ds.xml
- sapr3-ds.xml
- solid-ds.xml
- sybase-ds.xml

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.