home *** CD-ROM | disk | FTP | other *** search
/ OpenStep (Enterprise) / OpenStepENTCD.toast / OEDEV / EODEV.Z / fetch_main.m < prev    next >
Encoding:
Text File  |  1996-08-31  |  1.7 KB  |  59 lines

  1. /*
  2.         Copyright (c) 1996, NeXT Software, Inc.
  3.         All rights reserved.
  4.  
  5.         You may freely copy, distribute and reuse the code in this example.
  6.         NeXT disclaims any warranty of any kind, expressed or implied,
  7.         as to its fitness for any particular use.
  8. */
  9. #import <EOAccess/EOAccess.h>
  10.  
  11. void usage(void);
  12.  
  13. void fetch(void)
  14. {
  15.   NSString *modelPath = [[NSUserDefaults standardUserDefaults] stringForKey:@"model"];
  16.   NSString *entityName = [[NSUserDefaults standardUserDefaults] stringForKey:@"entity"];
  17.   EOEditingContext *editingContext = [EOEditingContext new]; // context with defaultCoordinator
  18.  
  19.   NSArray *results;
  20.  
  21.   if(!modelPath || !entityName) {
  22.     usage();
  23.     return;
  24.   }
  25.  
  26.   // For apps with models stored in the main bundle, the following is
  27.   // unnecessary, since the defaultGroup will be automatically built from
  28.   // the contents of the main bundle and and any referenced frameworks.
  29.   [EOModelGroup setDefaultGroup:[[EOModelGroup new] autorelease]];
  30.   [[EOModelGroup defaultGroup] addModelWithFile:modelPath];
  31.  
  32.   // Fetch objects from our context
  33.   results = [editingContext objectsWithFetchSpecification:[EOFetchSpecification fetchSpecificationWithEntityName:entityName qualifier:nil sortOrderings:nil]];
  34.   
  35.   NSLog(@"Result: %@", results);
  36. }
  37.  
  38. void usage(void)
  39. {
  40.     NSLog(@"Usage: fetch -model <full path for an eomodeld file> -entity <entity name>");
  41. }
  42.  
  43.  
  44. int main (int argc, const char *argv[])
  45. {
  46.    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
  47.  
  48.    NS_DURING
  49.      fetch();
  50.    NS_HANDLER
  51.      NSLog(@"%@", [localException reason]);
  52.    NS_ENDHANDLER
  53.  
  54.    [pool release];
  55.    exit(0);       // insure the process exit status is 0
  56.    return 0;      // ...and make main fit the ANSI spec.
  57. }
  58.  
  59.