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. A session represents the connection
between an application and the relational database that stores its persistent
objects. TopLink provides several different session objects that all
implement the same Session interface. In this document we will try to
understand using ServerSession.
Prerequisites
Before we get started, the following are the
assumptions that will be made in this document:
HowTo acquire ServerSession using
OracleAS TopLink
The session supports a shared session that can be used
by multiple users or clients in a three-tiered application. It brokers
client sessions to allow read and write access through a unified object
cache. The server session provides a shared read only database connection
that is used by all of its client for reads. All changes to objects and
the database must be done through a unit of work acquired from the client
session, this allows the changes to occur in a transactional object
space and under an exclusive database connection.
By default, SessionManager
attempts to create a new session using the specifications contained in
a file called sessions.xml. This file can
define one or more session configurations by name that the SessionManager makes available at runtime. This
file, which must be on the root of the class path, contains all of the configuration
information for the named session. This allows developers to update
the configuration of a session without modifying application code. Below
is a sample sessions.xml
The code snippet to retrieve a session from a session
manager is shown below. Retrieving a session this way uses all defaults.
If no session exists within the current instance of SessionManager, the Session Manager attempts to
load a session from sessions.xml.
// Get the session from session.xml named 'ServerSession' ServerSession aSession = (ServerSession)SessionManager.getManager().getSession("ServerSession"); .... .... // Disconnect from the database aSession.logout();
The server session manages the client session, shared
cache and connection pools. Although the server session is a TopLink
session it should only be used to manage the servers client sessions.
For this purpose the Server interface is
provided. The Server interface does not implement
the session API but only the public API required for the server session
such as configuring connection pools and acquiring client sessions. Servers
can create new client sessions using the acquireClientSession()
method.
Edit <SAMPLE_HOME>/src/META-INF/EmployeeDescriptor.xml,
set database parameters in the tag connection-url.
Add toplink.jar, xmlparserv2.jar, connector.jar and classes12.jar
to the classpath. Also ensure that <SAMPLE_HOME>/src/META-INF
directory is added to your classpath
From <SAMPLE_HOME>/src/oracle/otnsamples/toplink
directory, Compile the java sources as shown below javac -d . *.java
From <SAMPLE_HOME>/src/oracle/otnsamples/toplink
directory, execute the java class as shown below java oracle.otnsamples.toplink.EmployeeManagement