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.- An application that performs two types of tasks-regular user tasks and administrative tasks
- A WebObjects application that requires users to log in with their own login information
- An application that requires multiple, simultaneous transactions open on the same database
The different types of tasks require different connections to the database. Regular user tasks go through a database connection that uses a regular user login while administrative tasks go through a database connection that uses a special administrative login. The two connections use different connection dictionaries, but otherwise use the same models. Consequently, the each connection uses the same entities.
In this scenario, you'd set up a database connection for each user session. Here, too, the database connections use different connection dictionaries, but otherwise use the same models.
Because the transactions use the same model (and potentially the same connection information), they require their own connections to the database.
Figure 44. Multiple EOObjectStoreCoordinators
and "Inside EODatabaseContext".
Setting Up Multiple Coordinators Programmatically
If you are creating your EOEditingContexts programmatically, assigning unique EOObjectStoreCoordinators wherever necessary is straightforward. You simply:
EOObjectStoreCoordinator coordinator =In Objective-C:
new EOObjectStoreCoordinator();
EOEditingContext ec = new EOEditingContext(coordinator);
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 =In Objective-C:
new EOObjectStoreCoordinator();
EOEditingContext.setDefaultParentObjectStore(coordinator );
NSApplication.loadNibNamed("MyNib", this);
EOEditingContext.setDefaultParentObjectStore(null);
EOObjectStoreCoordinator *coordinator =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.
[[[EOObjectStoreCoordinator alloc] init] autorelease];
[EOEditingContext
setDefaultParentObjectStore:coordinator];
[NSApplication loadNibNamed:@"MyNib" owner:self];
[EOEditingContext setDefaultParentObjectStore:nil];
Table of Contents Next Section