I regret to say I have a very strong feeling against using PK's for anything but PK and relationships, ever.

May I ask why? I've found them quite useful when it comes to having immutable row / EO identifiers, have not bumped into problems with this yet. Except that for some reason in FrontBase they start with something like 100001, which I have yet to deal with. But, that's a point of aesthetics.

so I am guessing that is not what you need. So, could you elaborate on this a bit?

Anyway, even if I wanted to use them, it would not do, for there are items which have no numbers... Ha, thanks! Seems you just have led me to one reason I haven't realised originally why UNIQUE would not work quite well :) (Unless put into a table of its own, dedicated for this task, which I at the moment have alas completely no idea whether it's worth that or not... I think rather not?)

This can be worked around, with a boolean control property, let's call it hasOrderNumber:

public Number orderNumber(){
        if(hasOrderNumber)
                return sequenceNumber();
        else
                return null;
}

Without knowing why you do not want to use PKs for this, I'd use PKs in combination with this. But you can use any other sequence as well. As for the generation of the sequence itself, please see below.

What kind of a sequence is it? Do the users need to provide values, or can they be auto generated? In short, what are you trying to do?

There's an entity, say, Order, one of whose attributes is an integer orderNumber.

Some of created orders have no number (test ones, etc.). Those which have a number need to be numbered in a global sequence. In pseudo-code, I need a method

class Order:EOGenericRecord { ... ... ...

void assignOrderNumber() {
  // precondition: orderNumber()==null
  ...
  ...
// postcondition: orderNumber() is unique, so that all numbered orders make a sequence 1,2,3,4,....
}

so that this method works properly from any number of application instances.

From what I know of this problem, it is virtually impossible to ensure uniqueness of data in a WO setup in your Java code. For a recent discussion on this, in which I was trying something similar, check out the "DB uniqueness constraints and dealing with them" (July this year). So, after some valuable advice, I decided not to try to address this in Java. I guess that in your situation a combination between a database generated sequence and a uniqueness restraint would do what you need. Some database I believe can generate this for you. In others you might need to use a stored procedure to do it.

F
_______________________________________________
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