tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Blevins <david.blev...@visi.com>
Subject Re: Inspect database when using embedded OpenEJB
Date Tue, 21 Oct 2008 00:55:28 GMT

On Oct 20, 2008, at 8:11 AM, Bernhard Humm wrote:

>
> Dear all,
>
> when using OpenEJB embedded in JUnit tests are entity beans actually  
> being
> persisted to disk?
> Is there a way of inspecting the database content after execution of  
> the
> JUnit tests?
> I am using NetBeans IDE. Can I use the built-in database viewer to  
> connect
> to the database? How do I specify the connect parameters?

In OpenEJB 3.0, when using the supplied HSQL datasource in a TestCase  
we should be using an in memory database with the JdbcUrl of  
"jdbc:hsqldb:mem:hsqldb".  In OpenEJB 3.0 that sometimes worked and  
sometimes didn't (depending on if you had a conf/ directory in your  
openejb.base path), in which case the files were written to disk and  
the JdbcUrl ended up as "jdbc:hsqldb:file:data/hsqldb/hsqldb" which  
would be relative to your openejb.base path as in "${openejb.base}/ 
data/hsqldb/hsqldb".

In OpenEJB 3.1 we have a better way of detecting when we are running  
embedded and the JdbcUrl will always be "jdbc:hsqldb:mem:hsqldb"  
unless explicitly changed.

You should be able to use the NetBeans IDE tooling to connect to the  
database of the file based HSQLDB, in which case I recommend you  
explicitly supply the absolute path of the database files in your  
JdbcUrl and explicitly supply all data source parameters to both  
OpenEJB an NetBeans to ensure that they are the same.

Here might be some good values for both:

     JdbcDriver  org.hsqldb.jdbcDriver
     JdbcUrl     jdbc:hsqldb:file:/tmp/testing/data/hsqldb/hsqldb
     UserName    sa
     Password

On the OpenEJB side when embedding, you can explicitly declare a  
datasource and all parameters right in the test case as follows:

     Properties p = new Properties();
     p.put(Context.INITIAL_CONTEXT_FACTORY,  
"org.apache.openejb.client.LocalInitialContextFactory");
     p.put("movieDatabase", "new://Resource?type=DataSource");
     p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver");
     p.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:file:/tmp/testing/ 
data/hsqldb/hsqldb");
     p.put("movieDatabase.UserName", "sa");
     p.put("movieDatabase.Password", "");
     InitialContext context = new InitialContext(p);

Not sure how the data is supplied to NetBeans IDE.

Note that I don't think HSQLDB will allow more than one VM to be  
connected to the database files at one time, so be ready to get some  
exceptions if you attempt to use both simultaneously.  If that becomes  
a pain, you can set HSQLDB up as a standalone database as per the  
documentation on their side rather than using it as an embedded  
database.  You would just need to adjust your JdbcUrl accordingly in  
both OpenEJB and NetBeans.

-David


Mime
View raw message