Deploying J2EE Applications - Types of Data Sources
(Page 2 of 5 )
There are three types of data sources you can use in OC4J:
- Emulated data sources
- Non-emulated data source
- Native data sources
Emulated Data Sources Emulated data sources emulate the XA (Transactional) protocol for JTA ( Java Transaction API) transactions and offer features such as OC4J caching and pooling and Oracle JDBC extensions (for Oracle databases). The need for emulated data sources arose because many JDBC drives didn’t offer XA capabilities in earlier days.
An emulated data source doesn’t provide full XA global transactional support, such as the two-phase commit, which is unsupported under emulated data sources. However, because they lack full transactional support, emulated data source connections tend to be quite fast in nature. If you’re using local transactions or global transactions that don’t require the two-phase commit mechanism, emulated data sources are the recommended type of data source for you to use.
The following is a data-sources.xml configuration entry for an emulated data source:
<data-source
class=
"com.evermind.sql.DriverManagerDataSource"
name=ÓOracleDSÓ
location="jdbc/OracleCoreDS"
xa-location="OracleDS"
ejb-location="jdbc/OracleDS"
connection-driver="oracle.jdbc.driver.OracleDriver"
username="scott"
password="tiger"
url="jdbc:oracle:thin:@// localhost:5521/oracle.regress.
rdbms.dev.us.oracle.com"
inactivity-timeout=Ó30Ó
/>
Although you specify values for the location, ejb-location, and xa-location attributes when configuring an emulated data source in your data-source.xml file, you must only use the value specified by the ejb-location attribute when looking up that emulated data source. By now, you’re well aware that you use a JNDI tree to look up a data source. You must look up a data source in the following way (only the "jdbc/OracleDS" value is used in the JNDI lookup):
Context ic = new InitialContext();
DataSource ds = (DataSource) ic.lookup("jdbc/OracleDS");
Or this:
DataSource ds = (DataSource) ic.lookup("java:comp/env/jdbc/OracleDS");
Connection con = ds.getConnection();
exam watch: In the data-sources .xml file,
you must specify values for the location, xa-location, and ejb-location attributes. The first two attributes, however, are actually deprecated now, and only the value you specify for ejb-location is actually used as the location string. To be used in a JNDI lookup for retrieving the data source. Applications, EJBs, Servlets, and JSPs should use the ejb-location value to look up emulated data sources in the JNDI tree.
on the job: If you want true two-phase commits in your transactions, you must use a non-emulated data source.
Non-Emulated Data Sources A non-emulated data source provides full JTA services, meaning that the two-phase commit mechanism is provided as well. Oracle Corporation recommends you use non-emulated data sources. A non-emulated data source provides higher recovery and reliability as well as distributed database features, unlike the emulated data sources. Note that to run a non-emulated data source, you must use a Java-enabled database, such as the Oracle Database.
Here’s a typical data-sources.xml file for a non-emulated data source:
<data-source
class= "com.evermind.sql.OrionCMTDataSource"
location="jdbc/OracleDS"
connection-driver="oracle.jdbc.driver.OracleDriver"
username="scott"
password="tiger"
url="jdbc:oracle:thin:@//localhost:5521/ oracle.regress.rdbms.dev.us.oracle.com"
</data-source>
Note that JNDI lookups are performed using the value of the location attribute in the data-sources.xml file.
In the data-sources.xml file,
- Location refers to the JNDI name bound to the data source in the JNDI name spaces.
- The url, username, and password attributes refer to the database and default user name and password for retrieving connections to the database.
- Class is the type of data source class to bind in the name space.
Native Data Sources Native data sources are supplied by JDBC vendors, and are used to implement data sources. Vendors provide extensions to facilitate capabilities such as caching and pooling. OC4J supports native data sources, but because they don’t provide JTA services such as commits and rollbacks, they can’t be used in global transactions. Here’s how a data-sources.xml file looks for a native data source:
<data-source
class= "com.my.DataSourceImplementationClass"
name=ÓNativeDSÓ
location="jdbc/NativeDS"
username="user"
password="pswd"
url="jdbc:myDataSourceURL"
</data-source>
Exam watch: Native data sources don’t support JTA transactions. Both emulated as well as non-emulated data sources support JTA transactions, but only the non-emulated data sources support true two-phase commit (an emulated data source can only emulate a two-phase commit).
You can manage data sources through the Application Server Control’s Application Data Sources page. You can reach this page by clicking the Administration tab on the OC4J home page, and then clicking on Data Sources under the Application Defaults section. From the Application Data Sources page, you can perform the following functions:
- View data source information for all applications, including the data source name, the JNDI location, and class and JDBC Driver information.
- Create, delete, and modify data sources.
- View performance statistics for data sources (only for non-emulated data sources).
The Data Sources page can be used to connect top Oracle as well as non-Oracle databases. For Oracle database connections, you must either configure a non-emulated Data Source that is purely Oracle based or use an emulated Data Source, which involves a wrapper around an Oracle Data Source.
on the job: Use the com.evermind.sql.DriverManagerDataSource with the Merant JDBC drivers to connect to Oracle databases.
Next: Creating Data Sources >>
More Oracle Articles
More By McGraw-Hill/Osborne
|
This article is excerpted from chapter eight of the Oracle 10g Application Server Exam Guide, written by Sam Alapati (McGraw-Hill; ISBN: 0072262710). Check it out today at your favorite bookstore. Buy this book now.
|
|