Home | License | API Docs
Summary | Download
ShiftOne

ShiftOne OOC JNDI

What is OOC?
What's the point?
How does it help me configure my J2SE application?
How does it help me unit test?
How do I use OOC from my application code?
How do I set this thing up?
Does OOC do database connection pooling?
What if I don't want to pool with c3p0?
Do you have some configuration examples?

What is OOC?

OOC stands for Out of Context. It is a small, simple, in-process naming provider. It also includes a component that initializes the Context based on an XML descriptor (optional).

What's the point?

OOC was built for two reasons. First, it was built to provide environment configuration support to J2SE stand-alone applications. Second, it was built to facilitate unit testing

How does it help me configure my J2SE application?

In J2EE applications, JNDI provides a very nice layer of abstraction between application code, and environment configuration. Using this approach removes the need to either hardcode environment settings, or implement a way to externalize them. In addition, many component vendors provide an implementation of the ObjectFactory interface, a configurable factory. OOC supports ObjectFactorys, and allows them to be installed and initialized based on an XML descriptor. J2EE or J2SE? JNDI works with both

How does it help me unit test?

Well, Java applications that use JDBC, JMS, JavaMail, etc. typically obtain instances of configurable factories (such as a DataSource) from JNDI. OOC makes it possible, in some cases, to test components of an application without loading it into an application server. This is not to say that OOC simulates a full J2EE environment for testing, but it simulates part of it.

How do I use OOC from my application code?

OOC is used in the same way any other JNDI compliant naming services is used. This means code that is developed agains OOC can be easily ported into a J2EE environment. First an InitialContext object is instaniated, which is then used to lookup other resources.
Context    ctx     = new InitialContext();
DataSource ds      = (DataSource)ctx.lookup("java:comp/env/jdbc/myDB");
Connection connect = ds.getConnection();

How do I set this thing up?

Setup requires three things. Add the needed JAR files to your applications classpath. These include the ooc-jndi JAR as the JARs included in the lib directory of this distribution (such as log4j, jndi, and a SAX parser). Add your ooc-jndi.xml configuration file to you application classpath or current working directory - (the latter is default) Set the system property java.naming.factory.initial to org.shiftone.ooc.InitialContextFactory. This can be done from the command line, or from withing your Java code (I tend to do it in the static initializer of my unit test classes).

Does OOC do database connection pooling?

It used to, but now it uses c3p0 to. c3p0 is a mature pooling implementation. There is a OOC provided ObjectFactory that will use c3p0 to pool connection.

see: org.shiftone.ooc.factory.PooledDataSourceObjectFactory

What if I don't want to pool with c3p0?

Use the Jakarta Commons DBCP.

see: org.apache.commons.dbcp.jdbc2pool.Jdbc2PoolDataSource

Do you have some configuration examples?

Sure. Here is a sample config file. Also, references can be configured to use various 3rd party drivers. Here are some example references.

ShiftOne OOC JNDI 1.3

SourceForge.net Logo
page regenerated
© Jeff Drost