Chapter 28 Using Connection Management


Defining connection caches

A connection cache is an internal Jaguar structure that maintains a pool of available connections to a third-tier server. All connections in the cache must share a common user name and password, all must connect to the same third-tier server, and all must use the same connectivity library.

Use Jaguar Manager to define connection caches used by your application and install them in your application's Jaguar server. See Jaguar CTS System Administration Guide for more information.

JDBC DataSource lookup

Beginning with version 3.6, Jaguar supports JNDI lookup of JDBC 2.0 DataSources to access ConnectionPoolDataSources and XADataSources, as illustrated in the following example.

Note   JNDI access to connection caches requires JDBC 2.0 drivers Only connection caches that use a JDBC 2.0 driver can be aliased to JNDI resources. Specifically, the driver must implement the javax.sql.DataSource interface.

The JNDI lookup returns a DataSource interface, regardless of the cache configuration.

_cntxtProps = New Properties();
_cntxtProps.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sybase.ejb.InitialContextFactory");
_cntxtProps.put(javax.naming.Context.PROVIDER_URL,
"iiop://<host_name>:<port>");

nameConntext = new InitalContext(cntxtProps);

_ds = (javax.sql.DataSource)
nameCntxt.lookup("java:comp/env/jdbc/myAlias2DB");

_conn = ds.getConnection();

// use the connection

_conn.close();

Application authentication

EAServer provides application authentication by allowing you to get a JDBC connection for a user name and password that you specify in the source code. This feature is supported for JDBC 2.0 ConnectionPoolDataSources only. This example gets a connection :

_ds = (javax.sql.DataSource)
nameCntxt.lookup("java:comp/env/jdbc/myAlias2DB");

_conn = ds.getConnection(user_name, password);

// use the connection

_conn.close();

An application authenticated connection acts as a shared connection. Since only a single connection can be enlisted in a transaction, you cannot get two application authenticated connections, with different user name/password combinations in the same transaction. Attempts to do so can lead to unexpected results.

 


Copyright © 2000 Sybase, Inc. All rights reserved.