« April 2007 | Main | June 2007 »

May 2007 Archives

May 3, 2007

OC4J: Configuring DataSources

DataSource configuration in OC4J seems to be a confusing task for many, but once you get used to it, it is sound and simple...

There are three options to configure a DataSource in OC4J:

  1. Globally
  2. With the help of JDeveloper
  3. Manually per application

Configure a DataSource Globally

When you'd like to configure a DataSource globally, ie. per OC4J instance, you should use the Application Server Control. Simply go to the instance and follow this path Administration -> Services: JDBC Resources. On this page you have to create the Connection Pool and the Data Source (in that order). If you want to use this DataSource make sure that this is the only DataSource configured for your application (see below).

Configure a DataSource Per Application

With the Help of JDeveloper

If you're developing with JDeveloper you're quite safe. JDeveloper automagically configures the application settings based on the configured database connections. This works very smooth but sometimes it is not exactly what you want.

Manually

This is the most advanced solution and requires some understanding of the files used. In the META-INF directory of your application archive you have to provide the following three files.
META-INF/data-sources.xml
This file contains the actual configuration of the DataSource you want to use in your application. It looks like this one:

<?xml version='1.0'?>
<data-sources
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

 xsi:noNamespaceSchemaLocation="http://xmlns.oracle.com/oracleas/schema/data-sources-10_1.xsd">
 <connection-pool name="pool-demo">
  <connection-factory
   factory-class="oracle.jdbc.pool.OracleDataSource"

   user="demo" password="->DBDemo"
   url="jdbc:oracle:thin:@demo:1521:XE"/>
 </connection-pool>
 <managed-data-source name="managed-demo"
  jndi-name="jdbc/demoDS"

  connection-pool-name="pool-demo"/>
</data-sources>

META-INF/jazn-data.xml
This file contains the username/password information for the application and can include the DataSource username/password.

<?xml version='1.0' standalone='yes'?>
<jazn-data
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:noNamespaceSchemaLocation="http://xmlns.oracle.com/oracleas/schema/jazn-data-10_0.xsd"
 filepath="" OC4J_INSTANCE_ID="">
 <jazn-realm>
  <realm>
   <name>jazn.com</name>
   <users>
    <user>
     <name>DBDemo</name>
     <credentials>!demo</credentials>
    </user>
   </users>
   <roles/>
  </realm>
 </jazn-realm>
</jazn-data>

In the credentials tag we provide the real password in clear text prefixed with a '!'. This notation tells OC4J to encrypt the content of the credentials tag during deployment. Be aware that this will not be done within the original file contents in j2ee/<instancename>/applications. To be on the very save side, deploy it once, get the content of the credentials tag from j2ee/<instancename>/application-deployments/<application-name>/jazn-data.xml, and copy it into the jazn-data.xml you include in your EAR file.
META-INF/orion-application.xml
This file is the counterpart of the J2EE application.xml and contains OC4J-specific settings. Understand it as the wrapper for all the above. Here is a sample:

<?xml version='1.0'?>
<orion-application
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:noNamespaceSchemaLocation="http://xmlns.oracle.com/oracleas/schema/orion-application-10_0.xsd"
 default-data-source="jdbc/demoDS">
 <data-sources path="./data-sources.xml"/>
 <jazn location="./jazn-data.xml" provider="XML"/>
</orion-application>


Don't forget to tell JDeveloper not to update your data-sources.xml and jazn-data.xml. The two areas you should take care of are:
  • Turning the automatic inclusion of the data-sources.xml in your application off (Tools->Preferences->Deployment->Uncheck "Bundle Default data-sources.xml During Deployment").
  • Turning the content update of your own data-sources.xml (Right click on your data-sources.xml file, select Properties and tick off all check boxes).

May 8, 2007

Oracle 11g Technology Previews Available

Quite on time for the opening of JavaOne, Oracle has released three Technology Previews on OTN.

JDeveloper 11g Technology Preview



Oracle Containers for J2EE (OC4J) 11g Technology Preview

TopLink 11g Technology Preview

May 21, 2007

AVAILABLE FROM OTN: Oracle Development Kit for Spring

I've nearly missed this little gem on OTN... quoting OTN because it says it all:

"Oracle Development Kit for Spring


To help you better understand the support Oracle
offers to Spring developers, everything you need to get started with Spring
on Oracle Containers for Java EE is now available in the Oracle Development Kit for Spring.
Whether you're new to Spring or an old hand, you're sure to benefit from the contents
of the Development Kit:



  • A comprehensive set of How-To examples illustrating Spring-OC4J integration
  • The Oracle Developer Depot Web application, which enables you to deploy and run the
    How-To projects on OC4J
  • A Spring extension to JDeveloper, Oracle's free Java IDE
  • Supporting documentation and white papers

The Kit is available as a self-extracting ZIP archive. Note that you
will need Oracle Containers for Java EE (10.1.3.2) or higher to use all of the How-To projects
provided."

For those who overlooked the link before the quotation:
http://www.oracle.com/technology/tech/java/spring/sdk_index.html

May 24, 2007

QUIZ: When to specify an empty default constructor in Java?

I'm a purist. I don't like unnecessary things as the distract my attention from the important stuff...

Browsing the blogosphere, magazines, presentations, and books I see a lot of sample code which makes me shudder. The reason is simple. The usage of the Java Default Constructor. To make you aware of the good usage of it, I'm challenging you with this quiz:

When to specify an empty default constructor in Java?

Please post your answers in the comments section.
I'll summary the answers next week.

About May 2007

This page contains all entries posted to Olaf Heimburger's Blog in May 2007. They are listed from oldest to newest.

April 2007 is the previous archive.

June 2007 is the next archive.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type and Oracle