Hi Patrick,Thanks for providing a solution you have it working. But having a 
new field for maintaining the order of records like "sortOrder" in the entity/ 
table has various other benefits as affirmed by Chuck, Mike, et al.,

Thank You,
Shravan Kumar. M
--------------------------------


Mon Nov  2 15:39:00 2009
From: 
"Patrick Middleton" <patr...@onestep.co.uk>
To: 
"Development WebObjects" <webobjects-dev@lists.apple.com>
On 1 Nov 2009, at 12:40, Shravan Kumar. M wrote:

>
Thanks Kieran for your solution. But unfortunately, we don't extend
ERXGenericRecord, so we cannot get benefits of this!!! I have actually
read about your this solution in a similar kind of issue posted and
responded by you here: 
http://www.mail-archive.com/webobjects-dev@lists.apple.com/msg25975.html
> 
> From: Kieran Kelleher <kieran_li...@mac.com>
> To: Shravan Kumar. M <mshravan_...@yahoo.com>
> Cc: Chuck Hill <ch...@global-village.net>; WO Dev Group 
> <webobjects-dev@lists.apple.com>
> Sent: Sun, November 1, 2009 5:55:25 PM
> Subject: Re: how to insert records in database in the order of insertion to EC
> 
> Or if you want the order of the PKs to be the same order as your insertion 
> into the EC, you can try calling
> 
>     eo.primaryKeyInTransaction    (or sth like that)
> 
> which is provided by ERXGenericRecord subclass.
> 
>
That method assigned the PK ....... do it in each iteration. Then the
items are saved the the PK order the same as insertion order.
> 
> Regards, Kieran

I'm
still working with WO451, so I'm not going to post my code.  I
encountered a problem very much like this one: primary keys were also
being used as audit sequence IDs, and this made ensuring that the order
of insertion into an editing context and ascending order of primary
keys be the same essential.

The fix I chose was broadly as
follows (and as far as I can tell should work in 5.x, and I'm looking
at the 5.3 Javadocs that I have to hand.)
I created an instance of a helper object class; one member variable is the 
editing context of interest.
The editing context at this point has no unsaved changes.
The helper implements EOObserving, and on cue -- startWatching() -- registers 
itself as an observer with an EOObserverCenter.
When
the helper receives objectWillChange(Object object), it tests object to
see if [1] its editing context is the helper's editing context [2] its
EOGlobalID returns true for isTemporary() and [3] whether the object is
already in an array/vector/whatever other ordered collection is being
maintained by the helper -- if not, it adds it.
At some point --
stopWatching() -- we then unregister the helper from the
EOObserverCenter, and ask the helper for its collection.

We can
then examine the collection to see what primary keys we need to
generate, generate them, and cache them somewhere -- I have a singleton
class to be the default delegate for all EODatabaseContexts which
implements databaseContextNewPrimaryKey(EODatabaseContext dbCtxt,
Object object, EOEntity entity).

When I call save() on the
editingContext, EOF will insert objects into the database as normal,
except the pre-created primary keys will be assigned to the intended
objects and in the correct order.

---
Regards Patrick
OneStep Solutions (Research) LLP
www.onestep.co.uk


      
 _______________________________________________
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 arch...@mail-archive.com

Reply via email to