• 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: [SOLVED] how to insert records in database in the order of insertion to EC
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [SOLVED] how to insert records in database in the order of insertion to EC


  • Subject: Re: [SOLVED] how to insert records in database in the order of insertion to EC
  • From: Patrick Middleton <email@hidden>
  • Date: Mon, 2 Nov 2009 10:09:00 +0000


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/ email@hidden/msg25975.html

From: Kieran Kelleher <email@hidden>
To: Shravan Kumar. M <email@hidden>
Cc: Chuck Hill <email@hidden>; WO Dev Group <webobjects- email@hidden>
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 (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Re: how to insert records in database in the order of insertion to EC (From: Kieran Kelleher <email@hidden>)
 >Re: [SOLVED] how to insert records in database in the order of insertion to EC (From: "Shravan Kumar. M" <email@hidden>)

  • Prev by Date: Re: Customising D2W - adding filtering to list pages
  • Next by Date: Fwd: AjaxUpdateLink - how to change it's name
  • Previous by thread: Re: [SOLVED] how to insert records in database in the order of insertion to EC
  • Next by thread: Re: migrated to 3.5 with ant build problem
  • Index(es):
    • Date
    • Thread