Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide 10g (10.1.3.5.0) Part Number E13981-01 |
|
|
View PDF |
A data source is a Java object that represents the physical enterprise information system to which OC4J persists entities. Your application uses a data source object to retrieve a connection to the enterprise information system the data source represents.
This section describes the following:
For more information, see the following:
"Data Sources" in the Oracle Containers for J2EE Services Guide
OC4J supports the following types of data sources:
Table 2-5 lists the characteristics of these OC4J data sources.
Table 2-5 OC4J Data Source Type Characteristics
Characteristic | Managed | Native |
---|---|---|
Uses OC4J connection pool? |
Yes |
No |
Connections can participate in global transactions? |
Yes |
No |
Connections wrapped with an OC4J |
Yes |
No |
A managed data source (see Example 2-2) is an OC4J-provided implementation of the java.sql.DataSource
interface that acts as a wrapper for a JDBC driver or data source. You can associate a managed data source with a separate connection pool. Multiple managed data sources may share the same connection pool.
Example 2-2 Managed Data Source
<connection-pool name="ScottConnectionPool"> <connection-factory factory-class="oracle.jdbc.pool.OracleDataSource" user="scott" password="tiger" url="jdbc:oracle:thin:@//localhost:1521/ORCL" > </connection-factory> </connection-pool> <managed-data-source name="OracleManagedDS" jndi-name="jdbc/OracleDS" connection-pool-name="ScottConnectionPool" />
For more information, see "Configuring a Data Source for an Oracle Database".
A native data source (see Example 2-3) is a JDBC vendor-provided implementation of the java.sql.DataSource
interface. You use the connection pool provided by the data source instance you choose. Each native data source must use its own connection pool.
Example 2-3 Native Data Source
<native-data-source name="nativeDataSource" jndi-name="jdbc/nativeDS" description="Native DataSource" data-source-class="com.ddtek.jdbcx.sqlserver.SQLServerDataSource" user="frank" password="frankpw" url="jdbc:datadirect:sqlserver://server_name:1433;User=usr;Password=pwd"> </native-data-source>
For more information, see "Configuring a Data Source for a Third-Party Database".
You specify a connection URL to tell OC4J where to find the underlying physical data source.
When you define a managed data source (see "Managed Data Source"), the connection URL is an attribute of the connection pool you associate with it (see Example 2-2).
When you define a native data source (see "Native Data Source"), the connection URL is an attribute of the native data source (see Example 2-3).
When specifying the connection URL to an Oracle database, you must use a service-based URL: that is, of the form host:port/SID
(not host:port:SID
), as Example 2-4 shows.
When specifying the connection URL to a non-Oracle database, you use a URL appropriate for that system. Example 2-5 shows a typical connection URL for an SQLServer database.
Managed data sources support both local and global (two-phase commit) transactions. By default, they are configured to support global transactions. For more information, see "Configuring a Data Source for an Oracle Database").
Native data sources support only local transactions.
In OC4J, you configure data source information in a data-sources.xml
file.
You can include a data-sources.xml
file in your EAR but OC4J does not support multiple data-sources.xml
files.
In an EJB 3.0 application, you associate a data source with a persistence unit (see "Specifying a Data Source in a Persistence Unit").
For more information, see the following:
To simplify application configuration, you can define default data sources.
How you define a default data source depends on the type of the application from which you want to access the default data source.
For information on how to configure data sources for different types of applications, see the following:
OC4J does not support multiple data sources within different entities in orion-ejb-jar.xml
file.
If your application is composed of more than one EAR and each EAR contains a data-sources.xml
, then, when you deploy your application, OC4J will use the last entity bean's data-source.xml
file for all entity beans.
To accommodate this scenario, specify the data source in orion-application.xml
file or specify a default data source.
For more information, see the following: