OracleAS TopLink - HowTo use custom data sources
with TopLink
Date: 21/04/2004
After completing
this HowTo you should be able to:
•
Understand how to use custom data sources with TopLink •
Understand how to use sessions.xml in a J2EE application • Run the
sample using the instruction given
Oracle Application Server TopLink is an
advanced object-to-relational persistence. It helps to build high
performance applications that store persistent data in a relational
database. You can use the OracleAS TopLink Sessions Editor to manage sessions.xml
which
contains details of how TopLink accesses the database.
Prerequisites
Before we get started, the following are the
assumptions that will be made in this document:
How to use custom data sources
OracleAS TopLink 10g
OracleAS TopLink Sessions Editor provides a
graphical way to manage sessions.xml file outside the TopLink Workbench.
The sessions.xml file allows you to configure one or more sessions for
the TopLink project and associate these sessions with the project. You
can configure -
Let us consider a simple J2EE
application, with one table Employees,two JSP files to search/display
records from this table, a TopLink generated class Employees and a
utility class EmployeeReader. A snapshot of the TopLink workbench for
this project is shown below
There is no default login specified in this
project, since we are going to add that information in our sessions.xml
file.
To do this,
1. Open the TopLink Sessions Editor.
2. Create a new Sessions file by selecting File->New.
3.Right click on sessions.xml->New->Session and provide a name
for the session, CustomDS.
Associate this session with the project file,by entering the path to
the project file in the 'General' tab in the navigator pane.
4. This session will be used to access a
data source
defined in OC4J. So in the navigator pane, enter the name of the data
source
The data source should defined in a
data-sources.xml file, which should be bundled with the application.
In the code, you will use the session name
to obtain
a session.
//Get the named session using sessionName and SessionManager // The sessions.xml file is loaded by SessionManager and a Session // instance is created based on the properties set in the file Session session=SessionManager.getManager().getSession("DirectConnection");
Note that in a J2EE
application, the sessions.xml and the project descriptor files should
be available in the classpath.
e.g. Place them under WEB-INF/classes folder of your web
application