If you're not using a predefined fetch specification, you set the fetch limit programmatically using EOFetchSpecification's setFetchLimit method (setFetchLimit: in Objective-C) passing an integer value indicating the maximum number of objects to fetch (an unsigned integer value in Objective-C). The default value is zero, indicating no fetch limit.
The EODatabaseContext will either stop fetching objects when this limit is reached or ask the EOEditingContext's message handler to ask the user whether it should continue fetching. The default behavior simply stops fetching, so if you want to prompt the user, send setPromptsAfterFetchLimit (setPromptsAfterFetchLimit: in Objective-C) to the fetch specification with true (YES in Objective-C) as the argument. For more information on managing fetch limits, see the EOFetchSpecification class description and the EOEditingContext EOMessageHandlers interface description in the Enterprise Objects Framework Reference.
However, EODatabaseContext doesn't fetch related objects immediately, since they may never be accessed and fetching can be expensive. Instead the destination objects created are stand-ins, called faults, that fetch their data the first time they're accessed.
When a fault is accessed (sent a message for which it must get its data to respond), it triggers its EODatabaseContext to fetch its data and finish initializing it. This works well for limited numbers of objects. However, suppose you fetch multiple employees and then want to retrieve each employee's department. You'd have to loop over all of the employees and fetch each employee's department fault individually, resulting in numerous trips to the database.
To avoid these unnecessarily trips to the database, you can fine-tune faulting behavior for additional performance gains by using two different mechanisms: batch faulting, and prefetching relationships.
You can configure batch faulting in a model with EOModeler. With this approach, you specify the number of faults for the same entity or relationship that should be triggered along with the first fault. For more information on setting batch faulting in an EOModel, see Enterprise Objects Framework Tools and Techniques.
To actually control which faults are triggered along with the first one, you can use the EODatabaseContext method batchFetchRelationship (batchFetchRelationship:forSourceObjects:editingContext: in Objective-C). For example, given an array of Employee objects, this method can fetch all of their departments with one round trip to the server, rather than asking the server for each of the employee's departments individually. For more information, see the EOFetchSpecification class description in the Enterprise Objects Framework Reference.
If you define your fetch specification in a model, you can configure its prefetching behavior in EOModeler. For more information, see Enterprise Objects Framework Tools and Techniques.
Alternatively, you can programmatically set prefetching relationships by sending setPrefetchingRelationshipKeyPaths (setPrefetchingRelationshipKeyPaths: in Objective-C) to an EOFetchSpecification object and passing an array of relationship key paths whose destinations should be fetched along with the objects specified. For more information, see the EOFetchSpecification class description in the Enterprise Objects Framework Reference.
To set up object caching on an entity, you can use the Advanced Entity Inspector in EOModeler or you can do it programmatically using the EOEntity method setCachesObjects (setCachesObjects: in Objective-C). For more information on configuring object caching in EOModeler, see Enterprise Objects Framework Tools and Techniques, and for more information on object caching, see the EOEntity class specification in the Enterprise Objects Framework Reference.
In Java:
// Get the name of the Employee's departmentIn Objective-C:
employee.department().departmentName();
// Set the name of the employee's department
employee.department().setDepartmentName(newName);
// Get the name of the Employee's departmentFor more discussion of this subject, see the chapter "Designing Enterprise Objects".
[[employee department] departmentName];
// Set the name of the employee's department
[[employee department] setDepartmentName:newName];
Use Inheritance Wisely
As discussed in the chapter "Designing Enterprise Objects," the way that you map an object hierarchy onto a relational database in your EOModel can have a significant effect on performance. You should observe the following guidelines:
Ideally, you should store BLOBs in their own table away from more commonly accessed attributes.
This "universal" refresh is sometimes necessary because EOAssociations may display derived values (through key paths or business methods) that depend on objects other than the ones being displayed. However, if you know that your user interface doesn't display derived data, you can specify that an EODisplayGroup's EOAssociation objects be refreshed only if the EODisplayGroup objects change.
There are different ways to accomplish this:
In Java:
myDisplayGroup.setUsesOptimisticRefresh(true);
In Objective-C:
[myDisplayGroup setUsesOptimisticRefresh:YES];
This is equivalent to unchecking "Refresh All" in Interface Builder for myDisplayGroup.
Table of Contents Next Section