You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Marcin Okraszewski <ok...@o2.pl> on 2003/12/13 22:42:19 UTC

How to obtain db connection from pool ?

Hi,
I want to use my classes in Cocoon application. Unfortunately I don't 
know how to obtain a database connection from defined pool for database. 
How can I do it? I tried to reproduce code generated by ESQL, but I 
obtain nulls.

Regards,
Marcin Okraszewski


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


Re: How to obtain db connection from pool ?

Posted by Olivier Billard <ob...@rennes.jouve.fr>.
You can access the "cocoon context" in Avalon Components via the Contextualizable interface.

If you intend to get the request or the session in XSP, logicsheets will do the job, with 
thinks like : <xsp-request:get-parameter name="myParam" default="myParamDefaultValue"/>

--
Olivier

On 16/12/2003 09:36, Marcin Okraszewski wrote:

>> solution, I've adopted it from the code of database action, and it
>> looks almost the same (but written in javascript instead of java).
>> Because Cocoon is Avalon based I dont think there's other (non-Avalon)
>> possibility to achieve what you asked. Flowscript gives you access to
>> some Cocoon Avalon Components, which you can make use of mixing with
>> your own java components (not necesserily Avalon Components). I did so
>> and it works.
> 
> 
> In fact I use the flowscript. But, isn't it possible to obtain the 
> "cocoon context" without passing it from flowscript? I mean does any 
> class can obtain context by for example new org.apache.cocoon.Cocoon() - 
> I'll have to try it. Previously I tried with new 
> org.apache.cocoon.components.CocoonComponentManager() but it returned me 
> a null connection. Unfortunately I'm not into Avalon :-(
> 
>> BTW It's very funny to write in English to Polish folk ;-)
> 
> 
> Yes, I've also noticed it. It happens to me for a second or a third time 
> at this group :-) But (un)fortunately English is /official/ language of 
> computers.
> 
> Regards,
> Marcin Okraszewski



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


Re: How to obtain db connection from pool ?

Posted by Marcin Okraszewski <ok...@o2.pl>.
> solution, I've adopted it from the code of database action, and it
> looks almost the same (but written in javascript instead of java).
> Because Cocoon is Avalon based I dont think there's other (non-Avalon)
> possibility to achieve what you asked. Flowscript gives you access to
> some Cocoon Avalon Components, which you can make use of mixing with
> your own java components (not necesserily Avalon Components). I did so
> and it works.

In fact I use the flowscript. But, isn't it possible to obtain the 
"cocoon context" without passing it from flowscript? I mean does any 
class can obtain context by for example new org.apache.cocoon.Cocoon() - 
I'll have to try it. Previously I tried with new 
org.apache.cocoon.components.CocoonComponentManager() but it returned me 
a null connection. Unfortunately I'm not into Avalon :-(

> BTW It's very funny to write in English to Polish folk ;-)

Yes, I've also noticed it. It happens to me for a second or a third time 
at this group :-) But (un)fortunately English is /official/ language of 
computers.

Regards,
Marcin Okraszewski


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


Re: How to obtain db connection from pool ?

Posted by Mariusz Sieraczkiewicz <ma...@o2.pl>.
There are two possibities I know:
1) flowscript
2) Avalon Component.

Please give some context. I guess the flowscript is the easiest
solution, I've adopted it from the code of database action, and it
looks almost the same (but written in javascript instead of java).
Because Cocoon is Avalon based I dont think there's other (non-Avalon)
possibility to achieve what you asked. Flowscript gives you access to
some Cocoon Avalon Components, which you can make use of mixing with
your own java components (not necesserily Avalon Components). I did so
and it works.

Regards Mariusz Sieraczkiewicz.

BTW It's very funny to write in English to Polish folk ;-)

On Mon, 2003-12-15 at 23:24, Marcin Okraszewski wrote:
> Hi,
> And how about obtaining it outside a flow? How to get the instance of 
> the component selector that I could run something similar to 
> cocoon.getComponent() from the example below?
> 
> Regards,
> Marcin Okraszewski
> 
> > Suggested using flowscript, then try sth like this:
> > 
> >     try {
> >         var dbSelector = 
> > cocoon.getComponent(Packages.org.apache.avalon.excalibur.datasource.DataSourceComponent.ROLE 
> > + "Selector");
> >         var dataSrc = dbSelector.select("your counnection");
> >         conn = dataSrc.getConnection();
> > 
> >       // your stuff
> >     }
> >     catch (e) {
> >         e.toString();
> >     }
> >     finally {
> >         if (conn != null) {
> >             conn.close();
> >             conn = null;
> >         }
> > 
> >         if (dbSelector != null) {
> >             cocoon.releaseComponent(dbSelector);
> >             dbSelector = null;
> >         }
> >     }
> > 
> > But if you write Avalon Component, just look at database actions sources.
> > 
> > Regards
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> > For additional commands, e-mail: users-help@cocoon.apache.org
> > 
> > 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 



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


Re: How to obtain db connection from pool ?

Posted by Marcin Okraszewski <ok...@o2.pl>.
Hi,
And how about obtaining it outside a flow? How to get the instance of 
the component selector that I could run something similar to 
cocoon.getComponent() from the example below?

Regards,
Marcin Okraszewski

> Suggested using flowscript, then try sth like this:
> 
>     try {
>         var dbSelector = 
> cocoon.getComponent(Packages.org.apache.avalon.excalibur.datasource.DataSourceComponent.ROLE 
> + "Selector");
>         var dataSrc = dbSelector.select("your counnection");
>         conn = dataSrc.getConnection();
> 
>       // your stuff
>     }
>     catch (e) {
>         e.toString();
>     }
>     finally {
>         if (conn != null) {
>             conn.close();
>             conn = null;
>         }
> 
>         if (dbSelector != null) {
>             cocoon.releaseComponent(dbSelector);
>             dbSelector = null;
>         }
>     }
> 
> But if you write Avalon Component, just look at database actions sources.
> 
> Regards
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 
> 



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


Re: How to obtain db connection from pool ?

Posted by Mariusz Sieraczkiewicz <ma...@o2.pl>.
Suggested using flowscript, then try sth like this:

     try {
         var dbSelector = 
cocoon.getComponent(Packages.org.apache.avalon.excalibur.datasource.DataSourceComponent.ROLE 
+ "Selector");
         var dataSrc = dbSelector.select("your counnection");
         conn = dataSrc.getConnection();

	  // your stuff
     }
     catch (e) {
         e.toString();
     }
     finally {
         if (conn != null) {
             conn.close();
             conn = null;
         }

         if (dbSelector != null) {
             cocoon.releaseComponent(dbSelector);
             dbSelector = null;
         }
     }

But if you write Avalon Component, just look at database actions sources.

Regards

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