By calling "close()" on the initial context that bootstrapped the container. You have to set this property on the initial context though :
properties.setProperty("openejb.embedded.initialcontext.close", "DESTROY"); Christian On Fri, Oct 23, 2009 at 5:01 PM, Quintin Beukes <quin...@skywalk.co.za>wrote: > Yes, that clears it up. If you don't mind me asking another question, > how do you shut down the container in @AfterClass? > > Quintin Beukes > > > > On Fri, Oct 23, 2009 at 10:31 PM, Christian Bourque > <christian.bour...@gmail.com> wrote: > > Hey, > > > > Well in my case the container is started before tests are run and stopped > > after all tests have been executed (using @BeforeClass and @AfterClass). > > > > Of course you don't want to shut it down after every test because the > > database would be overridden each time... > > > > If you have multiple test classes I guess you could apply the same > technique > > using a test suite... > > > > Hope this helps... > > > > Christian > > > > On Fri, Oct 23, 2009 at 3:29 PM, Quintin Beukes <quin...@skywalk.co.za > >wrote: > > > >> Hey, > >> > >> You want to do a shutdown after each test? Is that after every literal > >> test (every test method) or after every unit test (test class)? > >> > >> If I understand your code correctly, this will only work if a new > >> OpenEJB instance is started, meaning the VM is closed and reopened, or > >> you do it manually. Or am I wrong with this? > >> > >> Could you perhaps explain a bit more about how your code works, > >> because a Singleton's @PreDestroy will only be called when the > >> Singleton gets destroyed, which only happens when the Container gets > >> destroyed, which in turn closes with OpenEJB. > >> > >> Quintin Beukes > >> > >> > >> > >> On Fri, Oct 23, 2009 at 8:01 PM, Christian Bourque > >> <christian.bour...@gmail.com> 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 <abla...@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. > >> >> > >> >> > >> > > >> > > >