Connection factories are obtained from JNDI in the usual way. The resource adaptor, when it is deployed, is stored in JNDI under a name that is specified during deployment. The JDO vendor usually provides a default name. Getting the name right is the only hard part. The code, shown in Listing 6-5, is straightforward. After getting a connection factory, the application obtains a persistence manager as shown in Listing 6-1.
Listing 6-5: Finding a ConnectionFactory in JNDI
String cfName = "someName"; // examples: "java:/kodo", "java:comp/env/eis/MyJDO" ConnectionFactory cf = null; try { cf = (ConnectionFactory) new InitialContext().lookup(cfName); } catch (NamingException ne) { // handle exception ... }