Hi Deepal,
Thank you, it really looks like good idea to implement interface
ServiceLifeCycle and make database pool there or to store it in AxisService
Parameter. It s a pity there s no sample in Axis2 distribution for pooling
database connection in Axis Service and I havent found it also in net. But
at least theres a sample for ServiceLifeCycle:)


       Regards Vladi




-----Original Message-----
From: Deepal Jayasinghe [mailto:[EMAIL PROTECTED] 
Sent: Thursday, October 11, 2007 12:43 PM
To: [email protected]
Subject: Re: Database connection

Hi VF
> Hi all,
> I would like to ask u, how can i utilize database connection in my web 
> service. I have one web service with more methods in it. Id like to 
> create database connection just once and not with each call (each 
> operation works with the same database connection) Is it enough to 
> create this service with application scope?
>   
Well if you deploy the service in application scope and inside the following
method you can have the DB initialization code and store the DB properties
in ServiceContext.

public void init(ServiceContext sc){
   //Db handling code goes here
}

Or there is some other way of doing that. In that way you do not need to
worry about the scope of the service , you can create the DB once and store
in AxisService or in ConfigurationContext and access it inside your method
call. To do that you need to have an implementation of "ServiceLifeCycle"
interface and you can include that in your services.xml as follows. In the
above impl write your code to start the DB inside the startUp and DB closing
steps in side the shutDown method.

<service class="org.sample.MyServiceLifeCycleImpl">

</service>

Thanks
Deepal
> It looks like this:
>
> Available services
> stkdds
>
> Service Description : stkdds
> Service Status : Active
> Available Operations
>
>     * getFinishedOrderBin
>     * getOrderInfo
>     * updateOrder
>     * getUserInfo
>     * cancelOrder
>     * updateUser
>     * testOperation
>     * getOrdersOverview
>     * getAllAccountsInfo
>     * getFinishedOrder
>     * getAccountInfo
>     * newOrder
>
>
> And my code for database connection smth like this:
>
> public Connection setConnection() throws Exception {
>       
>       if(conn != null){
>               return conn;
>         }
>
>             Class.forName("org.firebirdsql.jdbc.FBDriver");
>               conn = DriverManager.getConnection (p_connect_string, 
> sqlProps);
>             return conn;
>
>
>
>
>  Thanks Vladi
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
>   

--
Thanks,
Deepal
................................................................
"The highest tower is built one brick at a time"



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to