home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.1 (Developer) [x86] / NeXT Step 3.1 Intel dev.cdr.dmg / NextDeveloper / Examples / DatabaseKit / AssociationOracle / Controller.m < prev    next >
Encoding:
Text File  |  1993-03-30  |  2.2 KB  |  79 lines

  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.     dbQualifier = [[DBQualifier alloc] 
  53.             initForEntity:[detailFetchGroup entity]
  54.             fromDescription: "%p > %d", "salary", (int)[salaryField intValue]];
  55.     [newAssociation setQualifier: dbQualifier];
  56.     [departmentTable fetchAllRecords:sender];
  57.     return self;
  58. }
  59.  
  60. - free
  61. {
  62.     if (dbQualifier)
  63.         [dbQualifier free];
  64.     if (newAssociation)
  65.         [newAssociation free];
  66.     return [super free];
  67. }
  68.  
  69. /* For debugging purpose */
  70. - (BOOL)db:aDb willEvaluateString:(const unsigned char*)aString
  71.      usingBinder:aBinder
  72. {
  73.     fprintf(stderr, "SQL Query: %s\n", (char *)aString);
  74.     return YES;
  75. }
  76.     
  77. @end
  78.  
  79.