|
|
1.1 ! root 1: {\rtf0\ansi{\fonttbl\f2\fswiss Helvetica;\f4\fmodern Courier;\f0\fnil Times-Roman;\f3\fmodern Ohlfs;} ! 2: \paperw10800 ! 3: \paperh9980 ! 4: \margl120 ! 5: \margr100 ! 6: {\colortbl;\red0\green0\blue0;} ! 7: \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f2\b\i0\ulnone\fs36\fc0\cf0 PeopleDemo ! 8: \b0\fs24 \ ! 9: by Mai Nguyen, NeXT Developer Support Team\ ! 10: \ ! 11: ! 12: \b\fs28 Overview\ ! 13: ! 14: \b0\fs24 \ ! 15: This example shows how to manipulate records using the EOController API and its delegation mechanism. A simple validation scheme is used to validate the user input before an actual insert or update to the database server.\ ! 16: ! 17: \fc1\cf1 \ ! 18: ! 19: \b\fs28 Program Organization ! 20: \b0\fs24 \ ! 21: \ ! 22: ! 23: \b How to build a master-detail view ! 24: \b0 \ ! 25: To build a master-detail view, you need to drag and drop the ! 26: \b People.eomodel ! 27: \b0 file into IB and select Deparment as the root entity. This will generate an EOController which corresponds to the Department table. You also have to drag and drop another EOController from the EOPalette into the File Window of your NIB file. Then, by connecting the ! 28: \b toEmployee ! 29: \b0 one-to-many relationship to this second controller, it will become the detail controller which corresponds to the Employee table. \ ! 30: \ ! 31: Note that the Department EOController has "Buffer Edits" turned ON. This means that modifications to the record are buffered until you explicitly select the ! 32: \i Modify ! 33: \i0 button. On the other hand, "Buffer Operations" is OFF, which means that modifying a record is automatically affecting the server. You can see the UPDATE statement in the SQL panel by selecting the menu option "Show SQL...".\ ! 34: \ ! 35: ! 36: \b User Interface ! 37: \b0 \ ! 38: ! 39: \fc0\cf0 The User Interface is composed of one window and two panels:\ ! 40: � The main window shows the Department and the Employee tables in a master-detail view.\ ! 41: ! 42: \fi-220\li220 � A Fetch Options panel builds a new sorting order and a simple qualifier based on the user input. \ ! 43: ! 44: \fi-240\li240 � A SQL tracing panel shows the SQL statements generated during the insert/update/delete operations.\ ! 45: ! 46: \fi0\li0\fc1\cf1 \ ! 47: \ ! 48: ! 49: \b Major Classes in the Application ! 50: \b0 \ ! 51: \ ! 52: ! 53: \pard\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fi-1900\li1900\fc1\cf1 MainController A subclass of Object. It coordinates the fetch, insert, and delete operations. It also manages validation of the record before an insert or update actually happens. \ ! 54: ! 55: \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc1\cf1 \ ! 56: ! 57: \pard\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fi-1900\li1900\fc1\cf1 Department The Department object corresponds to the Department table in the People database. This example of an enterprise object shows how to manipulate additional data not contained in the model file (the averageSalary). \ ! 58: ! 59: \pard\tx560\tx1120\tx2060\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\fi-2060\li2060\fc1\cf1 \ ! 60: \ ! 61: ! 62: \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\b\fc1\cf1 Other Peculiarities ! 63: \b0 \ ! 64: ! 65: \pard\tx560\tx1120\tx2060\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\fi-2060\li2060\fc1\cf1 To load the adaptors dynamically, you need to add the option:\ ! 66: ! 67: \f4 OTHER_LDFLAGS = -all_load\ ! 68: ! 69: \f2 in your Makefile.preamble.\ ! 70: \ ! 71: ! 72: \pard\tx560\tx1120\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\fc1\cf1 This application includes the following libraries in the Project Builder's libraries suitcase: libEOInterface_s.a, libEOAccess_s.a, and libFoundation_s.a.\ ! 73: \ ! 74: To take advantage of the AutoRelease Pool, the Application class of this example is defined as EOApplication. To do so, select Attributes in Project Builder, and enter ! 75: \i EOApplication ! 76: \i0 in the TextField labeled App. Class. You also need to change the File Owner's Application class to ! 77: \i EOApplication. ! 78: \i0 Finally, you need to edit your PeopleDemo_main.m file to change the import line to #import <eointerface/EOApplication.h>.\ ! 79: \ ! 80: ! 81: \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\b\fs28\fc1\cf1 Topics Of Interest\ ! 82: ! 83: \b0\fs24 \ ! 84: ! 85: \pard\tx520\tx1060\tx1600\tx2120\tx2660\tx3200\tx3720\tx4260\tx4800\tx5320\b\fc1\cf1 How to validate the user input before an Update ! 86: \b0 \ ! 87: This is done in the controller delegate method - ! 88: \f4 (NSDictionary*)controller:(EOController *)controller willSave: (NSDictionary *)edits object:object\ ! 89: ! 90: \pard\tx520\tx1060\tx1600\tx2120\tx2660\tx3200\tx3720\tx4260\tx4800\tx5320\f0\fs28\fc1\cf1 \ ! 91: ! 92: \f2\fs24 Please see the Validation example for a more powerful approach to perform validation.\ ! 93: ! 94: \pard\tx520\tx1060\tx1600\tx2120\tx2660\tx3200\tx3720\tx4260\tx4800\tx5320\f0\fs28\fc1\cf1 \ ! 95: ! 96: \f2\b\fs24 How to properly delete a master record ! 97: \b0 \ ! 98: When deleting a master record, the associated detail records are not deleted. However, since the Employee detail record refers to the master record with the DeptId foreign key, those keys must be properly nulled out in the associated detail records.\ ! 99: ! 100: \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc1\cf1 \ ! 101: ! 102: \pard\tx520\tx1060\tx1600\tx2120\tx2660\tx3200\tx3720\tx4260\tx4800\tx5320\b\fc1\cf1 Debugging/Tracing ! 103: \b0 \ ! 104: There are two types of debugging and tracing methods:\ ! 105: 1) In the file MainController.m, the adaptor channel method ! 106: \b setDebugEnabled: ! 107: \b0 will trace all operations that go through the adaptor channel.\ ! 108: 2) In the file Department.m, the method ! 109: \b respondsTo: ! 110: \b0 will show what methods your enterprise object can respond to. ! 111: \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc1\cf1 \ ! 112: To turn the verbose mode on, you can add the following option in your Makefile.preamble:\ ! 113: ! 114: \pard\tx560\tx1120\tx2060\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\f4\fi-2060\li2060\fc1\cf1 OTHER_CFLAGS = -DDEBUG\ ! 115: ! 116: \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f2\fc1\cf1 \ ! 117: ! 118: \b\fs28 \ ! 119: Tips for moving from a Sybase to an Oracle database\ ! 120: \ ! 121: ! 122: \b0\fs24 As you may have noticed, the two examples PeopleDemo_oracle and PeopleDemo_sybase have identical source codes and nib files. When moving from a Sybase to an Oracle based example, you'll need to create a new ! 123: \b .eomodel ! 124: \b0 file from the new server. However, if you keep the internal names of the database as well as the external names identical, you won't have to redo all the connections inside Interface Builder. Naturally, you should also test your new Oracle application to make sure that it behaves exactly like the version on Sybase.\ ! 125: \ ! 126: ! 127: \b\fs28 \ ! 128: SQL scripts and Model Files\ ! 129: ! 130: \pard\tx2880\tx2900\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\b0\fs24\fi-2880\li2880\fc0\cf0 installPEOPLE.sqlsybase\ ! 131: installPEOPLE.sqloracle Used to create and restore the databases for Sybase and Oracle \ ! 132: \ ! 133: See the PeopleDBScripts directory\ ! 134: \ ! 135: sybasePeople.eoModel\ ! 136: oraclePeople.eoModel Model files to use respectively for Sybase or Oracle.\ ! 137: \ ! 138: \ ! 139: ! 140: \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc1\cf1 \ ! 141: ! 142: \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc1\cf1 Valid for NEXTSTEP Release 3.2 installed with the Enterprise Objects Framework Release 1.0\ ! 143: \ ! 144: June 1994 Created example\ ! 145: September 1994 Modified for EOF Final Version ! 146: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.