Good day all,
I am looking at the Magritte/Pier "bible" (Reng06a.pdf) Sec 2.3.2 (page 8)
Object Relational Mapping. I decided I would take a stab at implementing:
"In a very similar way, we are able to automatically create SQL statements
to store, load and query objects from a relational database". Any one care
to offer hints? I am very much a novice at all these patterns and things, so
I am guessing a Visitor pattern of sorts (I HAVE been studying the Gang of
Four bible tho ;)....
Here is what I have so far:
MADescription:
added methods:
> toSql: anObject ^self toSql: anObject writer:
self sqlWriter.
>sqlWriter ^self propertyAt: #sqlWriter ifAbsent: self class
defaultSqlWriter.
class>>defaultSqlWriter ^SQLWriter
And I have created MAWriter subclass SQLWriter with one instance variable
'sql'
SQLWriter>>defaultWriteStream
^((sql isNil ifTrue: [ sql := String new]) writeStream).
SQLWriter>>write: anObject description: aDescription to: aStream
anObject isNil ifTrue: [ ^ aDescription undefined ].
^ super write: anObject description: aDescription to: aStream which,
looking at it now, I really shouldn't need to override
Then there are the visiting method which are going to be the reall tricky
part.
SQLWriter>>visitContainer: aDescription
aDescription memento model isNil "we have a NEW model object so
INSERT" will this work????? heh
ifTrue: [ stream nextPutAll: 'INSERT INTO '; nextPutAll:
aDescription table; nextPutAll: ' VALUES ('; cr ] where does the table
method come in? hmmm
ifFalse: [ stream nextPutAll: 'UPDATE '; nextPutAll aDescription
table; cr; nextPutAll: 'SET ' ].
And then I will need to add something like:
aDescription do: [ :desc | self write: something description: desc
stream: stream ] What something goes here I am still scratching my head
about...
Any help/suggetions with this last part would be greatly appreciated.
Also, I have started to get used to looking at the unit tests to figure out
what things are supposed to do, then I noticed that there are NO tests for
MAVisitor and subclasses. Why is that? (Or am I missing something?)
Thanks in advance for any advice
John McKeon