On Dec 9, 2009, at 5:54 PM, dhartfrd wrote:
I'm trying to use openejb for unit testing with dbunit, but having
some
issues making it 'easy/clean' --
private Context ctx;
private String datasourceName = "jdbc/MyDS";
public void setUp() throws Exception {
Properties props = new Properties();
props.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.LocalInitialContextFactory");
props.put(datasourceName, "new://Resource?type=DataSource");
props.put(datasourceName + ".JtaManaged", "false");
props.put(datasourceName + ".JdbcDriver", "org.h2.Driver");
props.put(datasourceName + ".JdbcUrl","jdbc:h2:mem:testdb");
ctx = new InitialContext(props);
IDatabaseConnection connection = new
DatabaseDataSourceConnection((InitialContext) ctx, datasourceName);
}
Try one of these:
IDatabaseConnection connection = new
DatabaseDataSourceConnection((InitialContext) ctx, "openejb:Resource/"
+ datasourceName);
or
IDatabaseConnection connection = new
DatabaseDataSourceConnection((InitialContext) ctx, "java:openejb/
Resource/" + datasourceName);
The first one is preferred as the second one will not work in Tomcat.
Fortunately in Java EE 6 this is one of those things that is finally
being made standard, so there will be a standard "java:global/"
namespace where resources, ejbs, etc will all have predictable and
portable names.
Hope this helps!
-David