Writing a Client that Calls Exported Methods

You call the exported methods from a Java client program. The Java client program follows the coding pattern for EJBs and typically follows this outline:

  1. Set up initial environment.

  2. Call an initial context.

  3. Look up the factory for the generic Application Module.

  4. Call create() to get the Application Module instance. Cast the instance to the custom Application Module.

At this point, you can call any of the exported Application Module methods.

  1. Call findViewObject() or createViewObject() on the generic Application Module to either find or create the View Object, then cast it to your custom View Object interface.

At this point, you can call any of the exported View Object or View Object Row methods. For example, call one of the View Object methods that return a row (you might call next() or first(), for example) and cast it to your custom View Row interface.

  1. Commit changes to the application tier.

  2. Disconnect from the application tier.

For more information on writing Java clients, see Programming the Client Interface.

The following example program creates an instance of the generic HrAppmodule Application Module, gets a reference to the Application Module's DeptRow View Row, casts it to the DeptRow interface, and calls the exported accessor method getDeptRow().

package package4.client.vb;
import java.util.*;
import javax.naming.*;
import oracle.jbo.*;
import oracle.jbo.JboContext;
public class HRClient
{
public void test()
{
try
{
// set up the initial environment
Hashtable env = new Hashtable(10);
env.put(Context.INITIAL_CONTEXT_FACTORY,
JboContext.JBO_CONTEXT_FACTORY);
env.put(JboContext.DEPLOY_PLATFORM, JboContext.PLATFORM_VB);
env.put(JboContext.CONNECTION_MODE, new
Integer(ConnectionModeConstants.USE_BIND));
       // call the initial context
Context ic = new InitialContext(env);
       // look up factory for the generic application module
ApplicationModuleHome home = (ApplicationModuleHome)
ic.lookup("package4.HrAppmodule");
       // Call create() to get the application module instance; 
// cast it to the custom application module
ApplicationModule am = home.create();
       hrAm.getTransaction().connect("jdbc:oracle:thin:scott/tiger@user-pc3:1521:ORA815");
 // --Use an exported Application Module method--
// Call the exported Application Module method
hrAm.promoteAllEmps();
       // Get a reference to the View Object - Cast it to the custom  
// view object interface containing the exported method
ViewObject deptView = am.findViewObject("DeptView");
 // --Use an exported View Object method--
// Call the exported View Object method
empView.promote();
       // --Use an exported View Object Row method--
// Call one of the View Object methods that return a row
Row row;
while ((row = deptView.next()) != null)
{
// Cast the row to the view row interface
// and call the exported accessor method on the row
DeptViewRow deptRow = (DeptViewRow) row
System.out.println("DEPTNO :"+deptRow.getDeptno());
}
       // disconnect from the database
am.getTransaction().disconnect();
am.remove();
}
     catch(NamingException ne)
{
System.out.println("Unable to find application package4.HrAppmodule");
ne.printStackTrace();
}
     catch(ApplicationModuleCreateException e)
{
System.out.println("Unable to create application module package4.HrAppmodule");
e.printStackTrace();
}
}
  public static void main(String[] args)
{
new HRClient().test();
}
}