Generating Look Up or Binding Code
The following code was generated by the JNDI Module to bind an object (a PersistenceManagerFactory) in an LDAP Directory Service running on the local host at port 389.
/** Inserted by Jndi module */To complete this code you need to specify a name and object:
java.util.Properties jndiProperties = new java.util.Properties();
jndiProperties.put("java.naming.provider.url","ldap://localhost:389/o=forte4java.com");
jndiProperties.put("java.naming.factory.initial","com.sun.jndi.ldap.LdapCtxFactory");
try {
javax.naming.directory.DirContext jndiCtx = new javax.naming.directory.InitialDirContext(jndiProperties);
javax.naming.Context jndiObject = (javax.naming.Context)jndiCtx.lookup("");
jndiObject.bind("<Name>",<Object>);
} catch (javax.naming.NamingException ne) {
ne.printStackTrace();
}
/** Inserted by Jndi module */The object is bound under the name "pmf_for_oracle."
java.util.Properties jndiProperties = new java.util.Properties();
jndiProperties.put("java.naming.provider.url","ldap://localhost:389/o=forte4java.com");
jndiProperties.put("java.naming.factory.initial","com.sun.jndi.ldap.LdapCtxFactory");
try {
// Create a PersistenceManagerFactory: (// dixie::1521, db name ORCL)
PersistenceManagerFactory pmf = new PersistenceManagerFactoryImpl();
pmf.setConnectionUserName("scott");
pmf.setConnectionPassword("tiger");
pmf.setConnectionDriverName("oracle.jdbc.driver.OracleDriver");
pmf.setConnectionURL("jdbc:oracle:thin:@dixie:1521:ORCL");
pmf.setOptimistic(true); //it is false by defaultjavax.naming.directory.DirContext jndiCtx = new javax.naming.directory.InitialDirContext(jndiProperties);
javax.naming.Context jndiObject = (javax.naming.Context)jndiCtx.lookup("");
jndiObject.bind("cn=pmf_for_oracle", pmf);
} catch (javax.naming.NamingException ne) {
ne.printStackTrace();
}
Example of Look Up Code
The following code was generated by the JNDI Module to look up an the object that was bound by the previous example:
/** Inserted by Jndi module */
java.util.Properties jndiProperties = new java.util.Properties();
jndiProperties.put("java.naming.provider.url","ldap://localhost:389/o=forte4java.com");
jndiProperties.put("java.naming.factory.initial","com.sun.jndi.ldap.LdapCtxFactory");
try {
javax.naming.directory.DirContext jndiCtx = new javax.naming.directory.InitialDirContext(jndiProperties);
com.sun.forte4j.persistence.PersistenceManagerFactoryImpl jndiObject = (com.sun.forte4j.persistence.PersistenceManagerFactoryImpl)jndiCtx.lookup("cn=pmf_for_oracle");
} catch (javax.naming.NamingException ne) {
ne.printStackTrace();
}