cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Adam Ratcliffe" <a...@prema.co.nz>
Subject RE: Creating a global object for my application ?
Date Fri, 11 Feb 2005 21:50:28 GMT
Hi Lionel

I have a class AbstractDB, an Avalon component, that manages the lifecycle
of a connection.
It implements these Avalon interfaces: Initializable, Disposable,
Recyclable, Serviceable.

In initialize() I look up the datasource:

            ServiceSelector selector = (ServiceSelector)
this.serviceManager.lookup(DataSourceComponent.ROLE
                    + "Selector");
            this.datasource = (DataSourceComponent)
selector.select(this.dataSourceName);
            serviceManager.release(selector);

The method used to retrieve the connection looks like this:

            try {
                connection = datasource.getConnection();
                if (this.logger.isDebugEnabled())
                    this.logger.debug("Connection created: " +
this.connection.hashCode());
            } catch (Exception e) {
                throw new Exception("Could not create SQL connection using
datasource '" + this.dataSourceName + "'!",
                        e);
            }

In recycle() I close the connection, and in dispose I release the
datasource:

        if (datasource != null) {
            serviceManager.release(datasource);
        }

Is this something like you had in mind?

HTH
Adam

> -----Original Message-----
> From: Lionel Crine [mailto:crine@4dconcept.fr]
> Sent: Saturday, 12 February 2005 3:58 a.m.
> To: users@cocoon.apache.org
> Subject: Creating a global object for my application ?
>
>
> Hi,
>
> Here is my puzzle :
> I'd like to initialize an object (to access a database) only when a user
> get his connection granted.
> And then, I want to release the object when the session is finished.
>
> Obviously, The created object should handle multiple users.
>
>
> Is there any aboject defined in Cocoon as a component or should I make
> it myself ?
>
>
> Thanks in advance.
> Lionel
>
>
>
> --
> Lionel CRINE
> Ingénieur Systèmes documentaires
> Société : 4DConcept
> 22 rue Etienne de Jouy 78353 JOUY EN JOSAS
> Tel : 01.34.58.70.70 Fax : 01.39.46.06.90
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message