|
|
1.1 ! root 1: /* Controller.m: ! 2: * You may freely copy, distribute, and reuse the code in this example. ! 3: * NeXT disclaims any warranty of any kind, expressed or implied, as to its ! 4: * fitness for any particular use. ! 5: * ! 6: * Written by Mai Nguyen, NeXT Developer Support ! 7: * ! 8: */ ! 9: #import <dbkit/dbkit.h> ! 10: #import <libc.h> ! 11: #import "Controller.h" ! 12: #import "QualifiedAssociation.h" ! 13: ! 14: /* Define localized strings */ ! 15: #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.") ! 16: ! 17: @implementation Controller ! 18: ! 19: /* At init time, the proper association is set up between the master fetchgroup ! 20: * and the detail fetchgroup, such that whenever a fetch happens, that fetch ! 21: * will be done with the specified qualifier. ! 22: */ ! 23: -appDidInit:sender ! 24: { ! 25: id dbDatabase; ! 26: ! 27: /* Notify the user if the database can't be found */ ! 28: if ( (dbDatabase = [DBDatabase findDatabaseNamed:"OracleDemo" connect:YES]) == nil) { ! 29: NXRunAlertPanel(NULL, INSTALL_MODEL, "OK", NULL, NULL); ! 30: return self; ! 31: } ! 32: [dbDatabase setDelegate:self]; ! 33: ! 34: detailFetchGroup = [departmentTable fetchGroupNamed:"employees"]; ! 35: ! 36: /* Set up the new association. ! 37: Note that the new association now belongs to the DBModule ! 38: just as the old one did. */ ! 39: newAssociation = [[QualifiedAssociation alloc] ! 40: initAndReplaceAssociationTo:detailFetchGroup]; ! 41: dbQualifier = [[DBQualifier alloc] ! 42: initForEntity:[detailFetchGroup entity] ! 43: fromDescription: "%p > 1000", "salary"]; ! 44: [newAssociation setQualifier: dbQualifier]; ! 45: [departmentTable fetchAllRecords:sender]; ! 46: [theWindow makeKeyAndOrderFront:nil]; ! 47: return self; ! 48: } ! 49: ! 50: - changeQualifier:sender ! 51: { ! 52: if (dbQualifier) ! 53: [dbQualifier free]; ! 54: dbQualifier = [[DBQualifier alloc] ! 55: initForEntity:[detailFetchGroup entity] ! 56: fromDescription: "%p > %d", "salary", (int)[salaryField intValue]]; ! 57: [newAssociation setQualifier: dbQualifier]; ! 58: [departmentTable fetchAllRecords:sender]; ! 59: return self; ! 60: } ! 61: ! 62: - free ! 63: { ! 64: if (dbQualifier) ! 65: [dbQualifier free]; ! 66: if (newAssociation) ! 67: [newAssociation free]; ! 68: return [super free]; ! 69: } ! 70: ! 71: /* For debugging purpose */ ! 72: - (BOOL)db:aDb willEvaluateString:(const unsigned char*)aString ! 73: usingBinder:aBinder ! 74: { ! 75: fprintf(stderr, "SQL Query: %s\n", (char *)aString); ! 76: return YES; ! 77: } ! 78: ! 79: @end ! 80:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.