Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Semi-unique column



Refactor your table and move the unique stuff to an extra table and enforce the DB-level uniqueness there?

Am 28.11.2005 um 11:09 schrieb Ondra Cada:

Hello,

My current customer needs a column which is semi-unique, i.e., some of its values (programmatically determined which ones, in this case those which happen to contain a decimal digit) need to be unique, whilst others need not.

Of course, I can easily write a Java code to handle this kind of "uniqueness", something conceptually like

void testAndSave() {
String uval=changedObject.uniqueValue();
if (shouldBeUniqueValue(uval)) {
NSArray a=EOUtilities.objectMatchingKeyAndValue (changedObject.editingContext(),"uniqueValue",uval);
if (a.count()>0) throw new Exception("Not unique "+uval);
}
changedObject.editingContext().saveChanges();
}


I don't quite like this code though, for there still is a slight possibility for two concurrent clients' operations may be ordered so that both tests are all right, and then non-unique values are saved. Since only some values are to be uniqued, I cannot use a database unique constraint to prevent that (incidentally, am using FrontBase -- not that it is important in this case).

What would be the best solution? Is there a standard way to make such a test and save an atomical operation? I could lock or create an explicit transaction I guess, but at the first look it seems to be a bit overkill for such a plain task?

Thanks for any idea,
---
Ondra Čada
OCSoftware:     email@hidden               http://www.ocs.cz
private         email@hidden             http://www.ocs.cz/oc


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/krank% 40logicunited.com


This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/webobjects-dev/email@hidden

This email sent to email@hidden
References: 
 >Semi-unique column (From: Ondra Cada <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.