Documentation Archive Developer
Search
PATH  Documentation > WebObjects 4.5 > EOF Developer's Guide

Table of Contents Previous Section

Using Multiple EODatabaseChannels

By default, an EODatabaseContext uses one EODatabaseChannel. However, occasionally your application needs more channels. Conflicts due to "busy channels" can occur when an EODatabaseContext needs to perform a database operation and its EODatabaseChannel is already fetching. Most such conflicts are manifestations of inefficient database access and can be avoided. For more information, see the section "Cautions in Implementing Accessor Methods" in the chapter "Designing Enterprise Objects." However, if you can't eliminate fetching conflicts, using additional EODatabaseChannels is an option.

When an EODatabaseContext needs a new channel because all its current channels are busy, it posts an EODatabaseChannelNeededNotification. If you add yourself as an observer of this notification, you can create new EODatabaseChannels on demand. (For more information on registering for notifications, see the NSNotification and NSNotificationCenter class specifications in the Foundation Reference.)

Note: You should set an upper limit on the number of EODatabaseChannels your application registers with an EODatabaseContext. It's very unusual for an EODatabaseContext to require more than two or three EODatabaseChannels.

The following code examples demonstrate creating a new EODatabaseChannel and registering it with an EODatabaseContext:

In Java:

EODatabaseContext context; // Assume this exists
EODatabaseChannel channel = new EODatabaseChannel(context);
if (channel) context.registerChannel(channel);
In Objective-C:

EODatabaseContext *context; // Assume this exists
EODatabaseChannel *channel = [[EODatabaseChannel alloc]
initWithDatabaseContext:context];
if (channel) [context registerChannel:channel];
The EODatabaseChannel constructor can return null if no more channels can be associated with the EODatabaseContext. Similarly, in Objective-C, the EODatabaseChannel method initWithDatabaseContext: can return nil if no more channels can be associated with the EODatabaseContext. Some database servers and their corresponding adaptors don't support multiple channels per context. For example, the Sybase adaptor only supports one EODatabaseChannel per EODatabaseContext.

Table of Contents Next Section