File:  [NeXTSTEP 3.3 examples] / Examples / EnterpriseObjects / Validation / README.rtf
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 17:48:57 2018 UTC (8 years, 1 month ago) by root
Branches: NeXT, MAIN
CVS tags: NeXTSTEP33, HEAD
Sample Programs from NeXSTEP 3.3

{\rtf0\ansi{\fonttbl\f2\fswiss Helvetica;\f3\fmodern Ohlfs;}
\paperw9840
\paperh8400
\margl120
\margr120
{\colortbl;\red0\green0\blue0;}
\pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f2\b\i0\ulnone\fs36\fc0\cf0 Validation
\b0\fs24 \
by Craig Federighi, EO Development Team\
\

\b\fs28 Overview
\b0\fs24 \
\
This example presents a simple, generic scheme to allow validation constraints to be put where they belong: as methods in your enterprise objects.  The implementation consists of two parts.  First, the KeyValueValidation protocol passes dictionaries of proposed values to your object and allows it to return a dictionary of error messages.  The default implementation allows your object to implement methods like the following:\

\f3\fs20\fi-20\li720 - (NSString *)validateSalary:(NSNumber *)proposed\
\{\
    if ([proposed doubleValue] < 1000.0)\
        return @"Salaries must be greater than $1,000";\
\
    return  nil; // no error\
\}\

\f2\fs24 \

\fi0\li0 The second part of the implementation is a reusable controller delegate that will call the validation routines at the important points: when the user makes a change to a property, and before an object is inserted, updated, or deleted in the data source.\
\

\b\fs28 The Example Folder\

\b0\fs24 \
The example is composed of the following:\
\

\pard\tx1920\tx2880\tx3320\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fi-3320\li3320\fc0\cf0 Validation.subproj	- 	A application-independent validation scheme.\
    KeyValueValidation.h	-	A protocol for asking objects to validate properties.\
    ValidatingDelegate	-	An EOController delegate that calls the object to perform validation during willSaveEdits, willInsertObject:inDataSource, etc.\
    EOAcceptsNullFor...	-	An (unrelated) example of how objects can tell EOF to turn database NULLs into zeros (or any other values) when they are assigned to scalar numeric properties (int, double, etc).\
 AppController		- 	Subclass of ValidatingDelegate that adds a check box to turn on and off immediate validation on change.\
 Employee		- 	Example EO class that specifies validation constraints.\
 Department		- 	Another EO class that participates in validating an Employee (no employee can make more than ten times as much as others in the department).\
    	
\pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0\cf0 \

\b\fs28\fc1\cf1 Running the Example
\b0\fs24\fc0\cf0 \
\
Try making changes to the city, address, and salary fields in the application.  If "validate changes immediately" is checked certain constraints will be checked as soon as you try to leave a field.  All constraints are checked before saving to the data source.\
\

\b Validation Rules:
\b0 \
The employee class in this example encodes the following constraints:\

\pard\tx980\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fi-220\li960\fc0\cf0 �	Salaries must be greater than $1000\
�	A city must be entered (non-blank)\
�	Addresses may not be longer than 40 characters\
\

\pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0\cf0 Also, employees pass themselves on to their departments for department-specific validation.  This check is performed only when the object is about to be inserted of updated in the data source.  In this case department adds the constraint:\

\pard\tx980\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fi-220\li960\fc0\cf0 �	No employee may make more than ten times as much as anyone else in the department.\

\pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\b\fc0\cf0 \
\

\fs28\fc1\cf1 Known Limitations\

\b0\fs24\fc0\cf0 This validation support just offers an idea of a useful approach to performing validation under EOF; it is not a complete solution.  Current limitations include:\

\pard\tx980\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fi-220\li960\fc0\cf0 �	The default implementation of the KeyValueValidation protocol won't call methods that take C numeric arguments like 
\f3\fs20\fc1\cf1 setSalary:(double)salary
\f2\fs24\fc0\cf0 .\
�	When performing "immediate" upon the user hitting tab or return, the edit focus is not automatically restored to the field where the error occurred.\

\pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0\cf0 \
\

\b\fs28\fc1\cf1 Possible Enhancements\

\pard\tx980\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\b0\fs24\fi-220\li960\fc0\cf0 �	Some simple constraints might best be expressed in the EOModel file (perhaps as additions to the user dictionary) rather than in the EO class.  The ValidatingDelegate could be extended to check entries against constraints specified on their corresponding attributes in the model.\
�	The validation protocol does not provide a way for validators to automatically coerce or correct a proposed value; this might be useful in some circumstances.\
\

\pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\b\fs28\fc1\cf1 Tips for moving from a Sybase to an Oracle database\
\

\b0\fs24 This example works for Sybase currently. However, you can easily make it work for Oracle. When moving from a Sybase to an Oracle based example, you'll need to create a  new 
\b .eomodel
\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.\
\
For example:\
Prepare a People_Oracle.eomodel\

\pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc1\cf1 \

\b\fs28 Change History
\b0\fs24 \
\
16/Feb/95	Created for EOF 1.1 release (Craig Federighi)\

}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.