Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

DataSources can either be runtime- or application-scoped. Runtime-scoped DataSources are defined as part of the runtime system configuration and remain for the duration of the runtime instance. Application-scoped DataSources are defined as part of a composite and are activated when the composite is deployed and de-activated when it is undeployed.

Runtime DataSource Configuration

To configure runtime data sources, include the appropriate JDBC drivers in the runtime extensions/datasource directory, creating it if needed. Next, you will need to update the runtime systemConfig.xml, adding a <datasource> entry. The following demonstrates how to configure a connection pool using the non-XA MySQL driver:

Code Block
xml
xml

<datasources>
   <datasource name="LoanApplicationDS" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost/bigbank" username="bigbank" password="bigbank">
      <URL>jdbc:h2:mem:MessageDS;DB_CLOSE_DELAY=-1</URL>
      <minPoolSize>5</minPoolSize>
      <maxPoolSize>10</maxPoolSize>
   </datasource>
</datasources>

...

If a data source is an XA datasource, driver-specific properties can be configured by using sub-elements of <datasource> in the format:
<property_name>property_value</property_name>

Application DataSource Configuration

Application data sources can be configured in a composite using the Fabric3 <datasources> element, as shown in the following:

Code Block
xml
xml

<composite xmlns:f3="urn:fabric3.org"..>
   <f3:datasources>
      <datasource name="MessageDS" driver="org.h2.jdbcx.JdbcDataSource" type="xa">
         <URL>jdbc:h2:mem:MessageDS;DB_CLOSE_DELAY=-1</URL>
         <minPoolSize>5</minPoolSize>
         <maxPoolSize>10</maxPoolSize>
      </datasource>
   </f3:datasources>
</composite>

...

Note that it is sometimes useful to configure a datasource so that it can be referenced with multiple aliases. For example, an application may contain multiple JPA persistence units which refer to individual datasources. As an optimization, a single datasource can be configured for all of the individual datasource references, allowing JPA/Hibernate operations to be performed using a single XA transactional resource. The following is an example of how to configure a datasource with aliases:

Code Block
xml
xml

<composite xmlns:f3-other="urn:fabric3.org"..>
   <f3-other:datasources>
      <datasource name="MessageDS" aliases="MessageDSAlias1,MessageDSAlias2" driver="org.h2.jdbcx.JdbcDataSource" type="xa">
         <URL>jdbc:h2:mem:MessageDS;DB_CLOSE_DELAY=-1</URL>
         <minPoolSize>5</minPoolSize>
         <maxPoolSize>10</maxPoolSize>
      </datasource>
   </f3-other:datasources>
</composite>

...