[Setools] [gjallar] Playing with the model

goran at krampe.se goran at krampe.se
Thu Sep 21 08:38:08 UTC 2006


Hi!

A mini howto on how to play in a workspace with the Gjallar model in
Magma etc.

In Gjallar there is a session class called Q2Session. It is a subclass
of WASession (Seaside session class) that primarily adds a MagmaSession
in it.

There is also a class called Q2SessionWithoutSeaside that you use when
being outside of Seaside, and a Q2MockSession that simulates Magma when
running unit tests (for speed). You can get (and release) a session like
this:

Q2Session sessionDo: [
	session _ Q2Session current.
	model _ session model.
	....]

#sessionDo: will allocate a session (a Q2Session or a
Q2SessionWithoutSeaside depending) and bind it to the current running
Process using DynamicBindings. It also sets the current user of the
session to 'system' by default. Please trace (or just browse) the above
code and you will find Q2Session>>current that does the actual
instantiation of the correct session class.

You can also allocate a current session to the UI process in Morphic and
get its model:

	Q2Session current model

Evaluating this the first time allocates a Q2SessionWithoutSeaside (with
a MagmaCollection from the Q2MagmaSessionPool) and gets its model from
Magma. Evaluating this another time should give you the same already
bound session and thus the same model. When you are done you can get rid
of it using:

	Q2Session releaseCurrent

Which unbinds and releases the session from the UI process. You can see
that it is gone by using:

	Q2Session currentOrNil

Which should return nil if none is allocated. One "problem" with
exploring the model is that it uses MagmaCollections for a few things
(like the cases themselves) and they are not explorer/inspector-enabled
yet.

One way to more easily learn a bit about the model is to then use the
Q2MockMagmaSession instead which will use Q2MockMagmaCollections
(subclass of SortedCollection). Do it like this:

	Q2Session useMock: true. "this sets a class var"
	Q2Session current createMockModel. "this allocates a Q2MockMagmaSession
and then does the initializeDatabase and bootStrap of the model. The
model is then held in a class var in Q2Session."
	Q2Session current model explore. "open up an explorer. Have a look."
	Q2Model loadSampleData "this now works fine, the code is the same if we
use Magma or Mock. Notice that the model in the explorer now has cases
in it."


Finally, how do we run "doits" in an equivalent way as it is done in the
console in Gjallar? Well, one could think it would be enough to do it
like:

Q2Session sessionDo: [
	session _ Q2Session current.
	model _ session model.
	....]

...but that will not package it as a Q2Txn. So if we want to be "true"
to the transaction model (might not matter when just playing around etc)
we need to make sure we create proper txns. There are essentially two
ways, either we use the messages in Q2Model category "transactions". All
(almost - but deviations are known bugs) modifications in Gjallar go
(and should go) through one of those methods! This means that in order
for a "doit" to become a proper txn we need to use
#modifyProcessDefinitionIn:to: and #modifyGlobalDefinitionTo: (I should
rename them) which takes a String of code. To be completely true to the
model that code must not rely on dynamic properties like the current
time or randomness etc - in other words - they need to give the same
result if replayed once more. This is similar to how
Prevayler/SPrevayler works.

So if you are just playing around you can do like the above (with proper
compilation and syntax errors etc) but to produce "correct" txns we
unfortunately today need to do:

Q2Session sessionDo: [
	Q2Session current model modifyGlobalDefinitionTo: '(self findUserNamed:
''balder'') username: ''newbalder''']

Btw, when exploring the mock model the Q2MockMagmaCollections seem to be
"wrongly ordered" like for example the transactions in Q2Model. This is
because they use an ordering by hash by default. If you do "transactions
read: #number" you get a correctly ordered collection based on that
index. See #initializeTransactionsCollection where we create the index.

Well, over and out for now - gotta write some code. :)

regards, Göran


More information about the Setools mailing list