SandstoneDb + SortedCollections

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

SandstoneDb + SortedCollections

David Zmick
I am trying to use SandstoneDb to save an Object that contains a SortedCollection, but it fails with the error: "This message is not appropriate for this object".

Here is an example code.

SDActiveRecord subclass: #User
instanceVariableNames: 'sorted name'
classVariableNames: ''
poolDictionaries: ''
category: 'Sandbox'

User>>initialize
super initialize.
sorted := SortedCollection new.
name := 'asd'

and of course accessors for both of my variables.

I type this into a workspace:

(User new name: 'david') save.
User find: [:u | u name = 'david']

And it  works correctly, but this errors with: "This message is not appropriate for this object"

| u |
u := User new.
u name: 'david'.
u sorted add: 1.
u save

What can I do to fix this?


David Zmick
/dz0004455\
Reply | Threaded
Open this post in threaded view
|

Re: SandstoneDb + SortedCollections

Ramon Leon-5
On 12/21/2010 08:51 PM, David Zmick wrote:
> I am trying to use SandstoneDb to save an Object that contains a
> SortedCollection, but it fails with the error: "This message is not
> appropriate for this object".

Sorted collections contain sort blocks, which aren't serializable with
SmartRefStreams, which SandstoneDb is based on.

> What can I do to fix this?

You can't.  What you can do is store an OrderedCollection and sort them
on the fly in your accessor method.

--
Ramon Leon
http://onsmalltalk.com

Reply | Threaded
Open this post in threaded view
|

Re: SandstoneDb + SortedCollections

Ramon Leon-5
In reply to this post by David Zmick
On 12/21/2010 08:51 PM, David Zmick wrote:
> What can I do to fix this?

Another option might be to use a sort block that isn't a block, but an
ordinary object that responds as a sort block would, allowing the
collection to be serialized successfully.

--
Ramon Leon
http://onsmalltalk.com

Reply | Threaded
Open this post in threaded view
|

Re: SandstoneDb + SortedCollections

Eliot Miranda-2


On Tue, Dec 21, 2010 at 10:31 PM, Ramon Leon <[hidden email]> wrote:
On 12/21/2010 08:51 PM, David Zmick wrote:
What can I do to fix this?

Another option might be to use a sort block that isn't a block, but an ordinary object that responds as a sort block would, allowing the collection to be serialized successfully.

Another option would be to fix the limitation.  There's nothing conceptually preventing serializing a block.  It's just an object after all.  You have some choices
- how do you serialize the home context (you need to serialize every context along the static chain out to the home context)?  It should be serialized with a nil sender.

- bringing the block back in do you try and hook up the method to the corresponding method in image or leave it anonymous; leave it anonymous.

Eliot



--
Ramon Leon
http://onsmalltalk.com


Reply | Threaded
Open this post in threaded view
|

Re: SandstoneDb + SortedCollections

David Zmick
Alright, thank you! I will just sort in my accessor, that seems to be working pretty well. Thank you for your responses!

David Zmick
/dz0004455\


On Wed, Dec 22, 2010 at 11:20 AM, Eliot Miranda <[hidden email]> wrote:


On Tue, Dec 21, 2010 at 10:31 PM, Ramon Leon <[hidden email]> wrote:
On 12/21/2010 08:51 PM, David Zmick wrote:
What can I do to fix this?

Another option might be to use a sort block that isn't a block, but an ordinary object that responds as a sort block would, allowing the collection to be serialized successfully.

Another option would be to fix the limitation.  There's nothing conceptually preventing serializing a block.  It's just an object after all.  You have some choices
- how do you serialize the home context (you need to serialize every context along the static chain out to the home context)?  It should be serialized with a nil sender.

- bringing the block back in do you try and hook up the method to the corresponding method in image or leave it anonymous; leave it anonymous.

Eliot



--
Ramon Leon
http://onsmalltalk.com