tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Quintin Beukes <quin...@skywalk.co.za>
Subject Re: Closing the hsql corrrectly
Date Sat, 24 Oct 2009 12:29:56 GMT
Technically not, but it's the cleaner solution IMO. You want the
shutdown to occur only once. Since stateless beans are in pools
@PreDestroy will be called more than once. So for a stateless bean you
would need some static variable and synchronization to control this.
With a Singleton, all these things are unnecessary.

Quintin Beukes



On Sat, Oct 24, 2009 at 8:12 AM, hypnosat7 <ablarbi@yahoo.fr> wrote:
>
> Is it necessary to have a Singleton ?
>
> Christian Bourque wrote:
>>
>> Hi,
>>
>> Here's my solution to do a clean shutdown of HSQL when using the file
>> version, I've used the experimental singleton feature of EJB 3.1 to do
>> that
>> but since it is only for testing I don't mind:
>>
>> -------------------------------------------------------------------------------------------------------------------
>> @Singleton
>> @Startup
>> public class DatabaseBean implements Database
>> {
>>     @Resource
>>     private DataSource testDataSource;
>>
>>     @PreDestroy
>>     public void shutdown()
>>     {
>>         BasicManagedDataSource basicManagedDataSource =
>> (BasicManagedDataSource) testDataSource;
>>
>>         if
>> (basicManagedDataSource.getJdbcDriver().equals("org.hsqldb.jdbcDriver"))
>>         {
>>             try
>>             {
>>                 // this is a hack to do a clean shutdown of hsqldb...
>>
>> testDataSource.getConnection().createStatement().execute("SHUTDOWN");
>>             }
>>             catch (Exception e)
>>             {
>>                 e.printStackTrace();
>>             }
>>         }
>>     }
>> }
>> -------------------------------------------------------------------------------------------------------------------
>>
>> Don't forget to change the the datasource name...
>>
>> Hope this helps!
>>
>> Christian
>>
>> On Fri, Oct 23, 2009 at 2:11 AM, hypnosat7 <ablarbi@yahoo.fr> wrote:
>>
>>>
>>> Hello,
>>>
>>>  How can I close my hsql at the end of unit test, because my database is
>>> not closed at the end of the test: the entry 'modified' is set to 'yes'
>>> in
>>> the myHsqlDatabase.properties (http://hsqldb.org/doc/guide/apc.html) ?
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Closing-the-hsql-corrrectly-tp26021361p26021361.html
>>> Sent from the OpenEJB User mailing list archive at Nabble.com.
>>>
>>>
>>
>>
>
> --
> View this message in context: http://www.nabble.com/Closing-the-hsql-corrrectly-tp26021361p26036443.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>
>

Mime
View raw message