File:  [NeXTSTEP 3.3 examples] / Examples / DatabaseKit / AssociationOracle / Controller.m
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 17:49:00 2018 UTC (8 years, 1 month ago) by root
Branches: NeXT, MAIN
CVS tags: NeXTSTEP33, HEAD
Sample Programs from NeXSTEP 3.3

/* Controller.m:
 * You may freely copy, distribute, and reuse the code in this example.
 * NeXT disclaims any warranty of any kind, expressed or  implied, as to its
 * fitness for any particular use.
 *
 * Written by Mai Nguyen, NeXT Developer Support
 *
 */
#import	<dbkit/dbkit.h>
#import <libc.h>
#import "Controller.h"
#import "QualifiedAssociation.h"

/* Define localized strings */
#define INSTALL_MODEL NXLocalizedString("Please install OracleDemo.dbmodela into your project directory and restart.", NULL, "Notify user that OracleDemo.dbmodeal must be installed in his project directory.")

@implementation Controller

/* At init time, the proper association is set up between the master fetchgroup
 * and the detail fetchgroup, such that whenever a fetch happens, that fetch
 * will be done with the specified qualifier.
 */ 
-appDidInit:sender
{
	id	dbDatabase;

		/* Notify the user if the database can't be found */
	if ( (dbDatabase = [DBDatabase findDatabaseNamed:"OracleDemo" connect:YES]) == nil) {
		NXRunAlertPanel(NULL, INSTALL_MODEL, "OK", NULL, NULL);
		return self;
	}
	[dbDatabase setDelegate:self];
	
	detailFetchGroup = [departmentTable fetchGroupNamed:"employees"];

	  	/* Set up the new association.
		   Note that the new association now belongs to the DBModule
		   just as the old one did. */
        newAssociation = [[QualifiedAssociation alloc]
		initAndReplaceAssociationTo:detailFetchGroup];
	dbQualifier = [[DBQualifier alloc] 
			initForEntity:[detailFetchGroup entity]
			fromDescription: "%p > 1000", "salary"];
	[newAssociation setQualifier: dbQualifier];
	[departmentTable fetchAllRecords:sender];
	[theWindow makeKeyAndOrderFront:nil];
	return self;
}

- changeQualifier:sender
{
	if (dbQualifier)
		[dbQualifier free];
	dbQualifier = [[DBQualifier alloc] 
			initForEntity:[detailFetchGroup entity]
			fromDescription: "%p > %d", "salary", (int)[salaryField intValue]];
	[newAssociation setQualifier: dbQualifier];
	[departmentTable fetchAllRecords:sender];
	return self;
}

- free
{
	if (dbQualifier)
		[dbQualifier free];
	if (newAssociation)
		[newAssociation free];
	return [super free];
}

/* For debugging purpose */
- (BOOL)db:aDb willEvaluateString:(const unsigned char*)aString
     usingBinder:aBinder
{
	fprintf(stderr, "SQL Query: %s\n", (char *)aString);
	return YES;
}
	
@end


unix.superglobalmegacorp.com

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