PATH |
Generating Primary Key Values
Synopsis
Describes how the primary key is generated for a new object in EOF. It also explains the various ways the user can generate a primary key.
Description
Primary keys are used in a database to identify a row in a table. Each key is generated on the client side before its corresponding row is inserted into the database.
There are several ways to generate the primary key, some of which are outlined below.
Class Property of an Enterprise Object
The primary key can be generated by the user in the Enterprise Object (EO) when it is created. EOModeler allows the primary key to be made a class property and hence, an instance variable of the Enterprise Object. The user has the responsibility of creating a unique primary key each time a new EO is instantiated.
Adaptor-Generated Primary Key
In Enterprise Objects Framework's default primary key mechanism, the EOAdaptorChannel generates the primary keys. It collaborates with the database server to maintain a linear sequence of nonrepeating primary keys per entity. The primary key attribute must not be a class property. If the type of the primary key attribute is a 12-byte NSData, EOF generates unique primary keys without going to the database.
Delegate of the Database Context
Before using the adaptor's default primary key generation, the EODatabaseContext's delegate is given a chance to generate the primary key. This method is used only if it satisfies the following conditions
Custom Stored Procedure
The user can create a stored procedure for the generation of the primary keys and add it to model. The stored procedure is set as the primary key stored procedure for the entity.
Propagation of Primary Keys
The EOModeler allows the user to set the "Propagate Primary Key" in the advanced relationship inspector. When the user creates an object within an entity, that entity's primary key is used as the primary key for the new object.
For example, a column in table A can be the primary key for table A, as well as the foreign key to a table B.
See Also
- EOTemporaryGlobalID class specification in the Enterprise Objects Framework Reference
- EOUtilities class specification (Java) in the Enterprise Objects Framework Reference
- EOUtilities category specification (Objective-C) in the Enterprise Objects Framework Reference
- Accessing Non-Class Property Values
Questions
- How do I generate primary key using stored procedures?
- How do I generate primary key using the delegate of the database context?
- How do I generate primary key using class properties?
- How do I propagate primary keys?
- How do I generate primary key using the default primary key generation mechanism?
- How do I generate a primary key at the adaptor layer without a database transaction?
Revision History
22 July, 1998. Seejo Pylappan. First Draft.
19 November, 1998. Clif Liu. Second Draft.
© 1999 Apple Computer, Inc.