|
|
Sample Programs from NeXSTEP 3.3
/* KeyGenerator.h created by cfeder on Wed 26-Oct-1994 */
#import <eoaccess/eoaccess.h>
// This code provides an example of a generic key generation facility.
// This implementation is closely related to the UniqueKey example
// in /NextDeveloper/Examples/EnterpriseObjects. See the README file
// there for more information.
@interface KeyGenerator : NSObject
{
EODatabaseDataSource *dataSource;
EOEntity *entity;
id currentMaxRecord; // uniqued object from the database
unsigned lastGranted, lastReserved;
}
- initWithEntity:(EOEntity *)entity dataSource:(EODatabaseDataSource *)dataSource;
- (unsigned)nextKey;
+ keyGeneratorForEntity:(EOEntity *)entity;
// Returns a key generator object for the given entity.
// If called repeatedly with the same entity, returns the the same object.
+ (unsigned)nexKeyForEntity:(EOEntity *)entity;
// Convenience for [[KeyGenerator keyGeneratorForEntity] nextKey]
@end
// Informal protocol on object to tell them to assign
// themselves primary keys. EO classes may want to override
// this with their own key generation scheme. The default implementation
// uses the KeyGenerator (above).
@interface NSObject (assignPrimaryKey)
- (void)assignPrimaryKeyForEntity:(EOEntity *)entity;
// uses the key generator to assign a new primary key to the entity
- (void)assignPrimaryKeyIfNotAlreadyPresentForEntity:(EOEntity *)entity;
// does the above only if the object does not already have a
// primary key assigned.
@end
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.