You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by John Wilkinson <Jo...@xyratex.com> on 2009/09/23 10:11:36 UTC

persistance using POJO's

Hi,

I wish to have my service persist POJO's to a postgresql database.

 

 Every time I call a service, do I need to connect to a database, and
then at the end close the connection. Or is there a way to open the
connection when the service is first called, and then close when I stop
using the service, say by a method call?

 

 

Many regards,

John.

 

 


______________________________________________________________________
This email may contain privileged or confidential information, which should only be used for the purpose for which it was sent by Xyratex. No further rights or licenses are granted to use such information. If you are not the intended recipient of this message, please notify the sender by return and delete it. You may not use, copy, disclose or rely on the information contained in it.

Internet email is susceptible to data corruption, interception and unauthorised amendment for which Xyratex does not accept liability. While we have taken reasonable precautions to ensure that this email is free of viruses, Xyratex does not accept liability for the presence of any computer viruses in this email, nor for any losses caused as a result of viruses.

Xyratex Technology Limited (03134912), Registered in England & Wales, Registered Office, Langstone Road, Havant, Hampshire, PO9 1SA.

The Xyratex group of companies also includes, Xyratex Ltd, registered in Bermuda, Xyratex International Inc, registered in California, Xyratex (Malaysia) Sdn Bhd registered in Malaysia, Xyratex Technology (Wuxi) Co Ltd registered in The People's Republic of China and Xyratex Japan Limited registered in Japan.
______________________________________________________________________

RE: persistance using POJO's

Posted by John Wilkinson <Jo...@xyratex.com>.
Thanks Sagara for you help, I will have a go.

Many regards,
John.
 
John Wilkinson.
Product Engineer.
----x-y-r-a-t-e-x----
e-mail: john_wilkinson@xyratex.com
Tel: +44 (0)2392 6225
Mobile: +44 (0)7810 497152

-----Original Message-----
From: Sagara Gunathunga [mailto:sagara.gunathunga@gmail.com] 
Sent: 23 September 2009 12:27
To: axis-user@ws.apache.org
Subject: Re: persistance using POJO's

Hi John,

Can you try for this ...

In your ServiceLifeCycle implementation class open and close the db
connection as follows.

Class MyServiceLifeCycle implements ServiceLifeCycle  {

	public void startUp(ConfigurationContext arg0, AxisService service) {

           Connection conn=null;
          // Open the DB connection as usual.

         //set Connection object as a Parameter
         service.addParameter("dbConnection", conn);	
		
	}



      public void shutDown(ConfigurationContext arg0, AxisService service) {
		
           //get DB Connection from the service
           Connection conn=(Connection)service.getParameter("dbConnection");

         //close the  DB Connection
        ......................................		
	}
}




Then in your web service method you can access to above  DB Connection
as follows .

public XXXX myServiceMethod(){


// get DB Connection
AxisService service=MessageContext.getCurrentMessageContext().getAxisService();
Connection conn=(Connection)service.getParameter("dbConnection");


}


HTH


Thanks ,



On Wed, Sep 23, 2009 at 4:25 PM, John Wilkinson
<Jo...@xyratex.com> wrote:
> Thank you Sagara,
> If I implement the ServiceLifeCycle interface, can you give me a simple example of how I would access the connection from a POJO, and how the startup method saves the connection to a parameter, please.
>
> Many regards,
> John.
>
> John Wilkinson.
> Product Engineer.
> ----x-y-r-a-t-e-x----
> e-mail: john_wilkinson@xyratex.com
> Tel: +44 (0)2392 6225
> Mobile: +44 (0)7810 497152
> -----Original Message-----
> From: Sagara Gunathunga [mailto:sagara.gunathunga@gmail.com]
> Sent: 23 September 2009 09:41
> To: axis-user@ws.apache.org
> Subject: Re: persistance using POJO's
>
> This is also possible by implementing ServiceLifeCycle interface [1],
> it contains two methods called startUp (..) and shutDown(..) that can
> be used to open db connection at service deployment time  and close at
> db connection at system shut down time.
>
> So you can use  startUp (..) method to open the db connection and set
> it as a parameter in AxisService.
>
> Once you have a implementation class you can define it using "class"
> attribute on service.xml file as follows .
>
>
> <service   name="MyServiceName"
>                 class="MyServiceLifeCycleImpl" >
>
>
>
> [1] - http://ws.apache.org/axis2/1_4_1/api/org/apache/axis2/engine/ServiceLifeCycle.html
>
> Thanks,
>
>
> On Wed, Sep 23, 2009 at 1:48 PM, Upul Godage <up...@gmail.com> wrote:
>> Hi,
>>
>> You should use a database connection pooling of some sort.
>>
>> http://onjava.com/pub/a/onjava/2006/04/19/database-connection-pooling-with-tomcat.html
>>
>> Upul
>>
>> On Wed, Sep 23, 2009 at 1:41 PM, John Wilkinson
>> <Jo...@xyratex.com> wrote:
>>> Hi,
>>>
>>> I wish to have my service persist POJO's to a postgresql database.
>>>
>>>
>>>
>>>  Every time I call a service, do I need to connect to a database, and then
>>> at the end close the connection. Or is there a way to open the connection
>>> when the service is first called, and then close when I stop using the
>>> service, say by a method call?
>>>
>>>
>>>
>>>
>>>
>>> Many regards,
>>>
>>> John.
>>>
>>>
>>>
>>>
>>>
>>> ______________________________________________________________________
>>> This email may contain privileged or confidential information, which should
>>> only be used for the purpose for which it was sent by Xyratex. No further
>>> rights or licenses are granted to use such information. If you are not the
>>> intended recipient of this message, please notify the sender by return and
>>> delete it. You may not use, copy, disclose or rely on the information
>>> contained in it.
>>>
>>> Internet email is susceptible to data corruption, interception and
>>> unauthorised amendment for which Xyratex does not accept liability. While we
>>> have taken reasonable precautions to ensure that this email is free of
>>> viruses, Xyratex does not accept liability for the presence of any computer
>>> viruses in this email, nor for any losses caused as a result of viruses.
>>>
>>> Xyratex Technology Limited (03134912), Registered in England & Wales,
>>> Registered Office, Langstone Road, Havant, Hampshire, PO9 1SA.
>>>
>>> The Xyratex group of companies also includes, Xyratex Ltd, registered in
>>> Bermuda, Xyratex International Inc, registered in California, Xyratex
>>> (Malaysia) Sdn Bhd registered in Malaysia, Xyratex Technology (Wuxi) Co Ltd
>>> registered in The People's Republic of China and Xyratex Japan Limited
>>> registered in Japan.
>>> ______________________________________________________________________
>>>
>>
>>
>>
>> --
>> http://upulgodage.com
>>
>
>
>
> --
> Sagara Gunathunga
>
> Blog - http://ssagara.blogspot.com
> Web - http://people.apache.org/~sagara/
>
> ______________________________________________________________________
> This email may contain privileged or confidential information, which should only be used for the purpose for which it was sent by Xyratex. No further rights or licenses are granted to use such information. If you are not the intended recipient of this message, please notify the sender by return and delete it. You may not use, copy, disclose or rely on the information contained in it.
>
> Internet email is susceptible to data corruption, interception and unauthorised amendment for which Xyratex does not accept liability. While we have taken reasonable precautions to ensure that this email is free of viruses, Xyratex does not accept liability for the presence of any computer viruses in this email, nor for any losses caused as a result of viruses.
>
> Xyratex Technology Limited (03134912), Registered in England & Wales, Registered Office, Langstone Road, Havant, Hampshire, PO9 1SA.
>
> The Xyratex group of companies also includes, Xyratex Ltd, registered in Bermuda, Xyratex International Inc, registered in California, Xyratex (Malaysia) Sdn Bhd registered in Malaysia, Xyratex Technology (Wuxi) Co Ltd registered in The People's Republic of China and Xyratex Japan Limited registered in Japan.
> ______________________________________________________________________
>



-- 
Sagara Gunathunga

Blog - http://ssagara.blogspot.com
Web - http://people.apache.org/~sagara/

______________________________________________________________________
This email may contain privileged or confidential information, which should only be used for the purpose for which it was sent by Xyratex. No further rights or licenses are granted to use such information. If you are not the intended recipient of this message, please notify the sender by return and delete it. You may not use, copy, disclose or rely on the information contained in it.

Internet email is susceptible to data corruption, interception and unauthorised amendment for which Xyratex does not accept liability. While we have taken reasonable precautions to ensure that this email is free of viruses, Xyratex does not accept liability for the presence of any computer viruses in this email, nor for any losses caused as a result of viruses.

Xyratex Technology Limited (03134912), Registered in England & Wales, Registered Office, Langstone Road, Havant, Hampshire, PO9 1SA.

The Xyratex group of companies also includes, Xyratex Ltd, registered in Bermuda, Xyratex International Inc, registered in California, Xyratex (Malaysia) Sdn Bhd registered in Malaysia, Xyratex Technology (Wuxi) Co Ltd registered in The People's Republic of China and Xyratex Japan Limited registered in Japan.
______________________________________________________________________

Re: persistance using POJO's

Posted by Sagara Gunathunga <sa...@gmail.com>.
Hi John,

Can you try for this ...

In your ServiceLifeCycle implementation class open and close the db
connection as follows.

Class MyServiceLifeCycle implements ServiceLifeCycle  {

	public void startUp(ConfigurationContext arg0, AxisService service) {

           Connection conn=null;
          // Open the DB connection as usual.

         //set Connection object as a Parameter
         service.addParameter("dbConnection", conn);	
		
	}



      public void shutDown(ConfigurationContext arg0, AxisService service) {
		
           //get DB Connection from the service
           Connection conn=(Connection)service.getParameter("dbConnection");

         //close the  DB Connection
        ......................................		
	}
}




Then in your web service method you can access to above  DB Connection
as follows .

public XXXX myServiceMethod(){


// get DB Connection
AxisService service=MessageContext.getCurrentMessageContext().getAxisService();
Connection conn=(Connection)service.getParameter("dbConnection");


}


HTH


Thanks ,



On Wed, Sep 23, 2009 at 4:25 PM, John Wilkinson
<Jo...@xyratex.com> wrote:
> Thank you Sagara,
> If I implement the ServiceLifeCycle interface, can you give me a simple example of how I would access the connection from a POJO, and how the startup method saves the connection to a parameter, please.
>
> Many regards,
> John.
>
> John Wilkinson.
> Product Engineer.
> ----x-y-r-a-t-e-x----
> e-mail: john_wilkinson@xyratex.com
> Tel: +44 (0)2392 6225
> Mobile: +44 (0)7810 497152
> -----Original Message-----
> From: Sagara Gunathunga [mailto:sagara.gunathunga@gmail.com]
> Sent: 23 September 2009 09:41
> To: axis-user@ws.apache.org
> Subject: Re: persistance using POJO's
>
> This is also possible by implementing ServiceLifeCycle interface [1],
> it contains two methods called startUp (..) and shutDown(..) that can
> be used to open db connection at service deployment time  and close at
> db connection at system shut down time.
>
> So you can use  startUp (..) method to open the db connection and set
> it as a parameter in AxisService.
>
> Once you have a implementation class you can define it using "class"
> attribute on service.xml file as follows .
>
>
> <service   name="MyServiceName"
>                 class="MyServiceLifeCycleImpl" >
>
>
>
> [1] - http://ws.apache.org/axis2/1_4_1/api/org/apache/axis2/engine/ServiceLifeCycle.html
>
> Thanks,
>
>
> On Wed, Sep 23, 2009 at 1:48 PM, Upul Godage <up...@gmail.com> wrote:
>> Hi,
>>
>> You should use a database connection pooling of some sort.
>>
>> http://onjava.com/pub/a/onjava/2006/04/19/database-connection-pooling-with-tomcat.html
>>
>> Upul
>>
>> On Wed, Sep 23, 2009 at 1:41 PM, John Wilkinson
>> <Jo...@xyratex.com> wrote:
>>> Hi,
>>>
>>> I wish to have my service persist POJO's to a postgresql database.
>>>
>>>
>>>
>>>  Every time I call a service, do I need to connect to a database, and then
>>> at the end close the connection. Or is there a way to open the connection
>>> when the service is first called, and then close when I stop using the
>>> service, say by a method call?
>>>
>>>
>>>
>>>
>>>
>>> Many regards,
>>>
>>> John.
>>>
>>>
>>>
>>>
>>>
>>> ______________________________________________________________________
>>> This email may contain privileged or confidential information, which should
>>> only be used for the purpose for which it was sent by Xyratex. No further
>>> rights or licenses are granted to use such information. If you are not the
>>> intended recipient of this message, please notify the sender by return and
>>> delete it. You may not use, copy, disclose or rely on the information
>>> contained in it.
>>>
>>> Internet email is susceptible to data corruption, interception and
>>> unauthorised amendment for which Xyratex does not accept liability. While we
>>> have taken reasonable precautions to ensure that this email is free of
>>> viruses, Xyratex does not accept liability for the presence of any computer
>>> viruses in this email, nor for any losses caused as a result of viruses.
>>>
>>> Xyratex Technology Limited (03134912), Registered in England & Wales,
>>> Registered Office, Langstone Road, Havant, Hampshire, PO9 1SA.
>>>
>>> The Xyratex group of companies also includes, Xyratex Ltd, registered in
>>> Bermuda, Xyratex International Inc, registered in California, Xyratex
>>> (Malaysia) Sdn Bhd registered in Malaysia, Xyratex Technology (Wuxi) Co Ltd
>>> registered in The People's Republic of China and Xyratex Japan Limited
>>> registered in Japan.
>>> ______________________________________________________________________
>>>
>>
>>
>>
>> --
>> http://upulgodage.com
>>
>
>
>
> --
> Sagara Gunathunga
>
> Blog - http://ssagara.blogspot.com
> Web - http://people.apache.org/~sagara/
>
> ______________________________________________________________________
> This email may contain privileged or confidential information, which should only be used for the purpose for which it was sent by Xyratex. No further rights or licenses are granted to use such information. If you are not the intended recipient of this message, please notify the sender by return and delete it. You may not use, copy, disclose or rely on the information contained in it.
>
> Internet email is susceptible to data corruption, interception and unauthorised amendment for which Xyratex does not accept liability. While we have taken reasonable precautions to ensure that this email is free of viruses, Xyratex does not accept liability for the presence of any computer viruses in this email, nor for any losses caused as a result of viruses.
>
> Xyratex Technology Limited (03134912), Registered in England & Wales, Registered Office, Langstone Road, Havant, Hampshire, PO9 1SA.
>
> The Xyratex group of companies also includes, Xyratex Ltd, registered in Bermuda, Xyratex International Inc, registered in California, Xyratex (Malaysia) Sdn Bhd registered in Malaysia, Xyratex Technology (Wuxi) Co Ltd registered in The People's Republic of China and Xyratex Japan Limited registered in Japan.
> ______________________________________________________________________
>



-- 
Sagara Gunathunga

Blog - http://ssagara.blogspot.com
Web - http://people.apache.org/~sagara/

RE: persistance using POJO's

Posted by John Wilkinson <Jo...@xyratex.com>.
Thank you Sagara,
If I implement the ServiceLifeCycle interface, can you give me a simple example of how I would access the connection from a POJO, and how the startup method saves the connection to a parameter, please.

Many regards,
John.
 
John Wilkinson.
Product Engineer.
----x-y-r-a-t-e-x----
e-mail: john_wilkinson@xyratex.com
Tel: +44 (0)2392 6225
Mobile: +44 (0)7810 497152
-----Original Message-----
From: Sagara Gunathunga [mailto:sagara.gunathunga@gmail.com] 
Sent: 23 September 2009 09:41
To: axis-user@ws.apache.org
Subject: Re: persistance using POJO's

This is also possible by implementing ServiceLifeCycle interface [1],
it contains two methods called startUp (..) and shutDown(..) that can
be used to open db connection at service deployment time  and close at
db connection at system shut down time.

So you can use  startUp (..) method to open the db connection and set
it as a parameter in AxisService.

Once you have a implementation class you can define it using "class"
attribute on service.xml file as follows .


<service   name="MyServiceName"
                 class="MyServiceLifeCycleImpl" >



[1] - http://ws.apache.org/axis2/1_4_1/api/org/apache/axis2/engine/ServiceLifeCycle.html

Thanks,


On Wed, Sep 23, 2009 at 1:48 PM, Upul Godage <up...@gmail.com> wrote:
> Hi,
>
> You should use a database connection pooling of some sort.
>
> http://onjava.com/pub/a/onjava/2006/04/19/database-connection-pooling-with-tomcat.html
>
> Upul
>
> On Wed, Sep 23, 2009 at 1:41 PM, John Wilkinson
> <Jo...@xyratex.com> wrote:
>> Hi,
>>
>> I wish to have my service persist POJO's to a postgresql database.
>>
>>
>>
>>  Every time I call a service, do I need to connect to a database, and then
>> at the end close the connection. Or is there a way to open the connection
>> when the service is first called, and then close when I stop using the
>> service, say by a method call?
>>
>>
>>
>>
>>
>> Many regards,
>>
>> John.
>>
>>
>>
>>
>>
>> ______________________________________________________________________
>> This email may contain privileged or confidential information, which should
>> only be used for the purpose for which it was sent by Xyratex. No further
>> rights or licenses are granted to use such information. If you are not the
>> intended recipient of this message, please notify the sender by return and
>> delete it. You may not use, copy, disclose or rely on the information
>> contained in it.
>>
>> Internet email is susceptible to data corruption, interception and
>> unauthorised amendment for which Xyratex does not accept liability. While we
>> have taken reasonable precautions to ensure that this email is free of
>> viruses, Xyratex does not accept liability for the presence of any computer
>> viruses in this email, nor for any losses caused as a result of viruses.
>>
>> Xyratex Technology Limited (03134912), Registered in England & Wales,
>> Registered Office, Langstone Road, Havant, Hampshire, PO9 1SA.
>>
>> The Xyratex group of companies also includes, Xyratex Ltd, registered in
>> Bermuda, Xyratex International Inc, registered in California, Xyratex
>> (Malaysia) Sdn Bhd registered in Malaysia, Xyratex Technology (Wuxi) Co Ltd
>> registered in The People's Republic of China and Xyratex Japan Limited
>> registered in Japan.
>> ______________________________________________________________________
>>
>
>
>
> --
> http://upulgodage.com
>



-- 
Sagara Gunathunga

Blog - http://ssagara.blogspot.com
Web - http://people.apache.org/~sagara/

______________________________________________________________________
This email may contain privileged or confidential information, which should only be used for the purpose for which it was sent by Xyratex. No further rights or licenses are granted to use such information. If you are not the intended recipient of this message, please notify the sender by return and delete it. You may not use, copy, disclose or rely on the information contained in it.

Internet email is susceptible to data corruption, interception and unauthorised amendment for which Xyratex does not accept liability. While we have taken reasonable precautions to ensure that this email is free of viruses, Xyratex does not accept liability for the presence of any computer viruses in this email, nor for any losses caused as a result of viruses.

Xyratex Technology Limited (03134912), Registered in England & Wales, Registered Office, Langstone Road, Havant, Hampshire, PO9 1SA.

The Xyratex group of companies also includes, Xyratex Ltd, registered in Bermuda, Xyratex International Inc, registered in California, Xyratex (Malaysia) Sdn Bhd registered in Malaysia, Xyratex Technology (Wuxi) Co Ltd registered in The People's Republic of China and Xyratex Japan Limited registered in Japan.
______________________________________________________________________

Re: persistance using POJO's

Posted by Sagara Gunathunga <sa...@gmail.com>.
This is also possible by implementing ServiceLifeCycle interface [1],
it contains two methods called startUp (..) and shutDown(..) that can
be used to open db connection at service deployment time  and close at
db connection at system shut down time.

So you can use  startUp (..) method to open the db connection and set
it as a parameter in AxisService.

Once you have a implementation class you can define it using "class"
attribute on service.xml file as follows .


<service   name="MyServiceName"
                 class="MyServiceLifeCycleImpl" >



[1] - http://ws.apache.org/axis2/1_4_1/api/org/apache/axis2/engine/ServiceLifeCycle.html

Thanks,


On Wed, Sep 23, 2009 at 1:48 PM, Upul Godage <up...@gmail.com> wrote:
> Hi,
>
> You should use a database connection pooling of some sort.
>
> http://onjava.com/pub/a/onjava/2006/04/19/database-connection-pooling-with-tomcat.html
>
> Upul
>
> On Wed, Sep 23, 2009 at 1:41 PM, John Wilkinson
> <Jo...@xyratex.com> wrote:
>> Hi,
>>
>> I wish to have my service persist POJO’s to a postgresql database.
>>
>>
>>
>>  Every time I call a service, do I need to connect to a database, and then
>> at the end close the connection. Or is there a way to open the connection
>> when the service is first called, and then close when I stop using the
>> service, say by a method call?
>>
>>
>>
>>
>>
>> Many regards,
>>
>> John.
>>
>>
>>
>>
>>
>> ______________________________________________________________________
>> This email may contain privileged or confidential information, which should
>> only be used for the purpose for which it was sent by Xyratex. No further
>> rights or licenses are granted to use such information. If you are not the
>> intended recipient of this message, please notify the sender by return and
>> delete it. You may not use, copy, disclose or rely on the information
>> contained in it.
>>
>> Internet email is susceptible to data corruption, interception and
>> unauthorised amendment for which Xyratex does not accept liability. While we
>> have taken reasonable precautions to ensure that this email is free of
>> viruses, Xyratex does not accept liability for the presence of any computer
>> viruses in this email, nor for any losses caused as a result of viruses.
>>
>> Xyratex Technology Limited (03134912), Registered in England & Wales,
>> Registered Office, Langstone Road, Havant, Hampshire, PO9 1SA.
>>
>> The Xyratex group of companies also includes, Xyratex Ltd, registered in
>> Bermuda, Xyratex International Inc, registered in California, Xyratex
>> (Malaysia) Sdn Bhd registered in Malaysia, Xyratex Technology (Wuxi) Co Ltd
>> registered in The People's Republic of China and Xyratex Japan Limited
>> registered in Japan.
>> ______________________________________________________________________
>>
>
>
>
> --
> http://upulgodage.com
>



-- 
Sagara Gunathunga

Blog - http://ssagara.blogspot.com
Web - http://people.apache.org/~sagara/

Re: persistance using POJO's

Posted by Upul Godage <up...@gmail.com>.
Hi,

You should use a database connection pooling of some sort.

http://onjava.com/pub/a/onjava/2006/04/19/database-connection-pooling-with-tomcat.html

Upul

On Wed, Sep 23, 2009 at 1:41 PM, John Wilkinson
<Jo...@xyratex.com> wrote:
> Hi,
>
> I wish to have my service persist POJO’s to a postgresql database.
>
>
>
>  Every time I call a service, do I need to connect to a database, and then
> at the end close the connection. Or is there a way to open the connection
> when the service is first called, and then close when I stop using the
> service, say by a method call?
>
>
>
>
>
> Many regards,
>
> John.
>
>
>
>
>
> ______________________________________________________________________
> This email may contain privileged or confidential information, which should
> only be used for the purpose for which it was sent by Xyratex. No further
> rights or licenses are granted to use such information. If you are not the
> intended recipient of this message, please notify the sender by return and
> delete it. You may not use, copy, disclose or rely on the information
> contained in it.
>
> Internet email is susceptible to data corruption, interception and
> unauthorised amendment for which Xyratex does not accept liability. While we
> have taken reasonable precautions to ensure that this email is free of
> viruses, Xyratex does not accept liability for the presence of any computer
> viruses in this email, nor for any losses caused as a result of viruses.
>
> Xyratex Technology Limited (03134912), Registered in England & Wales,
> Registered Office, Langstone Road, Havant, Hampshire, PO9 1SA.
>
> The Xyratex group of companies also includes, Xyratex Ltd, registered in
> Bermuda, Xyratex International Inc, registered in California, Xyratex
> (Malaysia) Sdn Bhd registered in Malaysia, Xyratex Technology (Wuxi) Co Ltd
> registered in The People's Republic of China and Xyratex Japan Limited
> registered in Japan.
> ______________________________________________________________________
>



-- 
http://upulgodage.com