aka
destination.takeValuesFromDictionary(source.valuesForKeys(source.attributeKeys()));
ms
On Mar 21, 2011, at 5:14 PM, John Huss wrote:
> You could do this instead:
>
> /**
> * Copies attribute values FROM source TO destination
> * @param source
> * @param destination
> */
> private void copyAttributes(EOGenericRecord source, EOGenericRecord
> destination) {
> for (String key : source.attributeKeys()) {
> Object sourceAttributeValue = source.valueForKey(key);
> destination.takeValueForKey(sourceAttributeValue, key);
> }
> }
>
> On Mon, Mar 21, 2011 at 3:48 PM, Theodore Petrosky <[email protected]> wrote:
>
>
> --- On Mon, 3/21/11, David Avendasora <[email protected]> wrote:
>
> > From: David Avendasora <[email protected]>
> > Subject: Re: duplicating an EO
> > To: "Theodore Petrosky" <[email protected]>
> > Cc: "David LeBer" <[email protected]>,
> > [email protected]
> > Date: Monday, March 21, 2011, 6:26 AM
> > Hi Ted,
> >
> > The link for PWO at Apress' site is:
> > http://apress.com/book/view/9781590592960
> >
> > You can buy an eBook version of it there, which is spendy,
> > but worth it to always have it at your fingertips. Chuck
> > really wouldn't mind you buying it _3_ times... :-)
> >
> > There is also a link on that page to download the
> > sourcecode related to the book. In there, in one of the
> > chapters (I can't remember which one right now as I haven't
> > bought the eBook =:-0 ) you'll find the source code
> > for what you'd need in an EOCopyable interface and what
> > methods you should add to your custom sublcass of
> > EOGenericRecord.
> >
> > You do have a custom subclass of EOGenericRecord, right?!
>
> I am using Wonder and all my EOs extend ERXGenericRecord.
>
> So after reading the section in the PW book, I decided to get the job done by
> creating a new EO and copying the attributes. it works well. maybe not as
> beautifully as what is described in the book but it works.
>
>
>
> if (insertionQuant() > 1) {
>
> //NSLog.out.appendln("insertionQuant() > 1 ");
> int i;
> for (i = 0; i < insertionQuant() - 1; i++) {
>
> Grid copiedGrid = Grid.createGrid(theDupEC);
>
> copiedGrid.setBilling(newGridItem().billing());
> copiedGrid.setCenter(newGridItem().center());
> copiedGrid.setComments(newGridItem().comments());
> copiedGrid.setDueDateType(newGridItem().dueDateType());
> copiedGrid.setHeadLine(newGridItem().headLine());
> copiedGrid.setImage(newGridItem().image());
> copiedGrid.setInternalRelease(newGridItem().internalRelease());
> copiedGrid.setInvoice(newGridItem().invoice());
> copiedGrid.setIsADupe(true);
>
> try {
> theDupEC.saveChanges();
> } catch (Exception e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
>
> theDupEC.reset();
> }
> }
>
> >
> > Good luck. The book is key to understanding what the source
> > code is doing. Implementing Chuck's EOCopyable functionality
> > will probably take you marginally longer than just manually
> > doing the duplicating _this time_ but once you set it up,
> > it's available on all EOs and it is _very_ cool.
> >
> > I'm amazed that this hasn't made its way into WOnder yet...
> > well maybe people still need a reason to buy Chuck's book. I
> > mean, with all the other really excellent WO books out
> > there...
> >
> > Oh wait...
> >
> > Dave
> >
> > On Mar 20, 2011, at 6:24 PM, Theodore Petrosky wrote:
> >
> > > I have two copies of that book. I thought one at home
> > and one in the office. I guess I have to wait till tomorrow
> > at the office to read up.
> > >
> > > thanks
> > >
> > > Ted
> > >
> > > --- On Sun, 3/20/11, David LeBer <[email protected]>
> > wrote:
> > >
> > >> From: David LeBer <[email protected]>
> > >> Subject: Re: duplicating an EO
> > >> To: "Theodore Petrosky" <[email protected]>
> > >> Cc: [email protected]
> > >> Date: Sunday, March 20, 2011, 5:39 PM
> > >>
> > >> On 2011-03-20, at 4:59 PM, Theodore Petrosky
> > wrote:
> > >>
> > >>> I have a rather simple object. it has about
> > 15
> > >> attributes. My users have informed me that they
> > need a way
> > >> to insert 25 duplicates of this object. Obviously
> > they go in
> > >> and change the due date (or some other attribute)
> > of the
> > >> duplicates. this is the only change.
> > >>>
> > >>> so i gave them a simple popup with the numbers
> > 1 to 25
> > >> and they can choose how many of these things they
> > want.
> > >>>
> > >>> what would be the easiest and bestest way to
> > dup these
> > >> objects. I started thinking to create a loop that
> > iterates
> > >> the number of times that they want and insert a
> > new EO into
> > >> the EC and copy the attributes from my master
> > object.
> > >>>
> > >>> But maybe there is an easier way?
> > >>>
> > >>> I hope I am explaining it simply enough
> > >>
> > >>
> > >> Practical WebObjects has a great chapter on EO
> > copying.
> > >>
> > >> Unfortunately it is a subject that can eat an
> > entire
> > >> chapter. Duplicating only the attributes is easy,
> > you can
> > >> just ask the existing EO for it's entity, ask the
> > entity for
> > >> it's attributes, and then iterate through them
> > calling
> > >> setValueForKey on the new EO with valueForKey on
> > the
> > >> existing one. However when you get into
> > relationships things
> > >> become much more difficult to handle in a generic
> > way (i.e:
> > >> do you want to copy the destination EOs or just
> > the
> > >> relationships, do you want to copy the
> > relationships of the
> > >> destination EOs, etc).
> > >>
> > >> Anyway, the chapter in Chuck's book is well worth
> > the
> > >> read.
> > >>
> > >> ;david
> > >>
> > >> --
>
>
>
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list ([email protected])
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/webobjects-dev/johnthuss%40gmail.com
>
> This email sent to [email protected]
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list ([email protected])
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/webobjects-dev/mschrag%40pobox.com
>
> This email sent to [email protected]
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com
This email sent to [email protected]