• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Check / Force field uniqueness in EOF
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Check / Force field uniqueness in EOF


  • Subject: Re: Check / Force field uniqueness in EOF
  • From: Chuck Hill <email@hidden>
  • Date: Wed, 25 Mar 2009 13:02:51 -0700


On Mar 25, 2009, at 12:59 PM, Simon McLean wrote:

might be worth checking this out - from the wonder blog :-)

ERXEOControlUtilities. validateUniquenessOf provides a utility method
for validating unique EO attribute values.


	/**
	 *ValidateswhetherthevaluesofthespecifiedkeyPathsareuniqueforan
	 *Entity.Throwsa{@link ERXValidationException}ifthereisalreadyanEO
	 *withthesamevaluesonthegivenkeypaths.
	 *
	 *Shouldbecombinedwithaconstraintonthecorrespondingdatabase
	 *columns.<br />



2009/3/25 Dan Grec <email@hidden>:
Full of questions today....
I have an EO that has a field "RemoteSystemID" that must be unique in the
DB.
I have the constraint in the DB and that works well.
What I would like, is a way in EOF to detect non-uniqueness without going to
the db and relying on the SQL Exception.
Currently, I have something like this:
@Override
public void validateForSave() throws NSValidation.ValidationException {
validateRemoteSystemId();
super.validateForSave();
}
//check that no Categories have this same remoteSystemID
public void validateRemoteSystemId() {
NSArray<Category> categories =
SCEOFetcher.objectsMatchingKeyAndValue(editingContext(), Category.class,
_Category.REMOTE_SYSTEM_ID_KEY, remoteSystemId(), EOFetcher.DBEC);
if (categories.count() > 1)
throw new NSValidation.ValidationException("Category Remote System
Id must be unique.", this, REMOTE_SYSTEM_ID_KEY);
}
This works really well if there is already one in the DB with a value of say
"123" and I try to add with with a value of "123".
This does not work if I try to add two at the same time with a value of
"567", it allows them both through.
Does anyone have a strategy to catch uniqueness at the EOF level?
Or, is it fine to just rely on the DB throwing an SQLException and catch
that after ec().saveChanges() ?
(I feel like letting that happen is bad, and might leave EOF in an un-happy
state - is there any chance of that?)
Thanks again,
-Dan Grec
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden



-- Chuck Hill Senior Consultant / VP Development

Practical WebObjects - for developers who want to increase their overall knowledge of WebObjects or who are trying to solve specific problems.
http://www.global-village.net/products/practical_webobjects







_______________________________________________ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Check / Force field uniqueness in EOF (From: Dan Grec <email@hidden>)
 >Re: Check / Force field uniqueness in EOF (From: Simon McLean <email@hidden>)

  • Prev by Date: Re: Check / Force field uniqueness in EOF
  • Next by Date: Re: JavaClient Common classes
  • Previous by thread: Re: Check / Force field uniqueness in EOF
  • Next by thread: Java Client (topic of the day!)
  • Index(es):
    • Date
    • Thread