[Seaside] Re: Let me see if I understand correctly...(more DB pool, application/session stuff).

Yanni Chiu yanni at rogers.com
Mon Feb 27 14:34:38 UTC 2006


Rich Warren wrote:
> I can have my components use a session subclass that I've created.  Each 
> user gets their own session object (more or less, assuming of  course 
> they don't have multiple browsers open, etc.).

Yes. You can see the session id in the URL - it's the _s query parameter.

> So, if I want  all the 
> sessions to access an application-global resource (for  example, a 
> connection pool for a database), I would need to either  use a global 
> variable (which I'm not sure how to do in SmallTalk) or  use a singleton 
> class (which seems better than the global option, but  still has some 
> problems).

Yes, you could use a global. Note that all class object are globals.
Just like you code "MyApplication new", you can do "MyConnectionPool new",
to get a new connection pool instance.

Globals, like MyApplication and MyConnectionPool are held in the
"Smalltalk" system dictionary. Try "Smalltalk inspect". Just use
#at:, #at:put: and #removeKey: to manage the entries. You don't have
to add new classes that you define, because the compiler does
it for you. Objects that are not classes are also held there. Try:
"Smalltalk select: [:e | e isBehavior not]"

Here are a bunch of options for your connection pool:

1. Global connection pool instance.

You can add your connection pool as a global using:
     Smalltalk at: #DBConnectionPool put: MyConnectionPool new
Then access it in your code using "DBConnectionPool"

2. Singleton

Define a class variable and accessor in MyConnectionPool to hold
the singleton instance, then access it using:
     MyConnectionPool default

3. Class as singleton

The class is already a global. Simply define all your connection
pool methods on the class side. Then access your singleton using
just "MyConnectionPool"

4. Class variable in MySession

Add a class variable in MySession, maybe call it DBPool.
Then within you session, access it using DBPool.

There may be a bunch of other ways. One of them is class pools,
but I'll leave the explanation of pros/cons of that approach
to another time (or to someone else).

Of course, you still need to figure out when and where to
initialize your connection pool, but that depends on the
rest of your application.

> Ideally I would like to subclass the application and have the  
> application itself manage the global resource--but that does not seem  
> to be a possibility within the seaside framework.

Seaside doesn't appear to have it, because the Smalltalk environment
already provides it.

> Am I missing something, or thinking about this the wrong way?

Yes, Smalltalk is a rich development environment. Take some time
to explore it (look at tutorials and books that are freely available).



More information about the Seaside mailing list