eXo Platform 3.5

## Chapter 64. The data source provider

The DataSourceProvider is a service used to give access to a data source in an uniform manner in order to be able to support data sources that are managed by the application server.

getDataSource(String dataSourceName) | Tries to get the data source from a JNDI lookup. If it can be found and the data source is defined as managed, the service will wrap the original DataSource instance in a new DataSource instance that is aware of its managed state otherwise it will return the original DataSource instance.
isManaged(String dataSourceName) | Indicates whether or not the given data source is managed.

## Configuration

The configuration of the DataSourceProvider should be defined only if you use managed data sources since by default all the data sources are considered as not managed. See below the default configuration

    <configuration>
    ....
       <component>
          <key>org.exoplatform.services.jdbc.DataSourceProvider</key>
          <type>org.exoplatform.services.jdbc.impl.DataSourceProviderImpl</type>
          <init-params>
             <!--  Indicates that the data source needs to check if a tx is active
                  to decide if the provided connection needs to be managed or not.
                  If it is set to false, the data source will provide only
                  managed connections if the data source itself is managed.  -->
             <!--value-param>
                <name>check-tx-active</name>
                <value>true</value>
             </value-param-->
             <!-- Indicates that all the data sources are managed
                  If set to true the parameter never-managed and
                  managed-data-sources will be ignored -->
             <!--value-param>
                <name>always-managed</name>
                <value>true</value>
             </value-param-->
             <!-- Indicates the list of all the data sources that are
                  managed, each value tag can contain a list of
                  data source names separated by a comma, in the
                  example below we will register ds-foo1, ds-foo2
                  and ds-foo3 as managed data source. If always-managed
                  and/or never-managed is set true this parameter is ignored -->
             <!--values-param>
                <name>managed-data-sources</name>
                <value>ds-foo1, ds-foo2</value>
                <value>ds-foo3</value>
             </values-param-->
          </init-params>
       </component>
    ...
    </configuration>

check-tx-active | This parameter indicates that the data source needs to check if a transaction is active to decide if the provided connection needs to be managed or not. If it is set to false, the data source will provide only managed connections if the data source itself is managed. By default, this parameter is set to true. If this parameter is set to true, it will need the TransactionService to work propertly, so please ensure that the TransactionService is defined in your configuration.
always-managed | This parameter indicates that all the data sources are managed. If set to true the parameter never-managed and managed-data-sources will be ignored, so it will consider all the data sources as managed. By default, this parameter is set to false.
managed-data-sources | This parameter indicates the list of all the data sources that are managed, each value tag can contain a list of data source names separated by a comma. If always-managed and/or never-managed is set true this parameter is ignored.

Copyright © 2009-2012. All rights reserved. eXo Platform SAS