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.)
EODatabaseContext context; // Assume this existsIn Objective-C:
EODatabaseChannel channel = new EODatabaseChannel(context);
if (channel) context.registerChannel(channel);
EODatabaseContext *context; // Assume this existsThe 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.
EODatabaseChannel *channel = [[EODatabaseChannel alloc]
initWithDatabaseContext:context];
if (channel) [context registerChannel:channel];
Table of Contents Next Section