Absolutely I am. That's the only thing that knows for sure.
public setUsername(username) {
if (username.length() < 5)
throw new ValidationException(...);
if (username.length() > 15)
throw new ValidationException(...);
if (REfind("[^a-zA-Z0-9]", username) > 0)
throw new ValidationException(...);
try {
var id = userHome.getUserIDFromUsername(username);
// if an id exists, we need to check and see if it matches this object's
// id, for when we're calling an update operation. the column is unsigned
// so only positive values are allowed. getId() returns -1 for unpersisted
// objects.
if (id != getId())
throw new ValidationException(...);
} catch (InvalidUsernameException iue) {
// good, it's unique.
}
}
the getUserIdFromUsername method in the userHome object looks like this:
public getUserIdFromUsername(username)
throws InvalidUsernameException
{
var get = "";
<cfquery ... name="get">
SELECT id
FROM user
WHERE username = <cfqp value="#username#" ... />
</cfquery>
if (get.recordCount == 0)
return get.id;
}
On Wed, 3 Nov 2004 11:24:46 -0800, Phil Cruz <[EMAIL PROTECTED]> wrote:
> On Wed, 3 Nov 2004 10:55:52 -0800, Barney Boisvert <[EMAIL PROTECTED]> wrote:
>
>
> > > Can you elaborate on how you do unique username type of validation if
> > > you don't let the db throw the unique key error? Seems like you might
> > > have to implement some locking scheme?
> >
> > Transactions. Since the entire operation (BO validation and
> > persistance) happens as a single call to the business layer, it's all
> > in a single transaction. Another reason for not putting this stuff in
> > the input validation - that forces you to have per-request
> > transactions, which generally isn't what you want.
> >
> > some psuedo code for the method in the service object:
> >
> > function addUser(username, password)
> > throws ValidationException
> > {
> > start transaction;
> > var bo = userFactor.getNewUser();
> > bo.setUsername(username); // throws ValidationException if invalid
> > bo.setPassword(password); // throws ValidationException if invalid
> > persist(bo);
> > commit transaction;
> > }
> >
>
> Can you provide psuedo code for setUsername()? I'm not clear on how
> you are checking for uniqueness. You aren't hitting the db to check
> for an existing username or are you?
>
>
>
> -Phil
> ----------------------------------------------------------
> You are subscribed to cfcdev. To unsubscribe, send an email
> to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev'
> in the message of the email.
>
> CFCDev is run by CFCZone (www.cfczone.org) and supported
> by Mindtool, Corporation (www.mindtool.com).
>
> An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]
>
--
Barney Boisvert
[EMAIL PROTECTED]
360.319.6145
http://www.barneyb.com/blog/
I currently have 0 GMail invites for the taking
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev'
in the message of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).
An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]