|
|
1.1 ! root 1: {\rtf0\ansi{\fonttbl\f0\fswiss Helvetica;\f1\fmodern Ohlfs;} ! 2: \paperw10800 ! 3: \paperh10600 ! 4: \margl60 ! 5: \margr100 ! 6: {\colortbl;\red0\green0\blue0;} ! 7: \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f0\b\i0\ulnone\fs36\fc0\cf0 MasteringDetails ! 8: \b0\fs24 \ ! 9: by Craig Federighi, EO Development Team\ ! 10: \ ! 11: ! 12: \b\fs28 Overview ! 13: \b0\fs24 \ ! 14: \ ! 15: This example presents a generic scheme for assigning relationship keys automatically for insertions and deletions in detail controllers. The implementation of this is fairly complex, but the result is a significant simplification in the code required to implement applications that allow editing master-detail relationships.\ ! 16: \ ! 17: ! 18: \b\fs28 \ ! 19: Demo Application Features\ ! 20: ! 21: \b0\fs24 \ ! 22: The application allows the user to enter and edit employee information. The employee data has several interesting relationships:\ ! 23: ! 24: \pard\tx980\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fi-220\li960\fc0\cf0 � A to-one foreign key to primary key relationship for employee to department.\ ! 25: � A many-to-many relationship between employee and project.\ ! 26: ! 27: \pard\tx980\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fi-220\li960\fc0\cf0 � Primary key to primary key relationship for Quote and Picture.\ ! 28: ! 29: \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0\cf0 The primary purpose of this example is to show how key assignment can be handled in a general way when records are inserted in detail controllers with these sort of relationships.\ ! 30: \ ! 31: ! 32: \b Additional Features: ! 33: \b0 \ ! 34: \ ! 35: ! 36: \pard\tx980\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fi-220\li960\fc0\cf0 � The Quote field demonstrates storing rich text in the database. \ ! 37: � An image well allows storage and retrieval of images.\ ! 38: � Departments and Projects are selected by selecting from a list of available choices presented in a scrolling list (pick list). This is done with a new association type.\ ! 39: � New objects are automatically assigned unique primary keys.\ ! 40: ! 41: \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\b\fs28\fc0\cf0 \ ! 42: The Example Folder\ ! 43: ! 44: \b0\fs24 \ ! 45: The example contains the following:\ ! 46: \ ! 47: ! 48: \pard\tx1920\tx2880\tx3320\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fi-3320\li3320\fc0\cf0 EOFExtensions.subproj - A application-independent relationship management facility.\ ! 49: KeyGenerator - Much like the UniqueKey example, this provides a facility for assigning unique primary keys to objects.\ ! 50: ValueForKey - A category on NSObject to provide single key versions of takeValuesFromDictionary and valuesForKeys.\ ! 51: RelationshipKeySetter - The brains of this example. Provides categories on EORelationship to perform key assignment on master or detail objects in order for the relationship between them to hold in the database.\ ! 52: SavvyControllerDel... - A generic EOController delegate that uses the RelationshipKeySetter to assign keys correctly when objects are inserted or deleted in detail controllers.\ ! 53: SelectionInsertionAs... - An EOAssociation subclass that inserts and deletes objects in its controller based on the selection in its destination controller.\ ! 54: ! 55: \pard\tx1920\tx2880\tx3320\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fi-3320\li3320\fc0\cf0 ResetRelationships - Not actually used in this example. Provides a category on EODatabaseChannel for updating the relationship pointers of an EO when its foreign key values have been modified. This plays the opposite role to the RelationshipKeySetter.\ ! 56: ! 57: \pard\tx1920\tx2880\tx3320\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fi-3320\li3320\fc0\cf0 EmpController - The main controller in this application. Sets up associations, performs initial fetches, and provides an insert operation to add new employees. As a subclass of the generic SavvyControllerDelegate it acts as a delegate for detail controllers, performing key assignments for the insertion and deletion of objects.\ ! 58: Employee - An example EO class.\ ! 59: ! 60: \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0\cf0 \ ! 61: \ ! 62: ! 63: \b\fs28\fc1\cf1 Running the Example ! 64: \b0\fs24\fc0\cf0 \ ! 65: \ ! 66: Select an employee from the table view; notice that the department and project lists at the bottom of the window select the department and projects for the selected employee. You can edit the employee in several ways:\ ! 67: ! 68: \pard\tx980\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fi-220\li960\fc0\cf0 � Re-assign an employee to a different department by clicking on the new department in the departments list. \ ! 69: � Assign the employee to additional projects by shift clicking on a new project in the projects list. \ ! 70: � Add a picture for the employee by dragging an image into the image well.\ ! 71: � Type a new "quote" for the employee by typing in the Quote text view. This is an RTFD field, so you can use rich text and even add images or files.\ ! 72: ! 73: \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0\cf0 Save your changes by either clicking the save button or selecting a different employee.\ ! 74: \ ! 75: Add a new employee by clicking the Add button. Enter the new data for this employee and select save to commit the new entry to the database.\ ! 76: ! 77: \b \ ! 78: \ ! 79: ! 80: \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fs28\fc1\cf1 Building For Sybase v.s. Oracle\ ! 81: ! 82: \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\b0\fs24\fc0\cf0 This example uses the "People" database. Scripts to create this database on your server can be found in ! 83: \b /NextDeveloper/Examples/EnterpriseObjects/PeopleDBScripts. ! 84: \b0 This example includes model files for both Sybase and Oracle. To use Oracle, do the following in a shell:\ ! 85: ! 86: \f1\fs20 cp people_Oracle.eomodel people_photo_quote.eomodel\ ! 87: ! 88: \f0\fs24 and then make the project. \ ! 89: ! 90: \b \ ! 91: ! 92: \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0\cf0 \ ! 93: ! 94: \fs28\fc1\cf1 Known Limitations\ ! 95: ! 96: \b0\fs24\fc0\cf0 \ ! 97: The SavvyDelegate performs non-optimal database updates, sometimes updating an object twice or inserting an object and immediately updating it as part of a single save operation. ! 98: \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0\cf0 \ ! 99: \ ! 100: ! 101: \b\fs28\fc1\cf1 \ ! 102: Possible Enhancements\ ! 103: ! 104: \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\b0\fs24\fc0\cf0 The SavvyDelegate does not handle propagating deletions from a master to its details. It would be nice if we could just delete an employee from the master and have other associated data dropped automatically. ! 105: \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\b\fs28\fc1\cf1 \ ! 106: ! 107: \pard\tx980\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\b0\fs24\fi-220\li960\fc0\cf0 \ ! 108: ! 109: \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc1\cf1 This app performs no validation on employee data. Combining the SavvyDelegate here and the ValidatingDelegate from the Validation example could improve that situation.\ ! 110: \ ! 111: \ ! 112: ! 113: \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\b\fs28\fc1\cf1 Philosophical Reflections\ ! 114: ! 115: \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\b0\fs24\fc1\cf1 \ ! 116: ! 117: \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc1\cf1 This example shows how to eliminate a lot of the drudgery associated with assigning keys in detail controllers. One might ask why the assignment is being performed at the controller level at all. For example, what if I create an employee object on a screen that does not display the department or employee picture (and therefore doesn't have detail controllers for these properties)? I'd still like the employee to automatically be assigned a default department and (possibly empty) picture and quote objects.\ ! 118: \ ! 119: A better (and less UI-centric) way to handle the task of relationship management is to perform the work of the Savvy(Controller)Delegate in a delegate of the EODatabaseChannel, and/or in the EO itself. This is left as an exercise for the reader!\ ! 120: ! 121: \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc1\cf1 \ ! 122: \ ! 123: ! 124: \b\fs28 Change History ! 125: \b0\fs24 \ ! 126: \ ! 127: 17/Feb/95 Created for EOF 1.1 release (Craig Federighi)\ ! 128: ! 129: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.