• 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: efficient copy?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: efficient copy?


  • Subject: Re: efficient copy?
  • From: Chuck Hill <email@hidden>
  • Date: Mon, 02 Mar 2015 17:49:40 +0000
  • Thread-topic: efficient copy?

Hi,

On 2015-03-01, 7:51 AM, "OC" wrote:

Hello there,

I'll need to copy thousands of objects from one table to another; the copying'll be almost verbatim, but for a relationship. Namely,

entity OldAuction <->> OldRecord (relationships records->> and inverse <-auction)
entity NewAuction <->> NewRecord (relationships records->> and inverse <-newAuction)

Entity NewRecord has all attributes of OldRecord (and perhaps a couple of others)

The naïve code would be something like

===
def orig=... an object of the OldAuction entity ...
def new=... an object of the NewAuction entity ...
orig.allRecords().each { OldRecord old ->
  def newRecord=EOUtilities.createAndInsertInstance(new.editingContext(),'NewRecord')
  newRecord.newAuction=new
  newRecord.takeValuesFromDictionary(old.valuesForKeys(old.attributeKeys()))
}
new.editingContext().saveChanges()
===

I’d do this in batches, say 200 – 1000 auctions and then save, dispose the EC, create a new one and loop.  That avoid any possible problems with too much retained memory.


There's no need to make this lightning fast, e.g., a dedicated SQL procedure would definitely be an overkill; but still, it should be as fast as possible without making the code too complex, unintelligible and unmaintainable. I wonder, what's the best way? Guess I might e.g., fetch rawrows for orig.allRecords somehow, and use _them_ for the takeValuesFromDictionary argument?

As long as you just want data values and not EOs for a relationship.

Chuck

 _______________________________________________
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: 
 >efficient copy? (From: OC <email@hidden>)

  • Prev by Date: Re: global EO representant / locking on EO?
  • Next by Date: Re: global EO representant / locking on EO?
  • Previous by thread: Re: efficient copy?
  • Next by thread: clone eoentity/eoattribute/eorelationship
  • Index(es):
    • Date
    • Thread