File:  [NeXTSTEP 3.3 examples] / Examples / EnterpriseObjects / MasteringDetails / EOFExtensions.subproj / KeyGenerator.h
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 17:48:56 2018 UTC (8 years, 1 month ago) by root
Branches: NeXT, MAIN
CVS tags: NeXTSTEP33, HEAD
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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.