I enter the following code in a Workspace: (the class 'User' is just a very simple class with instance variable 'username' and corresponding accessors)
MagmaRepositoryController create: '/testDB' root: Dictionary new.
initialSession := MagmaSession openLocal: '/testDB'. initialSession connectAs: 'admin'. initialSession commit: [ initialSession root at: 'users' put: MagmaPreallocatedDictionary new ]. initialSession disconnect; closeRepository.
newUser := User new username: 'Charlie'; yourself. newSession := MagmaSession openLocal: '/testDB'. newSession connectAs: 'charlie'. newSession commit: [ (newSession root at: 'users') at: newUser put: OrderedCollection new ]. newSession disconnect; closeRepository.
testSession := MagmaSession openLocal: '/testDB'. testSession connectAs: 'aUser'. (testSession root at: 'users') size (testSession root at: 'users') at: newUser
The last two lines indicate the problem: the size of the MagmaPreallocatedDictionary is reported correctly (even when I add more users), but when I try to access any of the entries with the 'User' objects as keys, I get a 'errorKeyNotFound:' error.
Am I doing something wrong...?
Amir
Hi Amir, did you define #= method on User ?
I guest that It'll look like this:
User >> = otherUser "Answer whether the receiver is equal to the argument." self class = otherUser class ifFalse: [^false]. ^self name = otherUser name
You need implement the #hash method too:
User >> hash "Answer a SmallInteger whose value is related to the receiver's identity." ^self name hash
Hope this help.
Facu
On Thu, Dec 30, 2010 at 10:24 AM, Amir Ansari fractallyte@csi.com wrote:
I enter the following code in a Workspace: (the class 'User' is just a very simple class with instance variable 'username' and corresponding accessors)
MagmaRepositoryController create: '/testDB' root: Dictionary new.
initialSession := MagmaSession openLocal: '/testDB'. initialSession connectAs: 'admin'. initialSession commit: [ initialSession root at: 'users' put: MagmaPreallocatedDictionary new ]. initialSession disconnect; closeRepository.
newUser := User new username: 'Charlie'; yourself. newSession := MagmaSession openLocal: '/testDB'. newSession connectAs: 'charlie'. newSession commit: [ (newSession root at: 'users') at: newUser put: OrderedCollection new ]. newSession disconnect; closeRepository.
testSession := MagmaSession openLocal: '/testDB'. testSession connectAs: 'aUser'. (testSession root at: 'users') size (testSession root at: 'users') at: newUser
The last two lines indicate the problem: the size of the MagmaPreallocatedDictionary is reported correctly (even when I add more users), but when I try to access any of the entries with the 'User' objects as keys, I get a 'errorKeyNotFound:' error.
Am I doing something wrong...?
Amir _______________________________________________ Magma mailing list Magma@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/magma
Hi Facundo
Thanks for your help. What I'm trying to understand is how, between different Magma sessions, the Dictionary keys seem to 'lose' their identity. Obviously, the first thought is that there's something wrong in my code (which I why I posted it all). Surely it should be simple to check directly whether an object equals a key, without having to define hash methods...?
I ought to point out that I also tested these steps separately without committing in a Magma session, and everything worked OK.
Amir
On Thu, 30 Dec 2010 16:48:32 -0300 Facundo Vozzi facundov79@gmail.com wrote:
Hi Amir, did you define #= method on User ?
I guest that It'll look like this:
User >> = otherUser "Answer whether the receiver is equal to the argument." self class = otherUser class ifFalse: [^false]. ^self name = otherUser name
You need implement the #hash method too:
User >> hash "Answer a SmallInteger whose value is related to the receiver's identity." ^self name hash
Hope this help.
Facu
Hi Amir, each session has its *own* view of the persistent object model. It's own copy. It _must_ be that way, or else when one session changes an object it will appear "changed" for the other sessions too.
You are perfectly welcome to use identity-based checking in your Magma programs, as long as you do the check on objects from the same session.
However, as previously stated, you must ensure that identityHash is never part of the hash calculation, because the hash determines its position in the Dictionary, and it will not be the same between sessions.
HTH, Chris
On Fri, Dec 31, 2010 at 7:10 AM, Amir Ansari fractallyte@csi.com wrote:
Hi Facundo
Thanks for your help. What I'm trying to understand is how, between different Magma sessions, the Dictionary keys seem to 'lose' their identity. Obviously, the first thought is that there's something wrong in my code (which I why I posted it all). Surely it should be simple to check directly whether an object equals a key, without having to define hash methods...?
I ought to point out that I also tested these steps separately without committing in a Magma session, and everything worked OK.
Amir
On Thu, 30 Dec 2010 16:48:32 -0300 Facundo Vozzi facundov79@gmail.com wrote:
Hi Amir, did you define #= method on User ?
I guest that It'll look like this:
User >> = otherUser "Answer whether the receiver is equal to the argument." self class = otherUser class ifFalse: [^false]. ^self name = otherUser name
You need implement the #hash method too:
User >> hash "Answer a SmallInteger whose value is related to the receiver's identity." ^self name hash
Hope this help.
Facu
Magma mailing list Magma@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/magma
OK, that makes sense! Thanks for clearing this up; I can stop worrying about it now ;-)
Lastly, thank you (and other contributors) for all your time and effort on Magma - I'm using it in a web app, and it's proven to be a simple, elegant system, deserved of a far wider audience...
Happy 2011!
Amir
On Fri, 31 Dec 2010 10:58:23 -0600 Chris Muller asqueaker@gmail.com wrote:
Hi Amir, each session has its *own* view of the persistent object model. It's own copy. It _must_ be that way, or else when one session changes an object it will appear "changed" for the other sessions too.
You are perfectly welcome to use identity-based checking in your Magma programs, as long as you do the check on objects from the same session.
However, as previously stated, you must ensure that identityHash is never part of the hash calculation, because the hash determines its position in the Dictionary, and it will not be the same between sessions.
HTH, Chris
Incidentally, I'm replying to myself here - because this exchange of emails has (half) gone through personal email addresses instead of through the mailing list. Is there a way to configure the list server to exchange the 'From' field with the 'Cc' field in list emails?
So, when hitting the 'Reply' button in one's email client, the email would go automatically to the mailing list rather than the personal address of the sender...
Amir
magma@lists.squeakfoundation.org