The <session> element contains configuration information for a TopLink session. It includes several tags that specify the options for the session. The Sessions XML file normally contains at least one <session> element, and can include several if required by the application.
The <session> supports the configuration tags listed in Table B-1.
Table B-1 Tags within the <session> Element
Example B-2 Using a Project Class
<toplink-configuration>
<session>
<name>mysession</name>
<project-class>com.mycompany.MyProject</project-class>
...
</session>
</toplink-configuration>
Example B-3 Using Project XML
<toplink-configuration>
<session>
<name>mysession</name>
<project-xml>C:/myproject/myproject.xml</project-xml>
...
</session>
</toplink-configuration>
In addition to these tags, the <session> element includes several tags that contain session configuration information. These include:
The <session-type> element appears inside of a <session> element, and specifies the session type with the following tags:
Table B-2 Tags within the <session-type> Element
Example B-4 Defining a ServerSession
<session>
<name>myServerSession</name>
<project-class>com.mycompany.MyProject</project-class>
<session-type>
<server-session/>
</session-type>
...
</session>
Example B-5 Defining a DatabaseSession
<session>
<name>myDatabaseSession</name>
<project-class>com.mycompany.MyProject</project-class>
<session-type>
<database-session/>
</session-type>
...
</session>
The <login> element is optional for the session. If you do not include the <login> element in the Sessions XML file, you must set a default login in the TopLink Mapping editor.
Table B-3 Basic Configuration Tags Within the <login> Element
Example B-6 Basic Configuration Using JDBC
<session>
<name>myServerSession</name>
<project-class>com.mycompany.MyProject</project-class>
<session-type>
<server-session/>
</session-type>
<login>
<license-path>C:/myproject/license/</license-path>
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<connection-url>jdbc:oracle:thin@dbserver:1521:dbname</connection-url>
<platform-class>oracle.toplink.internal.databaseaccess.OraclePlatform</platform-class>
<user-name>scott</user-name>
<password>tiger</password>
</login>
...
</session>
Example B-7 Basic Configuration Using a DataSource
<session>
<name>myServerSession</name>
<project-class>com.mycompany.MyProject</project-class>
<session-type>
<server-session/>
</session-type>
<login>
<data-source>jdbc/MyApplicationDS</data-source>
<platform-class>oracle.toplink.internal.databaseaccess.OraclePlatform</platform-class>
</login>
...
</session>
The <login> element offers several optional tags that enable you to customize your session login. Optional <login> tags typically accept TRUE or FALSE as valid values. Table B-4 describes these tags.
Table B-4 Optional Tags Within the <login> Element
The Login element offers two other optional tags:
You can configure sequencing as part of the session login, although it is not a requirement. If you do not configure sequencing in the Sessions XML file, the application uses the configuration specified in the TopLink Mapping editor.
Configure sequencing in Sessions XML when you want to use custom sequencing for a given session.
Table B-5 lists the elements you use to configure sequencing in the Sessions XML file. All of these elements are optional.
Table B-5 Optional Sequencing Configuration Tags Within <login>
See "Sequencing" for more information.
Example B-8 Configuring Native Sequencing
<session>
<login>
...
<uses-native-sequencing>true</uses-native-sequencing>
<sequence-preallocation-size>50</sequence-preallocation-size>
</login>
...
</session>
Example B-9 Configuring Table-Based Sequencing
<session>
...
<login>
<uses-native-sequencing>false</uses-native-sequencing>
<sequence-table>SEQUENCE</sequence-table>
<sequence-name-field>SEQ_NAME</sequence-name-field>
<sequence-counter-field>SEQ_COUNT</sequence-counter-field>
</login>
...
</session>
You configure cache synchronization as part of the <login>. Use the <cache-synchronization-manager> element and the tags listed in Table B-6 to configure cache-synchronization for your application.
Table B-6 Cache Synchronization Manager Configuration Tags
Example B-10 Using the Cache Synchronization Manager
<session>
...
<login>
<cache-synchronization-manager>
<clustering-service>oracle.toplink.remote.rmi.RMIClusteringService</clustering-service>
<multicast-port>6020</multicast-port>
<multicast-group-address>226.18.6.18</multicast-group-address>
<is-asynchronous>true</is-asynchronous>
<should-remove-connection-on-error>true</should-remove-connection-on-error>
<naming-service-url>localhost:1099</naming-service-url>
</cache-synchronization-manager>
</login>
...
</session>
If your applications needs to know when session events take place, you can use event listeners to register for event notification. You can configure event listeners in the Sessions XML file.
The <event-listener-class> tag enables you to configure listener classes that either implement the oracle.toplink.sessions.SessionEventListener interface, or extend the oracle.toplink.sessions.SessionEventAdapter class. You can configure multiple event listener classes by including multiple <event-listener-class> tags, and specifying the implementing class name for each tag.
Example B-11 Setting the Event Listener Class in Code
package examples;
import oracle.toplink.sessions.*;
public class MyEventListener extends SessionEventAdapter {
public void preLogin(SessionEvent event) {
Session session = event.getSession();
/* custom code goes here */
}
}
Example B-12 Setting the Event Listener Class in Sessions XML:
<session>
...
<event-listener-class>examples.MyEventListener</event-listener-class>
...
</session>
TopLink registers the examples.MyEventListener class with the SessionEventManager for the session. TopLink invokes the MyEventListener class preLogin method when the preLogin event occurs on the session.
TopLink provides a profiler that you can use to optimize your application and identify performance bottlenecks. To implement the performance profiler, use the <profiler-class> tag to include the performance profiler in your session.
Example B-13 Implementing the Performance Profiler in Sessions XML
<session>
...
<profiler-class>oracle.toplink.tools.profiler.PerformanceProfiler</profiler-class>
...
</session>
The <profiler-class> tag supports any class that implements the oracle.toplink.sessions.SessionProfiler interface. Because of this, you can build your own profiler and add it to your session, provided your profiler implements the oracle.toplink.sessions.SessionProfiler interface.
If your system includes external transactions (under JTA, for example), specify a TopLink external transaction controller using the <external-transaction-controller-class> tag.
To use an external transaction controller, you must specify the following in the session login:
Example B-14 Configuring the External Transaction Controller
<session>
...
<login>
...
<uses-external-transaction-controller>true</uses-external-transaction-controller>
<data-source>jdbc/MyApplicationDS</data-source>
<uses-external-connection-pool>true</uses-external-connection-pool>
...
</login>
<external-transaction-controller-class>oracle.toplink.jts.oracle9i.Oracle9iJTSExternalTransactionController</external-transaction-controller-class>
...
</session>
The <exception-handler-class> tag specifies a class that handles exceptions for the session. This tag accepts any class that implements the oracle.toplink.exceptions.ExceptionHandler.
Example B-15 Configuring the Exception Handler in Code
package examples;
import oracle.toplink.exceptions.*;
public class MyExceptionHandler implements ExceptionHandler {
public Object handleException(RuntimeException exception) {
/*custom code goes here */
}
}
Example B-16 Configuring the Exception Handler in the Session XML File
<session>
...
<exception-handler-class>examples.MyExceptionHandler</exception-handler-class>
...
</session>
You can explicitly configure a single connection pool or multiple connection pools for your TopLink application with the <connection-pool> element in the Sessions XML file. If you do not configure a connection pool for a session, the session uses the default connection pool you defined for the project.
For more information on configuring the connection pool for the project, see "Working with Connection Pools" .
You must define a login for each <connection-pool> you define manually. For information on configuring a login, see "The <login> Element" .
Table B-7 <connection-pool> Element Tags
Example B-17 Configuring the Connection Pool Element
<session>
...
<connection-pool>
<is-read-connection-pool>true</is-read-connection-pool>
<name>additionalReadPool</name>
<max-connections>20</max-connections>
<min-connections>10</min-connections>
<login>
...
</login>
</connection-pool>
...
</session>
TopLink does not automatically enable logging for a session unless you explicitly request it. To enable logging in a sessions, include the <enable-logging> element as part of your session definition in the Sessions XML file.
To enable logging, include the <enable-logging> element, and set it to TRUE. After you enable logging, you can customize the logging behavior on the session by including one or more logging options in the Sessions XML file. The available logging options appear in Table B-8, and accept TRUE or FALSE as arguments.
Table B-8 <enable-logging> Option Tags
Example B-18 Configuring Logging and Logging Options
<session>
...
<enable-logging>true</enable-logging>
<logging-options>
<log-debug>false</log-debug>
<log-exceptions>true</log-exceptions>
<log-exception-stacktrace>true</log-exception-stacktrace>
<print-session>true</print-session>
<print-thread>false</print-thread>
<print-connection>true</print-connection>
<print-date>true</print-date>
</logging-options>
...
</session>
Copyright © 1997, 2004, Oracle. All rights reserved.