Re: EOF Design Questions
Ashley Aitken <[email protected]> Thu, 8 Apr 2004 23:02:37 +0800
| Newsgroups | gmane.comp.web.webobjects.eof |
|---|---|
| Message-ID | <[email protected]> |
Hi Francis,
Thanks for your posting.
On 08/04/2004, at 10:38 PM, Francis Labrie wrote:
> You can define an abstract superclass (i.e. ClonableGenericRecord) for
> all your cloneable entities extending EOGenericRecord Cloneable with a
> method that does something like this:
>
> public EOEnterpriseObject clone() {
> Enumeration keys;
> EOEnterpriseObject object;
> Object value;
> String key;
>
> object =
> EOClassDescription.classDescriptionForEntityName(entityName()).
> createInstanceWithEditingContext(editingContext(), null);
>
> keys = allPropertyKeys().objectEnumerator();
> while(keys.hasMoreElements()) {
> key = (String)keys.nextElement();
> object.takeValueForKey(valueForKey(key));
> } // while
>
> return(object);
> } // clone
That's a clear and straight-forward way of doing it.
I was hoping, however, that there maybe a more efficient way of doing
it (that may need to be provided by the frameworks using underlying
data structures).
> But this clone the targeted entity only, i.e. all relationships will
> be same for both the original and the cloned entity:
>
> EOA.toEOB -> clone -> EOA'.toEOB
>
> If you want to clone entities in relationships as well like this:
>
> EOA.toEOB -> clone -> EOA'.toEOB'
>
> Then you'll have to modify the clone() loop to build one for each
> attributeKeys(), toOneRelationshipKeys() and toManyRelationshipKeys()
> instead of using allPropertyKeys().
Yes, that will depend upon whether I need a shallow or deep clone.
>> 2. How best to revert some EOs (but not all) in the EC?
>> Using the original snapshot ... but could that change (is that a
>> problem)?
>
> You can use the editing context revert() method. Setting up the
> original snapshot shouldn't be a problem though.
Ok, but that will revert all objects in the editing context.
I want to revert only those objects that have been changed (and thus
cloned).
For example, I don't want to revert the cloned objects.
Cheers,
Ashley.
--
Ashley Aitken
Perth, Western Australia
mrhatken at mac dot com