On Aug 4, 2008, at 9:23 AM, Gino Pacitti wrote:
Hi David
Could you perhaps send me a class that implements this... I am
currently trying to use the same code but trying to debug too... :-(
Hi Gino,
The solution has a few parts, all of which work together so you end up
with the least amount of code duplication.
1) Get the EOCopiable Interface and EOEntityCopier Class from the PWO
Utilities Source Code. I've simply added these classes to my project.
- com.apress.practicalwo.practicalutilities.EOCopiable
- com.apress.practicalwo.practicalutilities.EOEntityCopier
2) Create your own custom EOGenericRecord subclass that impliments
EOCopiable. All your entities will extend this class instead of
EOGenericRecord directly, doing this will give all your Entities the
ability to be copied (you still need to do step 3). You'll need to
tell the .eogen file what the name of your EOGenericRecord subclass
is. You do this by adding a new variable to the "Defines" section of
the EOGenerator Editor screen. Variable Name: "EOGenericRecord" Value:
"MyGenericRecord". I believe the default Velocity EOGenerator
templates will pick this up. If not, let me know and I can give you
instruction on how to add it to a custom template.
3) Add a duplicate() method to each Entity that you want to actually
have the ability to be copied. Here's an example:
@Override
public EOEnterpriseObject duplicate(NSMutableDictionary copiedObjects) {
// Handle circular relationships by registering this object right away
EOEnterpriseObject copy = EOCopyable.Utility.newInstance(this);
EOGlobalID globalID = editingContext().globalIDForObject(this);
copiedObjects.setObjectForKey(copy, globalID);
// Copy all attributes first
EOCopyable.Utility.copyAttributes(this, copy);
// Override copied attributes that need to have different values than
the original
copy.takeValueForKey(this.routingDescription() + "-CLONE",
ROUTING_DESCRIPTION_KEY);
copy.takeValueForKey(false, IS_DEFAULT_KEY);
// Copy the relationships that must be copied as well
// This will make copies of the destination objects to populate the
relationship
// so the destination Entities must also have duplicate() methods
defined.
EOEntity entity = ((EOEntityClassDescription)
classDescription()).entity();
EOCopyable.Utility.deepCopyRelationship(copiedObjects, this, copy,
entity.relationshipNamed(ROUTING_STEPS_KEY));
EOCopyable.Utility.deepCopyRelationship(copiedObjects, this, copy,
entity.relationshipNamed(TOOL_CONFIGURATIONS_KEY));
// Copy the relationships that must NOT be copied
// This will simply set the relationship to the existing destination
object
// instead of creating a new copy.
copy.addObjectToBothSidesOfRelationshipWithKey(this.routingType(),
ROUTING_TYPE_KEY);
copy.addObjectToBothSidesOfRelationshipWithKey(this.manufacturingLine(),
MANUFACTURING_LINE_KEY);
copy.addObjectToBothSidesOfRelationshipWithKey(this.workCenter(),
WORK_CENTER_KEY);
copy
.addObjectToBothSidesOfRelationshipWithKey
(BillOfMaterialType.fetchOneClone(editingContext()),
BILL_OF_MATERIAL_TYPE_KEY);
copy.addObjectToBothSidesOfRelationshipWithKey(this.part(), PART_KEY);
copy.addObjectToBothSidesOfRelationshipWithKey(this.unitOfMeasure(),
UNIT_OF_MEASURE_KEY);
return copy;
}
A key thing to remember, which _always_ bites me, is that if you add a
relationship to your Entity, you need to also add it to your
duplicate() method or it will not know what to do with it. (I've
thought about adding logic to my custom Veogenerator template to be
able to create the duplicate method on the fly based on User Info
parameters defined in the model, but I haven't gotten around to it
yet, but this doesn't really reduce the potential for errors, just
moves them to the EOModel.)
Good luck!
Dave
Gino
On 4 Aug 2008, at 14:22, David Avendasora wrote:
Gino,
I have implemented the solution outlined in Practical WO into my
project and I can say that it works phenomenally well. You have to
write a method for each Entity that describes _exactly_ what you
want to have happen when you ask for a copy, but once you do that
it really is as easy as calling that method and getting a copy back.
Dave
On Aug 3, 2008, at 7:50 PM, David LeBer wrote:
On 3-Aug-08, at 6:55 PM, Owen McKerrow wrote:
Hey,
Ondra's suggestion is the a good idea. Or you could have a look
at Chapter 9 of Chucks "Practical WebObjects" book, which is a
whole chapter on this very topic :)
And it requires an entire chapter because when you think about it,
it is NOT an insignificant thing to do:
- You may not want to clone all attributes for all entities
- You may not want to clone all relationships for all entities
- If cloning an object graph you may/will encounter circular
references that need to be dealt with.
Owen McKerrow
WebMaster, emlab
Ph : +61 02 4221 5517
http://emlab.uow.edu.au
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - -
'The test of a first-rate intelligence is the ability to hold two
opposed ideas in the mind at the same time and still be able to
function.'
-F.Scott Fitzgerald,
On 04/08/2008, at 5:52 AM, Gino Pacitti wrote:
Well what I mean is that instead of
neweo.setValue(existingeo.someValue());
for every value in the existingeo which I want to transpose to
the neweo.
Is there a operation like -
neweo = existineo.clone();
So all the values in the new eo are the same as existingeo but
obvioulsy with a new PK..
GIno
On 3 Aug 2008, at 20:41, Ondřej Čada wrote:
Gino,
On Aug 3, 2008, at 9:27 PM, Gino Pacitti wrote:
Has anyone had experience copying an EO values fetched and in
and EditingContext to a new EO in an atomic action?
"Atomic" in what sense?
Myself, I've always combined valuesForKeys and
takeValuesFromDictionary, but YMMV :)
;david
--
David LeBer
Codeferous Software
'co-def-er-ous' adj. Literally 'code-bearing'
site: http://codeferous.com
blog: http://davidleber.net
profile: http://www.linkedin.com/in/davidleber
twitter: http://twitter.com/rebeld
--
Toronto Area Cocoa / WebObjects developers group:
http://tacow.org
_______________________________________________
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/webobjects%40avendasora.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/ginokris%40mac.com
This email sent to [EMAIL PROTECTED]
-----------------------------------------------------
Gino L. Pacitti Base Enterprise UK
email: [EMAIL PROTECTED]
phone: sales: 0845 094 9784
mob: 07980 851 953
Aol: kris121
Msn: [EMAIL PROTECTED]
Skype: ginkris
Mac.com: [EMAIL PROTECTED]
http://www.base-enterprise.co.uk
mail: Base Enterprise
PO BOX 674
East Grinstead
West Sussex
RH19 3ZG
Base Enterprise LTD
Company Number 04339224
Registered in England & Wales
Registered Member of the UK Web Design Association.
Accredited by Business Link and a member of the FSB.
Web Design, coding and information architect
Web Objects and Database Developer
HTML, XML, Javascript and WAP technologies.
-----------------------------------------------------
This email and any attachments is confidential and may be legally
privileged and protected from disclosure. It is intended solely for
the use of the individual or entity to whom it is addressed and
others authorized to receive it.
If you are not the intended recipient of this e-mail of any parts of
it please telephone +44 845 094 9784 immediately upon receipt
or contact [EMAIL PROTECTED]
No other person is authorized to copy, forward or disclose,
distribute or retain this e-mail in any form.
_______________________________________________
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]