SimpleNamingContextBuilder

Simple implementation of a JNDI naming context builder.

Mainly targeted at test environments, where each test case can configure JNDI appropriately, so that new InitialContext() will expose the required objects. Also usable for standalone applications, e.g. for binding a JDBC DataSource to a well-known JNDI location, to be able to use traditional J2EE data access code outside of a J2EE container.

There are various choices for DataSource implementations:

  • SingleConnectionDataSource (using the same Connection for all getConnection calls);
  • DriverManagerDataSource (creating a new Connection on each getConnection call);
  • Apache's Jakarta Commons DBCP offers BasicDataSource (a real pool).

Typical usage in bootstrap code:

 SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder();
 DataSource ds = new DriverManagerDataSource(...);
 builder.bind("java:comp/env/jdbc/myds", ds);
 builder.activate();
Note that it's impossible to activate multiple builders within the same JVM, due to JNDI restrictions. Thus to configure a fresh builder repeatedly, use the following code to get a reference to either an already activated builder or a newly activated one:
 SimpleNamingContextBuilder builder = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
 DataSource ds = new DriverManagerDataSource(...);
 builder.bind("java:comp/env/jdbc/myds", ds);
Note that you should not call activate() on a builder from this factory method, as there will already be an activated one in any case.

An instance of this class is only necessary at setup time. An application does not need to keep a reference to it after activation.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值