I'm trying to convert some objects that is stored in GOODS to their subclass, but I'm not sure why its not working. Could anyone have a look? File in the attached and run the code below. How should I do this instead? Thanks.
====== db := KKDatabase onHost: 'localhost' port: 6102. a := AA new. a list add: BB new. db root at: #xxx put: a. db commit.
x := (db root at:#xxx). "x list do: [:e | e primitiveChangeClassTo: BBSubclass new]." x list: (OrderedCollection with: (x list do: [:e | e primitiveChangeClassTo: BBSubclass new])). "x inspect" db commit.
db := KKDatabase onHost: 'localhost' port: 6102. (db root at:#xxx) inspect ======
On Sun, 28 Nov 2004 18:35:49 +0800, Yar Hwee Boon hboon@motionobj.com wrote:
I'm trying to convert some objects that is stored in GOODS to their subclass, but I'm not sure why its not working. Could anyone have a look? File in the attached and run the code below. How should I do this instead? Thanks.
Read the comment on #primitiveChangeClassTo:. In particular, "Note: The primitive will fail in most cases that you think might work. ".
If you really need to do this, #become: will work better (ie, something like "a become: (BB basicNew copyFrom: a)"), though it's slow if you use it on individual objects rather than with a bulk #elementsExchangeIdentityWith:.
Avi
On Sun, 28 Nov 2004 11:40:36 +0100, Avi Bryant avi.bryant@gmail.com wrote:
If you really need to do this, #become: will work better (ie, something like "a become: (BB basicNew copyFrom: a)")
Sorry, I should have been more careful about my example: to better match your post, this should be "e become: (BBSubclass basicNew copyFrom: e)".
Avi
On Sun, 28 Nov 2004 11:42:42 +0100, Avi Bryant avi.bryant@gmail.com wrote:
match your post, this should be "e become: (BBSubclass basicNew copyFrom: e)".
I'm getting the same result. I think this still face the same issue. What I'm doing is:
====== x := (db root at:#xxx). x list do: [:e | e become: (BBSubclass basicNew copyFrom: e)]. "x inspect" db commit. ======
Seems that the list/element is not marked as dirty.
On Sun, 28 Nov 2004 19:03:02 +0800, Yar Hwee Boon hboon@motionobj.com wrote:
====== x := (db root at:#xxx). x list do: [:e | e become: (BBSubclass basicNew copyFrom: e)]. "x inspect" db commit. ======
OK. Just for the record, if anyone ever needs to do this, this works. Thanks Avi.
===== x list do: [:e | e primitiveChangeClassTo: BBSubclass new. x writeBarrier add: e yourself; modified: e yourself]. =====i
On Sun, 28 Nov 2004 11:40:36 +0100, Avi Bryant avi.bryant@gmail.com wrote:
On Sun, 28 Nov 2004 18:35:49 +0800, Yar Hwee Boon hboon@motionobj.com wrote:
Read the comment on #primitiveChangeClassTo:. In particular, "Note: The primitive will fail in most cases that you think might work. ".
I did. The primitive did not fail actually. In the middle of the workspace code I pasted, if you uncomment the #inspect call. You will find that the list element is properly converted. But the #inspect at the last line after committing shows that the list has not been updated in the database. I was guessing that I might be the GOODS client code?
If you really need to do this, #become: will work better (ie, something like "a become: (BB basicNew copyFrom: a)"), though it's slow if you use it on individual objects rather than with a bulk #elementsExchangeIdentityWith:.
I'll try this, thanks.
squeak-dev@lists.squeakfoundation.org