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

Table of Contents Previous Section

Object Store Coordinator Configurations

Recall that by default, all the EOEditingContexts in an application share the same EOObjectStoreCoordinator (see "Sharing Editing Contexts and Coordinators"). In this default configuration, all of a coordinator's editing contexts are synchronized with one another after any of the editing contexts save changes. Also, the editing contexts share underlying database connections wherever possible. This default behavior is typically what you want, but there are a some rare situations in which you might need more than one EOObjectStoreCoordinator.

All entity names must be unique within the scope of an EOObjectStoreCoordinator, so you need multiple coordinators when your application uses more than one connection to a database and each connection uses entities with the same name. For example, the following scenarios require multiple coordinators:

As shown in Figure 44, using an additional coordinator influences the number of database connections your application maintains.

Figure 44. Multiple EOObjectStoreCoordinators

The following sections describe how to create multiple coordinators. After you create an EOObjectStoreCoordinator, it takes care of setting up its underlying network of objects as described in the sections "Inside EOObjectStoreCoordinator"
and "Inside EODatabaseContext".

Setting Up Multiple Coordinators Programmatically

If you are creating your EOEditingContexts programmatically, assigning unique EOObjectStoreCoordinators wherever necessary is straightforward. You simply:

In Java:

EOObjectStoreCoordinator coordinator =
new EOObjectStoreCoordinator();
EOEditingContext ec = new EOEditingContext(coordinator);
In Objective-C:

EOObjectStoreCoordinator *coordinator =
[[[EOObjectStoreCoordinator alloc] init] autorelease];
EOEditingContext *ec = [[EOEditingContext alloc]
initWithParentObjectStore:coordinator];

Setting Up Multiple Coordinators Using Nibs

If you are unarchiving your EOEditingContexts from nib files, you can specify a unique EOObjectStoreCoordinator using the EOEditingContext method setDefaultParentObjectStore (setDefaultParentObjectStore: in Objective-C) as follows:

In Java:

EOObjectStoreCoordinator coordinator =
new EOObjectStoreCoordinator();
EOEditingContext.setDefaultParentObjectStore(coordinator );
NSApplication.loadNibNamed("MyNib", this);
EOEditingContext.setDefaultParentObjectStore(null);
In Objective-C:

EOObjectStoreCoordinator *coordinator =
[[[EOObjectStoreCoordinator alloc] init] autorelease];
[EOEditingContext
setDefaultParentObjectStore:coordinator];
[NSApplication loadNibNamed:@"MyNib" owner:self];
[EOEditingContext setDefaultParentObjectStore:nil];
After setting the default object store coordinator, new editing contexts (such as the one being unarchived from the nib) use the new EOObjectStoreCoordinator. After loading the nib, set the default parent object store back to the default EOObjectStoreCoordinator by sending a setDefaultParentObjectsStore message with null (nil) as the argument.

Table of Contents Next Section