You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Jonny Pony <jo...@hotmail.com> on 2004/10/19 13:27:43 UTC

Action (accessing jdbc-pooll) using Avalon components

Hi,

I want my action to access the jdbc-pool configured in the cocoon.xconf.

My try so far:


package foo.bar.acting;

import java.sql.*;
import org.apache.avalon.framework.service.*;
...


public class PoolTest extends AbstractAction implements Serviceable{

	public Map act(Redirector redirector, SourceResolver resolver,
			Map objectModel, String source, Parameters params) {
		...
		/*
			I want to use the service method below in this action
			But how??
		*/
	}

	public void service(ServiceManager manager) throws ServiceException {

		ServiceManager serviceManager = null;
		ServiceSelector selector = (ServiceSelector) 
serviceManager.lookup(DataSourceComponent.ROLE + "Selector");

		DataSourceComponent ds = (DataSourceComponent) 
selector.select("mysql-test");
		Connection con = null;
		...

		try {
			con = ds.getConnection();
			...
		} catch (Exception e) {
		} finally {
			try {
				con.close();
			} catch (Exception e) {
			}
			if (selector != null)
				selector.release(ds);
			if (serviceManager != null)
				serviceManager.release(selector);
		}
	}
}

My question is how to use the service method in this action. Or more 
precise, how to access it?
Do I pass an empty ServiceManager?

Jonny

_________________________________________________________________
Tun Sie Ihrem Rechner ’was Gutes. MSN Hotmail mit McAfee® Anti-Virus. 
http://www.msn.de/email/antivirus/ Jetzt kostenlos anmelden!


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


Re: Action (accessing jdbc-pooll) using Avalon components

Posted by Jorg Heymans <jh...@domek.be>.
in service() set the manager to an instance variable, then access it in 
act() - or did i completely miss your point?

Jonny Pony wrote:
> Hi,
> 
> I want my action to access the jdbc-pool configured in the cocoon.xconf.
> 
> My try so far:
> 
> 
> package foo.bar.acting;
> 
> import java.sql.*;
> import org.apache.avalon.framework.service.*;
> ...
> 
> 
> public class PoolTest extends AbstractAction implements Serviceable{
> 
>     public Map act(Redirector redirector, SourceResolver resolver,
>             Map objectModel, String source, Parameters params) {
>         ...
>         /*
>             I want to use the service method below in this action
>             But how??
>         */
>     }
> 
>     public void service(ServiceManager manager) throws ServiceException {
> 
>         ServiceManager serviceManager = null;
>         ServiceSelector selector = (ServiceSelector) 
> serviceManager.lookup(DataSourceComponent.ROLE + "Selector");
> 
>         DataSourceComponent ds = (DataSourceComponent) 
> selector.select("mysql-test");
>         Connection con = null;
>         ...
> 
>         try {
>             con = ds.getConnection();
>             ...
>         } catch (Exception e) {
>         } finally {
>             try {
>                 con.close();
>             } catch (Exception e) {
>             }
>             if (selector != null)
>                 selector.release(ds);
>             if (serviceManager != null)
>                 serviceManager.release(selector);
>         }
>     }
> }
> 
> My question is how to use the service method in this action. Or more 
> precise, how to access it?
> Do I pass an empty ServiceManager?
> 
> Jonny
> 
> _________________________________________________________________
> Tun Sie Ihrem Rechner ’was Gutes. MSN Hotmail mit McAfee® Anti-Virus. 
> http://www.msn.de/email/antivirus/ Jetzt kostenlos anmelden!


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