Re: Simple insert?
Re: Simple insert?
- Subject: Re: Simple insert?
- From: Chris Hanson <email@hidden>
- Date: Sat, 31 May 2003 22:10:23 -0400
On Thursday, May 29, 2003, at 05:42 PM, Goodbye Bill wrote:
One page should simply
check for the existence of the requested username and create the
necessary
entry in the table.
One suggestion: When working with WebObjects, move away from thinking
about tables and pages and towards thinking of objects and actions.
What you're talking about is adding the ability to create a new user
for your system. Typically, you'd just write:
if (!userExists(enteredUserName) && passwordValid()) {
EOEnterpriseObject user =
EOUtilities.createAndInsertObject("User", ec);
user.takeValueForKey(enteredUserName, "userName");
user.takeValueForKey(enteredPassword, "password");
ec.saveChanges();
}
where userExists is implemented along these lines:
boolean userExists(String userName) {
boolean exists = false;
try {
EOEnterpriseObject user
= EOUtilities.objectMatchingKeyAndValue(ec, "User",
"userName",
userName);
exists = true;
}
catch (Exception exception) {
exists = false;
}
return exists;
}
Another page should take the standard username and
password combination and be able to authenticate against that table.
Stated in terms of user actions rather than one possible
implementation, you want users to be able to log in to your
application. See userExists() above for an example of how you might do
this.
EOF lets you stop thinking in terms of tables, primary and foreign
keys, and so on most of the time. Instead you can think in terms of
objects, their behaviors, and user actions relating to them.
-- Chris
--
Chris Hanson, bDistributed.com, Inc. | Email: email@hidden
Custom Application Development | Phone: +1-847-372-3955
http://bdistributed.com/ | Fax: +1-847-589-3738
http://bdistributed.com/Articles/ | Personal Email: email@hidden
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.