Skip Headers

Oracle TopLink Developer's Guide 10g Release 3 (10.1.3) B13593-01 |
| Home | Solution Area | Contents | Index

Previous | Next |

# Data Access Concepts

This section describes concepts unique to TopLink data access, including the following:

- Externally Managed Transactional Data Sources

- Data Source Login Types

- Data Source Platform Types

- Authentication

- Connections

- Connection Pools

## Externally Managed Transactional Data Sources

A TopLink transactional data source is externally managed if the connection pool is managed by a transaction service (such as an application server controlled transaction or a JTA transaction). A JTA managed data source or connection pool is commonly used in J2EE applications and normally required in EJB applications. When using an externally managed connection pool:

- Configure the session to use an `ExternalTransactionController` to integrate TopLink's unit of work with the external transaction service (see "Integrating the Unit of Work With an External Transaction Service").

- Use the external-transaction-control option to specify the connection's login and inform TopLink that the connection is maintained by the external controller (see "Configuring External Connection Pooling").

- You may need to configure the TopLink read connection pool or sequence connection pool to use a non-JTA connection pool in order to avoid transactional overhead (see "Connection Pools")

For more information on transactional data sources, see the following:

- "JTA Controlled Transactions"

- "OTS Controlled Transactions"

- "CMP Controlled Transactions"

Refer to Chapter 100, "Understanding TopLink Transactions" for more information on TopLink transactions.

## Data Source Login Types

The login (if any) associated with a session determines how the TopLink runtime connects to the project's data source.

A login includes details of data source access, such as authentication, use of connection pools, and use of external transaction controllers. A `Login` owns a data source platform.

A data source platform includes options specific to a particular data source including such as binding, use of native SQL, use of batch writing, and sequencing. For more information about platforms, see "Data Source Platform Types".

For projects that do not persist to a data source, a login is not required. For projects that do persist to a data source, a login is always required.

In TopLink Workbench, the project type determines the type of login that the project uses, if applicable.

You can use a login in a variety of roles. A login's role determines where and how you create it. The login role you choose depends on the type of project you are creating and how you intend to use the login:

- "Non-CMP Session Role: Session Login"

- "CMP Deployment Role: Deployment Login"

- "Development Role: Development Login"

There is a session login type for each project type that persists to a data source:

- DatabaseLogin

- EISLogin

Note that there is no XML login. TopLink XML projects are used for nonpersistent, in-memory object to XML data transformation and consequently there is no data source to log in to. For more information about persistent and nonpersistent projects, see "Persistent and Nonpersistent Projects".

For additional information, see the following:

- "Projects and Login"

- "Configuring Common Data Source Login Options"

### DatabaseLogin

If you are creating a project that accesses a relational database, you must configure the project with a `DatabaseLogin`. Your choice of `DatabasePlatform` further customizes your project for a particular type of database (see "Database Platforms").

For more information, see "Database Login Configuration Overview".

### EISLogin

If you are creating a project that accesses a nonrelational data source using a J2C adapter, you must configure the project with an `EISLogin`. Your choice of `EISPlatform` further customizes your project for a particular J2C adapter and specifies what record type TopLink uses to exchange data with the EIS (see "EIS Platforms").

For more information, see "EIS Login Configuration Overview".

## Data Source Platform Types

TopLink abstracts the details of your underlying data source using data source platform classes. TopLink provides the following data source platforms:

- Database Platforms

- EIS Platforms

A data source platform is owned by your project's `Login`. For more information about logins, see "Data Source Login Types".

In general, TopLink Workbench provides minimal access to a platform API. To configure most platform options, you must use an amendment method (see "Configuring Amendment Methods"), or a `preLogin` event listener (see "Managing Session Events With the Session Event Manager").

### Database Platforms

TopLink interacts with databases using structured query language (SQL). Because each database platform uses its own variation on the basic SQL language, TopLink must adjust the SQL it uses to communicate with the database to ensure that the application runs smoothly.

The type of database platform you choose determines the specific means by which the TopLink runtime accesses the database, including the type of Java Database Connectivity (JDBC) driver to use. JDBC is an application programming interface (API) that gives Java applications access to a database. TopLink relational projects rely on JDBC connections to read objects from, and write objects to, the database. TopLink applications use either individual JDBC connections or a JDBC connection pool (see "Connection Pools"), depending on the application architecture.

TopLink provides a variety of database-specific platforms that let you customize your project for your target database.

Oracle Database platforms are located in `oracle.toplink.platform.database.oracle` package and include the following:

- `OraclePlatform`

- `Oracle8Platform`

- `Oracle9Platform`

Non-Oracle Database platforms are located in `oracle.toplink.platform.database` package and include the following:

- `AccessPlatform` for Microsoft Access databases

- `AttunityPlatform` for Attunity Connect JDBC drivers

- `CloudscapePlatform`

- `DB2MainframePlatform`

- `DB2Platform`

- `DBasePlatform`

- `HSQLPlatform`

- `InformixPlatform`

- `MySQL4Platform`

- `PointBasePlatform`

- `SQLAnyWherePlatform`

- `SQLServerPlatform`

- `SybasePlatform`

Specify your database platform at the project level (see "Configuring Relational Database Platform at the Project Level") for all sessions, or override this project-level configuration at the session level (see "Configuring a Relational Database Platform at the Session Level").

If you set your database platform in TopLink Workbench, then TopLink Workbench manages the database platform configuration for you automatically.

### EIS Platforms

TopLink interacts with an EIS data source indirectly by way of a J2C adapter. TopLink abstracts the details of an EIS data source using the `oracle.toplink.eis.EISPlatform` class.

The type of EIS platform you choose determines the specific means by which the TopLink runtime accesses the EIS, including the type of J2C adapter to use. TopLink EIS projects rely on EIS connections to read objects from, and write objects to, the EIS. TopLink applications use individual EIS connections returned by the EIS connection factory specified by the EIS platform.

TopLink provides a variety of `EISPlaform` classes that let you customize your project for your target EIS.

EIS platforms for production are located in `oracle.toplink.eis.adapters` package and include the following:

- `oracle.toplink.eis.adapters.aq.AQPlatform` to access an EIS using Oracle Advanced Queuing messages.

- `oracle.toplink.eis.adapters.attunity.AttunityPlatform` to access an EIS using an Attunity J2C adapter.

- `oracle.toplink.eis.adapters.jms.JMSPlatform` to access an EIS using JMS messages.

- `oracle.toplink.eis.adapters.mqseries.MQPlatform` to access an EIS using IBM MQSeries messages.

EIS platforms for testing are also located in `oracle.toplink.eis.adapters` and include the following:

- `oracle.toplink.eis.adapters.blackbox.BlackBoxPlatform` for testing your EIS project with the Sun BlackBox reference adapter using indexed records only.

- `oracle.toplink.eis.adapters.xmlfile.XMLFilePlatform` for testing your EIS project with an EIS emulated as one or more XML files in the local file system using XML records.

Specify your EIS platform at the session level (see "Configuring an EIS Data Source Platform at the Session Level").

If you set your platform in TopLink Workbench, then TopLink Workbench manages the EIS platform configuration for you automatically.

## Authentication

Authentication is the means by which a data source validates a user's identity and determines whether or not the user has sufficient privileges to perform a given action.

For two-tier applications, simple JDBC authentication is usually sufficient (see "Simple JDBC Authentication").

For three-tier applications, you can use simple JDBC authentication or, proxy authentication (see "Oracle Database Proxy Authentication") when using the Oracle Call Interface (OCI) JDBC driver.

Authentication plays a central role in data security and user accountability and auditing (see "Auditing").

### Simple JDBC Authentication

When you configure a TopLink database login with a user name and password ("Configuring User Name and Password"), TopLink provides these credentials to the JDBC driver that you configure your application to use (see "Configuring Database Login Connection Options").

By default, TopLink writes passwords to and reads them from the `sessions.xml` file in encrypted form using JCE encryption. Optionally, you can configure a different encryption class (see "Configuring Password Encryption").

### Oracle Database Proxy Authentication

TopLink supports proxy authentication with the Oracle Database in JSE applications and JEE applications using OC4J native or managed data sources with Oracle JDBC driver release 10.1.0.2.0 or later and external connection pools (see "External Connection Pools") only.

Note: TopLink does not support Oracle Database proxy authentication with JTA.

Oracle Database proxy authentication delivers the following security benefits:

- A limited trust model, by controlling the users on whose behalf middle tiers can connect, and the roles the middle tiers can assume for the user.

- Scalability, by supporting user sessions through Oracle Call Interface (OCI) and thick JDBC, and eliminating the overhead of reauthenticating clients.

- Accountability, by preserving the identity of the real user through to the database, and enabling auditing of actions taken on behalf of the real user.

- Flexibility, by supporting environments in which users are known to the database, and in which users are merely "application users" of which the database has no awareness.

Note: Oracle Database supports proxy authentication in three-tiers only; it does not support it across multiple middle tiers.

For more information about authentication in an Oracle Database, see "Preserving User Identity in Multitiered Environments" in the Oracle Database Security Guide.

Configure your TopLink database login to use proxy authentication (see "Configuring Oracle Database Proxy Authentication") to do the following:

- address the complexities of authentication in a three-tier architecture (such as client-to-middle-tier and middle-tier-to-database authentication, and client reauthentication through the middle -tier to the database)

- enhance database audit information (for even triggers and stored procedures) by using a specific user for database operations, rather than the generic pool user

- simplify VPD/OLS configuration (see "Isolated Client Sessions and Oracle Virtual Private Database (VPD)") by using a proxy user, rather than setting user information directly in the session context with stored procedures

### Auditing

Regardless of what type of authentication you choose, TopLink logs the name of the user associated with all database operations. Example 84-1 shows the `CONFIG` level TopLink logs when a `ServerSession` connects through the main connection for the sample user "scott", and a `ClientSession` uses proxy connection "jeff".

Example 84-1 TopLink Logs with Oracle Database Proxy Authentication

    [TopLink Config]--ServerSession(13)--Connection(14)--Thread(Thread[main,5,main])--connecting(DatabaseLogin( platform=>Oracle9Platform   user name=> "scott" connector=>OracleJDBC10_1_0_2ProxyConnector datasource name=>DS))
    [TopLink Config]--ServerSession(13)--Connection(34)--Thread(Thread[main,5,main])--Connected: jdbc:oracle:thin:@localhost:1521:orcl
    User: SCOTT
    [TopLink Config]--ClientSession(53)--Connection(54)--Thread(Thread[main,5,main])--connecting(DatabaseLogin(platform=>Oracle9Platform user name=> "scott" connector=>OracleJDBC10_1_0_2ProxyConnector datasource name=>DS))
    [TopLink Config]--ClientSession(53)--Connection(56)--Thread(Thread[main,5,main])--Connected: jdbc:oracle:thin:@localhost:1521:orcl
    User: jeff

For more information on configuring TopLink log level and log options, see "Configuring Logging".

Your database server likely provides additional user auditing options. Consult your database server documentation for details.

Alternatively, you may consider using the TopLink unit of work in conjunction with your database schema for auditing purposes (see "Implementing User and Date Auditing with the Unit of Work").

## Connections

A connection is an object that provides access to a data source by way of the driver you configure your application to use (see "Configuring Database Login Connection Options"). Relational projects use JDBC to connect to the data source; EIS and XML projects use JCA. TopLink uses the interface `oracle.toplink.internal.databaseaccess.Accessor` to wrap data source connections. This interface is accessible from certain events (see "Descriptor Event Manager").

Typically, when using a server session, TopLink uses a a different connection for both reading and writing. This allows you to use nontransactional connections for reading and avoid maintaining connections when not required. CMP applications typically use the same connection for both reading and writing. See "Reading Through the Write Connection" and "Exclusive Write Connections" for more information.

By default, a TopLink server session acquires connections lazily: that is, only during the commit operation of a unit of work. Alternatively, you can configure TopLink to acquire a write connections at the time you acquire a client sessions (see "Lazy Connection Acquisition").

Connections can be allocated from internal or external connection pools (see "Connection Pools").

## Connection Pools

A connection pool is a service that creates and maintains a shared collection (pool) of data source connections on behalf of one or more clients. The connection pool provides a connection to a process on request, and returns the connection to the pool when the process is finished using it. When it is returned to the pool, the connection is available for other processes. Because establishing a connection to a data source can be time-consuming, reusing such connections in a connection pool can improve performance.

TopLink uses connection pools to manage and share the connections used by server and client sessions. This feature reduces the number of connections required and allows your application to support many clients.

You can configure your session to use internal connection pools provided by TopLink or external connection pools provided by a JDBC driver or J2EE container.

You can use connection pools in your TopLink application for a variety of purposes, such as reading, writing, sequencing, and other application-specific functions.

This section describes the following:

- Internal Connection Pools

- External Connection Pools

- Default (Write) and Read Connection Pools

- Sequence Connection Pools

- Application-Specific Connection Pools

### Internal Connection Pools

For non-J2EE applications, you typically use internal connection pools. By default, TopLink sessions use internal connection pools.

Using internal connection pools, you can use TopLink Workbench to configure the default (write) and read connection pools (see "Default (Write) and Read Connection Pools") and you can create additional connection pools for object identity (see "Sequence Connection Pools"), or any other purpose (see "Application-Specific Connection Pools").

Using internal connection pools, you can optimize the creation of read connections for applications that read data only to display it and only infrequently modify data (see "Configuring a Nontransactional Read Login").

For information on selecting the type of connection pool to use, see "Configuring External Connection Pooling".

For more information on creating and configuring internal connection pools, see:

- "Internal Connection Pool Creation Overview"

- "Internal Connection Pool Configuration Overview"

### External Connection Pools

For J2EE applications, you typically use external connection pools.

If you are using an external transaction controller (JTA), you must use external connection pools to integrate with the JTA (see "Integrating the Unit of Work With an External Transaction Service").

Using external connection pools, you must use Java to configure the default (write) and read connection pools (see "Default (Write) and Read Connection Pools") and create additional connection pools for object identity (see "Sequence Connection Pools"), or any other purpose (see "Application-Specific Connection Pools").

For more information on selecting the type of connection pool to use, see "Configuring External Connection Pooling".

### Default (Write) and Read Connection Pools

When you use internal TopLink connection pools, a session provides a read connection pool and a write connection pool.

All read queries use connections from the read connection pool and all queries that write changes to the data source use connections from the write connection pool. You can configure attributes of the default read and write connection pools.

Whenever a new connection is established, TopLink uses the connection configuration you specify in your session's `DatasourceLogin`. Alternatively, when you use an external transaction controller, you can define a separate connection configuration for a read connection pool to avoid the additional overhead, if appropriate (see "Configuring a Nontransactional Read Login").

For more information on configuring read and write connection pools, see "Internal Connection Pool Configuration Overview".

### Sequence Connection Pool s

An essential part of maintaining object identity (see "Cache Type and Object Identity") is sequencing–managing the assignment of unique values to distinguish one instance from another. For more information, see "Projects and Sequencing".

Sequencing involves reading and writing a special sequence resource maintained by your data source.

By default, TopLink includes sequence operations in the current transaction. This avoids the complicating the write transaction, which may lead to deadlocks over the sequence resource. However, when using an external transaction controller (such as a JTA data source or connection pool), TopLink cannot use a different transaction for sequencing. Use a sequence connection pool to configure a non-JTA transaction pool for sequencing. This is required only for table sequencing – not native sequencing.

In each server session, you can create one connection pool, called a sequence connection pool, that TopLink uses exclusively for sequencing. With a sequence connection pool, TopLink satisfies a request for a new object identifier outside of the transaction from which the request originates. This allows TopLink to immediately commit an update to the sequence resource, which avoids deadlocks.

Note: If you use a sequence connection pool and the original transaction fails, the sequence operation does not roll back.

You should use a sequence connection pool, if the following applies:

- You use table sequencing (that is, non-native sequencing). See "Table Sequencing" and "Unary Table Sequencing" for more information.

- You use external transaction controller (JTA).

You should not use a sequence connection pool, if the following applies:

- You do not use sequencing, or use the data source's native sequencing (see "Native Sequencing With an Oracle Database Platform" and "Native Sequencing With a Non-Oracle Database Platform").

- You have configured the sequence table to avoid deadlocks.

- You use non-JTA data sources.

For more information, see

- "Internal Connection Pool Creation Overview"

- "Internal Connection Pool Configuration Overview"

### Application-Specific Connection Pools

When you use internal TopLink connection pools in a session, you can create one or more connection pools that you can use for any application purpose. These are called named connection pools, as you can give them any name you want and use them for any purpose.

Typically, use these named connection pools to provide pools of different security levels. For example, the "default" connection pool may only allow access to specific tables but the "admin" connection pool may allow access to all tables.

For more information, see the following:

- "Internal Connection Pool Creation Overview"

- "Internal Connection Pool Configuration Overview"

- "Acquiring a Client Session that Uses a Named Connection Pool"