<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Hi All,<br>
<br>
I have been working on a revised Magma-Seaside interface using Session
Helpers, i.e. this allows you to add Magma to any seaside application
without needing a specialized subclass of WASession.I also have a
tutorial portion for Magma almost ready.<br>
<br>
I just need a bit of spare time for testing, so watch this space.<br>
<br>
Keith<br>
<br>
<br>
======<br>
<br>
Draft Tutorial follows:<br>
<br>
<b>Saving all data in an object-oriented database: Magma</b><br>
<br>
Another option to make your data persistent is to use an
object-oriented database like Magma.<br>
<br>
<b>Installing the Magma Database</b><br>
<br>
Magma is written entirely in Squeak, so there is no need to install a
separate server application. Both Magma and Seaside can run in the same
image. To install (into a 3.10 based image) just execute the following.
(This may take a while)<br>
<br>
<tt><b>Installer universes install: 'Magma seasideHelper'.</b></tt><br>
<br>
<b>Configuring your application to use Magma</b><br>
<br>
In the configuration for the 'todo' application you will need to add
WAMagmaConfiguration to the configuration "ancestry". Select it from
the drop down menu and click "Add". As soon as you do this, a new group
of configuration options will appear. You will need to select the
"WAMagma", helper class from the drop down menu.<br>
<br>
The WAMagma class provides the basic interface between Magma Sessions
and Seaside Sessions. Subclasses provide specialized session management
such as shared or pooled sessions. <br>
<br>
<b>Using Magma</b><br>
<br>
Magma is very easy to use with seaside. To obtain and use a database
session helper, simply send #magma to the current session. For example
the code "self session magma" will work within all seaside components.<br>
<br>
To use Magma in this application in a similar manner to the way we have
connected to databases in other examples we need to create an
interfacing class, to which we can add our specialized querying
methods. We will use this interfacing class as our root object in the
database.<br>
<i><br>
(note at present if a subclass of Dictionary is used then it is not
possible to add instVars to this class)<br>
</i><tt><br>
Dictionary subclass: #StMagmaDatabase<br>
    instanceVariableNames: ''<br>
    classVariableNames: ''<br>
    poolDictionaries: ''<br>
    category: 'STTutTodoApp'<br>
<br>
StSession-#initialize<br>
    super initialize.<br>
    self db: (self magma rootAs: StMagmaDatabase)</tt><br>
<br>
The tutorial application accesses the database via the #db accessor.
Here we define this using the #rootAs: helper method, which does
everything we need, both to initialize the database, and to provide us
the interface that we want to it.<br>
<br>
<b>Initializing the Database Root</b><br>
<br>
To initialize our users collection we define the initialization on our
root object, and we need a method to return the users from the
database, to add a new user, and to find a user.<br>
<br>
<tt>StMagmaDatabase-#initialize<br>
    | users |<br>
    users := OrderedCollection new.<br>
    self at: #users put: users.<br>
<br>
StMagmaDatabase-#users<br>
        ^ self at: #users  <br>
<br>
StMagmaDatabase-#addUser: newUser<br>
        ^ self users add: newUser<br>
<br>
StMagmaDatabase-#findUserByEmail: anEmail<br>
    ^ self users <br>
        detect: [:each | each email equals: anEmail] <br>
        ifNone:[]</tt><br>
<br>
Notice how for basic usage we have not needed any database specific
code! <br>
<br>
If our userbase is going to grow to a significant size it makes sense
to re-implement the above using some database features, so let us
introduce a MagmaCollection, a collection designed to enable concurrent
access to large indexed data sets.<br>
 (<a class="moz-txt-link-freetext" href="http://wiki.squeak.org/squeak/2639">http://wiki.squeak.org/squeak/2639</a>) <br>
<br>
In this instance we use a factory method to create our MagmaCollection.
This allows us to switch the Magma helper to seamlessly by using
WAMockMagma instead of WAMagma.<br>
<br>
<tt>initialize<br>
    | users |<br>
    users := WAMagma factory newMagmaCollection.<br>
    users addIndex: (MaSearchStringIndex attribute: #email) beAscii.<br>
    self at: #users put: users<br>
<br>
findUserByEmail: anEmail<br>
    ^ (self users where: [ :each | each email equals: anEmail ] )
firstOrNil<br>
</tt><br>
to be continued....<br>
<br>
<br>
<br>
</body>
</html>