You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Olivier Billard <ob...@rennes.jouve.fr> on 2003/10/08 14:38:22 UTC

Use of a connection in an avalon component

Hi all !

I wonder how to use a DataSourceComponent and its connection in a custom cocoon avalon 
component, that is ThreadSafe, to use all performance and connection pool used in Cocoon.

Should I :
  - get a connection via datasource.getConnection() and close() it for each public method 
call,
  - get a connection in the initialize() method from the interface Initializable, close() 
it on the dispose() method from Disposable interface, and only create a Statement for each 
public method call ?
  - implement another avalon interface, like Runnable, to get/relase the Connection ?

I looked for exemples in the databases block, but the helpers are not Components.

Thank you,

-- 
Olivier BILLARD



Re: Use of a connection in an avalon component

Posted by Olivier Billard <ob...@rennes.jouve.fr>.

On 09/10/2003 15:10, Sylvain Wallez wrote:

> Olivier Billard wrote:
> 
>> Hi all !
>>
>> I wonder how to use a DataSourceComponent and its connection in a 
>> custom cocoon avalon component, that is ThreadSafe, to use all 
>> performance and connection pool used in Cocoon.
>>
>> Should I :
>>  - get a connection via datasource.getConnection() and close() it for 
>> each public method call,
>>  - get a connection in the initialize() method from the interface 
>> Initializable, close() it on the dispose() method from Disposable 
>> interface, and only create a Statement for each public method call ?
>>  - implement another avalon interface, like Runnable, to get/relase 
>> the Connection ?
>>
>> I looked for exemples in the databases block, but the helpers are not 
>> Components. 
> 
> 
> 
> If your component is ThreadSafe, a single instance of it will exist in 
> the whole system. JDBC connections being non thread safe, you *must* get 
> and close them at each call. Don't be afraid to call close(): the 
> connection you get is a wrapper managed by the DataSourceComponent which 
> puts back the real request in the pool for later reuse when close() is 
> called on the wrapper.

by later reuse, do you mean datasource.getConnection() ?

-- 
Olivier



Re: Use of a connection in an avalon component

Posted by Sylvain Wallez <sy...@anyware-tech.com>.
Olivier Billard wrote:

> Hi all !
>
> I wonder how to use a DataSourceComponent and its connection in a 
> custom cocoon avalon component, that is ThreadSafe, to use all 
> performance and connection pool used in Cocoon.
>
> Should I :
>  - get a connection via datasource.getConnection() and close() it for 
> each public method call,
>  - get a connection in the initialize() method from the interface 
> Initializable, close() it on the dispose() method from Disposable 
> interface, and only create a Statement for each public method call ?
>  - implement another avalon interface, like Runnable, to get/relase 
> the Connection ?
>
> I looked for exemples in the databases block, but the helpers are not 
> Components. 


If your component is ThreadSafe, a single instance of it will exist in 
the whole system. JDBC connections being non thread safe, you *must* get 
and close them at each call. Don't be afraid to call close(): the 
connection you get is a wrapper managed by the DataSourceComponent which 
puts back the real request in the pool for later reuse when close() is 
called on the wrapper.

Sylvain

-- 
Sylvain Wallez                                  Anyware Technologies
http://www.apache.org/~sylvain           http://www.anyware-tech.com
{ XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }
Orixo, the opensource XML business alliance  -  http://www.orixo.com