PATH Documentation > WebObjects

Up Previous Next

Fetching with an Editing Context

Synopsis

Describes how to fetch enterprise objects with an editing context.

Discussion

Instead of using a display group to fetch objects, you can fetch enterprise objects directly with an EOEditingContext. Fetching from an EOEditingContext gains you more control over how the objects are fetched and enables you to directly manipulate the object graph. To fetch objects with an editing context involves these steps:

Obtain an editing context.

For WebObjects applications, each session has its own editing context which is obtained by sending the defaultEditingContext message to the session:

 
anEditingContext = [[self session] defaultEditingContext];

Otherwise you can simply create an editing context.

 
anEditingContext = [EOEditingContext new];
  1. Create a fetch specification.

The fetch specification is an EOFetchSpecification object that tells EOF which objects you want to fetch and the order they should appear. See the programming topic "Creating Fetch Specifications Programmatically" to find out how to create the fetch specification. An example is given below.

 
aQualifier = [EOQualifier qualifierWithQualifierFormat:    @"lastName = 'Smith'"];aFetchSpecification = [EOFetchSpecification fetchSpecificationWithEntityName:    @"Employee" qualifier: aQualifier sortOrderings:nil];
  1. Fetch the objects with the editing context.

You use the method objectsWithFetchSpecification which returns an array of enterprise objects that meets the fetch specification you have defined.

 
NSArray * results = [anEditingContext    objectsWithFetchSpecification: aFetchSpecification];

EOUtilities Convenience API

The EOUtilities Application Program Interface (API) is a collection of convenience methods to simplify common operations with EOF. It is implemented as a category on EOEditingContext in Objective-C and as an abstract class in Java. To perform the fetch above using EOUtilities use:

 
NSArray *Smiths = [[[self session] defaultEditingContext]    objectsMatchingValue:@"Smith" forKey:@"lastName"    entityNamed:@"Employee"];

See Also

Questions

Keywords

Revision History

20 July, 1998. Winnie Pun. First Draft.

16 November, 1998. Clif Liu. Second Draft.

 

© 1999 Apple Computer, Inc.

Up Previous Next