Programming the Client Interface

The Business Components for Java Client API (the oracle.jbo.* package) provides a performance-enhancing and productivity-boosting programming interface that insulates application developers from having to understand:

By writing to this API, your clients and servers can easily support operating in any of the deployment configurations described above without code changes by you. In every scenario, your client code follows the same simple steps to establish a connection with a server:

  1. Setup appropriate environment properties for the connection.

  2. Create a JNDI Naming Context for the environment.

  3. Lookup the ApplicationModuleHome for the Application Module you intend to create.

  4. Create an instance of the Application Module by calling create() on the home interface.

  5. Set the database connection to be used by the Application Module.

Sample Code for Local Business Components for Java Client

The following code example is a working example of a simple Business Components for Java client program.

import oracle.jbo.*;
import java.util.Hashtable;
import javax.naming.*;
public class SampleLocalClient {
  public static void main(String[] arg) throws Exception {
String
/*
* Change the strings below to match
* your appmodule's name and jdbc connect string
*
*/
theAMDefName = "test.DeptModule",
theVOMemberName = "DeptView",
theUsername = "scott",
thePassword = "tiger",
theDBUrl = "jdbc:oracle:thin:@localhost:1521:xsl";
    // Setup the Environment for a LOCAL connection
Hashtable env = new Hashtable(10);
env.put(Context.INITIAL_CONTEXT_FACTORY, JboContext.JBO_CONTEXT_FACTORY);
env.put(JboContext.DEPLOY_PLATFORM , JboContext.PLATFORM_LOCAL);
    // Create the initial JNDI context
Context ic = new InitialContext(env);
    // Lookup a home/factory for the desired Application Module
ApplicationModuleHome home =(ApplicationModuleHome)ic.lookup(theAMDefName);
    // Instantiate the Application Module
ApplicationModule am = home.create();
    // Get the ApplicationModule's Transaction and establish a connection
am.getTransaction().connect(theDBUrl,theUsername,thePassword);
    // Find the desired View Object member in the Appliction Module
ViewObject vo = am.findViewObject( theVOMemberName );
    // Query the ViewObject and return the first Row
Row r = vo.first();
    // If we got a row...
if (r != null) {
      // Loop over the attributes in the Row and Print out the values
for (int i = 0; i < vo.getAttributeCount(); i++ ) {
String attrName = vo.getAttributeDef(i).getName();
String attrVal = r.getAttribute(i).toString();
System.out.println(attrName + " = " + attrVal);
}
}
// Disconnect
am.getTransaction().disconnect();
}
}