Adapter Development Kit 6.5 | webMethods Adapter Development Kit Documentation | webMethods Adapter Development Kit Installation and User’s Documentation | Run Time Activities | Run Time Connection Allocation for Adapter Services | Implementing Partitioned Connection Pools | Updating the Connection Factory
 
Updating the Connection Factory
To complete support for the partitioned connection pool feature, the adapter's WmManagedConnectionFactory implementation must be able to produce valid WmConnectionRequestInfo objects and it must be able to use those objects to create connections with the required characteristics.
As shown in the sample MegaBank code below, the implementation of getConnectionRequestInfo() uses information from the provided ConnectionSpec object to produce a valid ConnectionRequestInfo object. In this case, the MegaBank user name is used as a key to lookup a set of user ID and credentials appropriate for the backend being accessed by this connection. (Details of how this lookup is implemented are adapter-specific and outside the scope of this document.)
/**
* Produce a ConnectionRequestInfo object based on the provided ConnectionSpec
* object. If an mbUserName is provided, lookup the name to use on the backend
* for this connection pool.
*/
public ConnectionRequestInfo getConnectionRequestInfo(ConnectionSpec spec)
{
MbConnectionRequestInfo partitionDef = null;
if(spec != null && spec instanceof MbConnectionSpec)
{
synchronized(this)
{
try
{
String mbUserName = ((MbConnectionSpec)spec).getMbUserName();
lookupUser(mbUserName);
partitionDef = new MbConnectionRequestInfo(mbUserName,
this.backendUserID, this.credentials);
}
catch(IllegalArgumentException ex)
{
// no partition info available for this user. Swallow the
// exception and return null
}
}
}
return partitionDef
}
When the connection pool needs a new connection belonging to a particular partition, the ConnectionRequestInfo object returned above is passed to the createManagedConnectionObject method. In the sample code shown below, this information is used to override default logon information that is otherwise established based on metadata parameter settings. Note that all createManagedConnectionObject implementations must be able to establish default-partition connections when null is passed in the cxRequestInfo argument.
/**
* Create a connection using userId and credentials from the provided
* connectionRequestInfo object, if provided. If connectionRequestInfo is
* not provided use the default userId and credentials information established
* at node startup from metadata parameters.
*/
public WmManagedConnection createManagedConnectionObject(Subject subject,
ConnectionRequestInfo cxRequestInfo) throws ResourceException
{
String connUser;
Credentials connCredentials;
if (cxRequestInfo != null && cxRequestInfo instanceof
MbConnectionRequestInfo)
{
connUser = ((MbConnectionRequestInfo)cxRequestInfo).getUserId();
connCredentials =
((MbConnectionRequestInfo)cxRequestInfo).getCredentials();
}
else
{
connUser = this.defaultUserId;
connCredentials = this.defaultCredentials;
}
return new MbConnection(connUser, connCredentials);
}