Main

Seaside Archives

October 27, 2007

Postgres database connection pools in Seaside, part 2.

Postgres database connection pools in Seaside

Part 2. Configurations

Using Rails you have several places to include configuration code for your application, you use database.yml, config.rb, environment.rb, environments/development.rb, environment/production.rb, etc. In those files you can set variables that your application code will use, execute code and basically, anything you need in order to provide the required parameters to your application.

If you use Django you have a settings file for your all your configuration needs.

Seaside is no exception, it provides a very powerful, flexible and versatile mechanism to configure a web application.

A Seaside configuration class provides more than just a set of keyed values, it defines the type of the values and it can provide a list of options that an administrator can change through the administrative interface of Seaside, it also provides some kind of 'inheritance'.

Before getting into database connections with its user, password and other parameters, I will use a configuration class for those parameters. For an introduction about configurations you should read the following pages:

  1. Configuration and Preferences
  2. David Shaffer's tutorial: Custom application configuration parameters.

Now back to our business. We will use a configuration class for all the required Glorp parameters:

WASystemConfiguration subclass: #GlorpSessionConfiguration
    instanceVariableNames: ''
    classVariableNames: ''
    poolDictionaries: ''
    category: 'LearnGlorpSession'

With the these methods:

ancestors
    ^ Array with: WASessionConfiguration new

attributes
    ^ Array
        with: (WAStringAttribute key: #sessionClass) 
        with: (WAStringAttribute key: #glorpServer group:#database)
        with: (WAStringAttribute key: #database group:#database)
        with: (WAStringAttribute key: #glorpUserName group:#database)
        with: (WAStringAttribute key: #glorpPassword group:#database)

glorpDatabase
    ^'You need to provide a database'

glorpPassword
    ^''

glorpServer
    ^'localhost'

glorpUserName
    ^'postgres'

sessionClass
    ^MyPostgresSession

sessionClasses
    ^MyPostgresSession withAllSubclasses

I will assume you don't have a Seaside root component yet so let's write one:

WAComponent subclass: #GlorpExampleComponent
    instanceVariableNames: ''
    classVariableNames: ''
    poolDictionaries: ''
    category: 'GlorpExample'

renderContentOn: html
    html text: 'Glorp example'

And with a class method:

canBeRoot
    ^ true

( You can read more about the root component here )

Then load this url in your browser (using the port you told SSKom to use): http://localhost:9091/seaside/config and enter the user and password ( defaults: admin/seaside ).

Under "Add entry point" define a name for our testing application, for the example I will use: glorpexample. Then select the Root component from the combo 'GlorpExampleComponent'.

And now, pay attention to the options provided in the combo list named 'Ancestry'. Your configuration class is listed there! Select it and click the Add button.

Now save the changes.

What do we have so far?

We have a Seaside application with our configuration class that provides a custom Seaside session that provides a pool of connections to PostgreSQL.

If you load again the configuration page for our glorpexample application you can appreciate a separated section for the database! You can change the field values or revert to the previous ones.

With these, all you need to do now to execute a query using Glorp is: WACurrentSession value execute: query.

October 18, 2007

Postgres database connection pools in Seaside, part 1.

Installation

  1. I will use Ramón León's Squeak image. It has a customized UI, much better than the default Squeak interface and comes with all we need ( Postgres access, Glorp, Seaside ).

  2. Download and install the corresponding Squeak version for that image (check León's page).

  3. Launch the Squeak image.

  4. If you are on OSX change the port change the port SSKom port to some number greater than 1024, like: SSKom startOn: 9091 and execute ('Do it') that line.

Now you have Seaside running from that image and we can begin writing some code.

seasidesskomstart.png

October 10, 2007

Postgres pools for Seaside using Glorp

As a complete Smalltalk newbie one of my main concerns about writing a web application for the company I work for using Seaside was how to use database connections in a correct and scalable way.

After writing a couple of configuration pages in Seaside for a current internal application written in Rails a few months ago, I was ready to write something 'real'. Worried about how to get that done, I avoided the risks and kept working at other stuff.

Well, now I was getting again into the mood to trying it out and found a blog post about using Glorp and Seaside. The author, Ramon León, directed me to his MagritteGlorp package that provides connection pooling and integration with the Seaside session management code.

Well, after digging into it for a few hours I got it working and will be posting soon a basic guide/example of how to use it.

About Seaside

This page contains an archive of all entries posted to [Brain dump] / old in the Seaside category. They are listed from oldest to newest.

Many more can be found on the main index page or by looking through the archives.