Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide 10g Release 3 (10.1.3) B14428-02 |
|
![]() Previous |
![]() Next |
This chapter describes:
Configuring a Default Data Source for an EJB 3.0 Application
Configuring a Default Data Source for an EJB 2.1 Application
For more information, see:
"Data Sources" in the Oracle Containers for J2EE Services Guide
Note: You can download a data source code example fromhttp://www.oracle.com/technology/tech/java/oc4j/1013/how_to/index.html . |
To create a data source for an Oracle database, you create a managed datasource. You can create a managed data source using the Application Server Control Console (see "Using Application Server Control Console") or deployment XML (see "Using Deployment XML").
For more information, see:
"Data Sources" in the Oracle Containers for J2EE Services Guide
You can use Application Server Control Console to create a managed data source dynamically without restarting OC4J.
For more information, see http://www.oracle.com/technology/tech/java/oc4j/1013/how_to/index.html
.
You can configure a managed data source for an Oracle database by configuring a connection-pool
element and managed-data-source
element in the data-sources.xml
file as Example 20-1 shows.
Example 20-1 data-sources.xml For an Oracle JDBC 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" tx-level="global" />
Be sure to specify a service-based connection URL in the connection-factory
element (see "How Do You Define a Connection URL in OC4J?").
By default, a managed data source supports global (two-phase commit) transactions. To configure a managed data source to support only local transactions, set the managed-data-source
attribute tx-level
to local
. For more information, see "What Transaction Types Do Data Sources Support?").
For more information, see:
http://www.oracle.com/technology/tech/java/oc4j/1013/how_to/index.html
http://www.oracle.com/technology/tech/java/newsletter/articles/oc4j_datasource_config.html
If you configure a managed data source using this method, you must restart OC4J to apply your changes. Alternatively, you can use Application Server Control Console to create a data source dynamically without restarting OC4J (see Using Application Server Control Console)
To create a data source for a third-party (non-Oracle) database, you create a native datasource. You can create a native data source using the Application Server Control Console (see "Using Application Server Control Console") or deployment XML (see "Using Deployment XML").
For more information, see:
"Data Sources" in the Oracle Containers for J2EE Services Guide
You can use Application Server Control Console to create a native data source dynamically without restarting OC4J.
For more information, see http://www.oracle.com/technology/tech/java/oc4j/1013/how_to/index.html
.
Example 20-2 shows how to define a native data source element for a third-party database (in this example, SQLServer).
Example 20-2 data-sources.xml for a Third-Party Database
<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>
By default, a native data source supports only local transactions. For global (two-phase commit) transactions, configure a managed data source. For more information, see "What Transaction Types Do Data Sources Support?").
For more information, see:
http://www.oracle.com/technology/tech/java/oc4j/1013/how_to/index.html
http://www.oracle.com/technology/tech/java/newsletter/articles/oc4j_datasource_config.html
If you configure a native data source using this method, you must restart OC4J to apply your changes. Alternatively, you can use Application Server Control Console to create a native data source dynamically without restarting OC4J (see "Using Application Server Control Console")
You can configure a default data source for an EJB 3.0 application using deployment XML (see "Using Deployment XML").
For more information, see:
"Data Sources" in the Oracle Containers for J2EE Services Guide
To configure a default data source for an EJB 3.0 application:
Set the name of the default data source in the default-data-source
attribute of your orion-application.xml
file.
Customize your EJB 3.0 application to define a data source of this name in your ejb3-toplink-session.xml
file.
For more information, see:
You can configure a default data source for an EJB 2.1 application using deployment XML (see "Using Deployment XML").
For more information, see:
"Data Sources" in the Oracle Containers for J2EE Services Guide
To configure a default data source for an EJB 2.1 application:
Set the name of the default data source in the default-data-source
attribute of the orion-application
element in your orion-application.xml
file.
Set the name of the default data source in the data-source
attribute of the entity-deployment
element in your orion-ejb-jar.xml
file.
Define the default data source in the <
OC4J_HOME
>/j2ee/home/config/data-sources.xml
file.