Last updated at 6:39 am UTC on 9 December 2007
Magma provides very suitable database support to a Seaside web application.
The Magma repository on SqueakSource includes a package Magma seaside. This package may be installed after installing Magma and Seaside to provide Seaside applications a suggested interface to a Magma repository, and a supplemental panel in Seaside's Configuration utility to point the application to any local or remote Magma repository.
Communication with Magma occurs through database sessions. Each Seaside session will create its own connection to the Magma repository, known as a MagmaSession. Note WAMagmaSession extends WASession to manage the allocation of this MagmaSession and its closure when the Seaside session is finalized.
Two Types of Connections
With the new panel in Seaside's configuration utility you may specify one of two ways it should connect the MagmaSession, local or remote. The base Magma installation abstracts this distinction with subclasses of MagmaLocation.
For small systems with just a few users, a local connection serializes all database requests from all Seaside sessions, single-threaded.
The fully qualified pathname of the Magma repository must be supplied to the MagmaLocalLocation
Larger systems may utilize a remote connection to the Magma repository running in a separate image. This should scale to a significantly larger user base, particularly in the context of multiple Seaside images (each handling a finite number of Seaside sessions), by dividing the heavy Magma-client burden across multiple images, threads, machines. The lightly-taxed Magma-server will not starve so long for requests and, under maximum throughput conditions, always have a few requests queued and ready.
Under this configuration, each MagmaSession accesses the repository over TCP. To this end only the hostname and port need be supplied.
Note, when using a remote connection, the remote repository must be opened and started separately, for more information see Getting started with Magma.
Regardless of which type of connection is used (local or remote), the Seaside application code remains exactly the same. Once the connection has been set through the Configuration utility, all access to the data from a MagmaSession is transparent; e.g., via normal method sends. Each session's view of the data is refreshed at each transaction boundary, with optimistic locking to ensure consistency.
Integrating The Seaside Sushi Store with Magma
Seaside provides a Sushi Store application to demonstrate the features it offers. This application (WAStore) does not read the inventory of available sushi options (WAStoreItem) from a database, nor does it store the orders once they have been processed.
To add this functionality, the following must be performed:
- Create a Magma repository to hold the inventory and the orders.
- Modify WAStore to use Magma.
- Modify the Sushi Store code to read the inventory of WaStoreItems from Magma.
- Introduce a new class WAOrder to hold all the details of an order.
- Modify the Sushi Store code to persist WAOrder instances.
- Modify the Sushi Store code to list the orders.
A change set is provided from this page implementing these functions and to demonstrate how the WAStore application was modified to use Magma.
Installing the Tutorial change Set
- Install Seaside 2.5 or 2.6 from SqueakSource
- Install MagmaServerLoader from SqueakMap (part of the Magma project)
- Install Magma seaside from SqueakSource (part of the Magma project)
- Install the seasideSushiStoreWithMagma.cs.gz change set.
The change set will open a Workspace with instructions.
WAMagmaSession also provides convenience methods to acess the Magma repository (via the MagmaSession).
To ensure that all Seaside applications use WAMagmaSession and can configure a MagmaLocation via the seaside/config application, the Magma seaside package provides WAMagmaConfiguration which is used by Seaside root components.
Contact Brent Pinkney or the Magma mailing list for assistance.