On Aug 15, 2008, at 12:08 PM, Florijan Stamenkovic wrote:


On Aug 15, 2008, at 14:59, Chuck Hill wrote:


On Aug 15, 2008, at 11:45 AM, Florijan Stamenkovic wrote:

With any such value there is some probability the client will (next week or next year) want (a) to edit it, (b) in some special case, to have non-unique values.

Aaaaaah, I love being an in-house developer that can just stamp his foot and say no, without having to think about such a thing as: clients :)

That -- same as an extra UNIQUE column -- would not satisfy the demand that "all numbered orders make a sequence 1,2,3,4,....". The client would prefer that the sequence is without gaps (not something like "1,5,6,27,....").

I start to see your point. It makes it very tedious to deal with however. I've been in this situation. The decision (based on my selfless recommendations :) was not to care that 1,2,3,7,10... is ugly. They are unique. They identify things persistently. Sold.

As for Chuck's solution, also notice that it does not help you deal with the potential demand for edibility. And since it doesn't, you might as well use PKs (or a separate db generated sequence) in a two table setup in which you would still get the sparse but linear sequence like in Chuck's solution, but with far less fuss.

I think my solution would avoid gaps. The Order and OrderNumber are updated in the same transaction so there should be no rolling back of the number after another order has used a higher one.

Was not thinking that it would not. Uhm frankly was not exactly sure if and how it would work :) I'm just saying that you can get the same thing, if I understand correctly what the end result of your code would be, but in an easier way by doing this in the Order:

public void assignNumber(){
addToBothSides(EOUtilities.createAndInsert(editingContext(), "OrderNumber"), "orderNumber");
}

public Number number(){
        OrderNumber on = orderNumber();
        if(on == null) return null;

return (Integer) ((EOKeyGlobalID)editingContext().globalIDForObject(on)).keyValues() [0];
}

And you're done. Not every Order has to have a number, but when they do, they are in sequence.

Writing this in Mail, so it might not be entirely correct.


editingContext().globalIDForObject(on) will be an EOTemporaryGlobalID until the object is saved. You can use Wonder to get a permanent key, but if the transaction is not committed, you will get gaps in the sequence (I think).

The "no gaps" part is what makes this tricky!

Chuck


--
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      (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to