Querying nested MagmaCollections

Amir Ansari fractallyte at csi.com
Thu Jan 7 13:12:29 UTC 2010


Dear List,

I'm not lazy!  I've gone through the mailing list, and various  
Smalltalk books.  There's little information on how to handle nested  
collections, much less nested MagmaCollections.  But I can imagine this  
would be a fairly common task, especially since object databases are  
structured in a different way to relational databases.  (This also came  
up on the mailing list a while ago:  
http://lists.squeakfoundation.org/pipermail/magma/2007-March/ 
000598.html)


I've created two example classes: Writer (with 'books' and 'name'  
instance variables and accessors), and Book (with 'title' instance  
variable and accessors).

'books' is a MagmaCollection of Book items, contained within Writer  
(ie. a Writer creates many Books!). This is initialised in Writer:

initialize
	books := MagmaCollection new.
	books addIndex: (MaKeywordIndex attribute: #title)


OK, now I create a MagmaCollection called myLibrary and add some  
example books:


myLibrary := MagmaCollection new.
myLibrary addIndex: (MaKeywordIndex attribute: #name).

writer1 := Writer new name: 'Margaret Mitchell'.
writer1 books
	add: (Book new title: 'Gone With the Wind');
	add: (Book new title: 'Lost Laysen').

writer2 := Writer new name: 'Kenneth Grahame'.
writer2 books
	add: (Book new title: 'The Wind in the Willows');
	add: (Book new title: 'The Reluctant Dragon').

writer3 := Writer new name: 'Anne McCaffrey'.
writer3 books
	add: (Book new title: 'Dragonriders of Pern');
	add: (Book new title: 'Crystal Singer').

myLibrary
	add: writer1;
	add: writer2;
	add: writer3.


The problem I'm struggling with is how to query this data structure!  I  
would like to generate collections based on the following queries:

1.	All books with titles containing the word 'wind'
2.	All writers who have books with titles containing the word 'dragon'


Thanks for any help!

Amir



More information about the Magma mailing list