Skip Headers
Oracle® Database JPublisher User's Guide
10g Release 1 (10.2)

Part Number B14188-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
View PDF

A Generated Code Examples

This appendix contains generated code examples that are explained in the following sections:

Generated Code: User Subclass for Java-to-Java Transformations

This section contains generated code for the example in "JPublisher-Generated Subclasses for Java-to-Java Type Transformations". This example uses style files and holder classes in generating a user subclass that supports PL/SQL output arguments and uses Java types supported by Web services. This example shows the JPublisher-generated interface, base class, and user subclass to publish the following PL/SQL package, foo_pack, consisting of the stored function foo, by using Java types suitable for Web services:

CREATE OR REPLACE PACKAGE foo_pack AS 
   FUNCTION foo(a IN OUT SYS.XMLTYPE, b INTEGER) RETURN CLOB; 
END; 
/

Assume that you translate the foo_pack package as follows:

% jpub -u scott/tiger -s foo_pack:FooPack -style=webservices10

Note that:

The foo() wrapper method in the FooPackUser user subclass uses the following type transformation functionality and a call to the corresponding _foo() method of the generated base class, which is where the Java Database Connectivity (JDBC) calls occur to invoke the wrapped stored function, foo:

foo (SourceHolder, Integer)
{
     SourceHolder -> Source 
          Source -> SimpleXMLType 
               _foo (SimpleXMLType[], Integer); 
          SimpleXMLType -> Source 
     Source -> SourceHolder
}

Interface Code

The following code is for the Java interface that JPublisher generates in FooPack.java:

import java.sql.SQLException;
import sqlj.runtime.ref.DefaultContext;
import sqlj.runtime.ConnectionContext;
import java.sql.Connection;
// Ensure that the java.io.* package and other required packages are imported.
import java.io.*;

public interface FooPack extends java.rmi.Remote 
{
   public java.lang.String foo(SourceHolder _xa_inout_x, Integer b) throws java.rmi.RemoteException;
}

Base Class Code

The following code is for the base class that JPublisher generates in FooPackBase.java. The _foo() method is called by the foo() method of the user subclass and uses JDBC to invoke the foo stored function of the foo_pack PL/SQL package that JPublisher is publishing.

Note:

Comments indicate corresponding SQLJ code, which JPublisher translates automatically during the generation of the class.
import java.sql.SQLException;
import sqlj.runtime.ref.DefaultContext;
import sqlj.runtime.ConnectionContext;
import java.sql.Connection;
// Ensure that the java.io.* package and other required packages are imported.
import java.io.*;

public class FooPackBase
{

  /* connection management */
  protected DefaultContext __tx = null;
  protected Connection __onn = null;
  public void _setConnectionContext(DefaultContext ctx) throws SQLException
  { release(); __tx = ctx; 
    ctx.setStmtCacheSize(0);
    ctx.setDefaultStmtCacheSize(0);
    if (ctx.getConnection() instanceof oracle.jdbc.OracleConnection)
    {
       try 
       {
          java.lang.reflect.Method m =
             ctx.getConnection().getClass().getMethod("setExplicitCachingEnabled",
             new Class[]{Boolean.TYPE});
          m.invoke(ctx.getConnection(), new Object[]{Boolean.FALSE});
       }
       catch(Exception e) { /* do nothing for pre-9.2 JDBC drivers*/ }
    }}
public DefaultContext _getConnectionContext() throws SQLException
{ if (__tx==null)
  { __tx = (__onn==null) ? DefaultContext.getDefaultContext() : 
                               new DefaultContext(__onn); }
  return __tx;
};
public Connection _getConnection() throws SQLException
{ return (__onn==null) ? ((__tx==null) ? null : __tx.getConnection()) : __onn; }
public void release() throws SQLException
{ if (__tx!=null && __onn!=null) __tx.close(ConnectionContext.KEEP_CONNECTION);
  __onn = null; __tx = null;
}

/* constructors */
public FooPackBase() throws SQLException
{ __tx = DefaultContext.getDefaultContext();
}
public FooPackBase(DefaultContext c) throws SQLException
{ __tx = c; }
public FooPackBase(Connection c) throws SQLException
{__onn = c; __tx = new DefaultContext(c);  }

/* *** _foo() USES JDBC TO INVOKE WRAPPED foo STORED PROCEDURE *** */

public oracle.sql.CLOB _foo (
  oracle.sql.SimpleXMLType a[],
  Integer b)
  throws SQLException
{
  oracle.sql.CLOB __jPt_result;
 
  //  ************************************************************
  //  #sql [_getConnectionContext()] __jPt_result = { VALUES(SCOTT.FOO_PACK.FOO(
  //        :a[0],
  //        :b))  };
  //  ************************************************************
 
{
  // declare temps
  oracle.jdbc.OracleCallableStatement __sJT_st = null;
  sqlj.runtime.ref.DefaultContext __sJT_cc = _getConnectionContext(); 
  if (__sJT_cc==null) sqlj.runtime.error.RuntimeRefErrors.raise_NULL_CONN_CTX();
  sqlj.runtime.ExecutionContext.OracleContext __sJT_ec =
              ((__sJT_cc.getExecutionContext()==null) ?
              sqlj.runtime.ExecutionContext.raiseNullExecCtx() :
              __sJT_cc.getExecutionContext().getOracleContext());
  try {
   String theSqlTS = "BEGIN :1 := SCOTT.FOO_PACK.FOO
              (\n       :2 ,\n       :3 )  \n; END;";
   __sJT_st = __sJT_ec.prepareOracleCall(__sJT_cc,"0FooPackBase",theSqlTS);
   if (__sJT_ec.isNew())
   {
      __sJT_st.registerOutParameter(1,oracle.jdbc.OracleTypes.CLOB);
      __sJT_st.registerOutParameter(2,2007,"SYS.XMLTYPE");
   }
   // set IN parameters
   if (a[0]==null) __sJT_st.setNull(2,2007,"SYS.XMLTYPE"); 
   else __sJT_st.setORAData(2,a[0]);
   if (b == null) __sJT_st.setNull(3,oracle.jdbc.OracleTypes.INTEGER); 
   else __sJT_st.setInt(3,b.intValue());
 // execute statement
   __sJT_ec.oracleExecuteUpdate();
   // retrieve OUT parameters
   __jPt_result =  (oracle.sql.CLOB) __sJT_st.getCLOB(1);
   a[0] = (oracle.sql.SimpleXMLType)__sJT_st.getORAData
                                (2,oracle.sql.SimpleXMLType.getORADataFactory());
  } finally { __sJT_ec.oracleClose(); }
}

 //  ************************************************************

    return __jPt_result;
  }
}

User Subclass Code

The following code is for the user subclass that JPublisher generates in FooPackUser.java. This class extends the FooPackBase class and implements the FooPack interface. The foo() method calls the _foo() method of the base class. Java-to-Java transformations are handled in try blocks, as indicated in code comments.

import java.sql.SQLException;
import sqlj.runtime.ref.DefaultContext;
import sqlj.runtime.ConnectionContext;
import java.sql.Connection;
// Ensure that the java.io.* package and other required packages are imported.
import java.io.*;

public class FooPackUser extends FooPackBase implements FooPack, java.rmi.Remote
{

  /* constructors */
  public FooPackUser() throws SQLException  { super(); }
  public FooPackUser(DefaultContext c) throws SQLException { super(c); }
  public FooPackUser(Connection c) throws SQLException { super(c); }
  /* superclass methods */
  public java.lang.String foo(SourceHolder _xa_inout_x, Integer b) 
                                                   throws java.rmi.RemoteException
  { 
    oracle.sql.CLOB __jRt_0 = null;
    java.lang.String __jRt_1 = null;

/* *** FOLLOWING try BLOCK CONVERTS SourceHolder TO Source *** */

    try {
       javax.xml.transform.Source[] a_inout;
       // allocate an array for holding the OUT value
       a_inout = new javax.xml.transform.Source[1];
       if (_xa_inout_x!=null) a_inout[0] = _xa_inout_x.value;
       oracle.sql.SimpleXMLType[] xa_inoutx;
       xa_inoutx = new oracle.sql.SimpleXMLType[1];

/* *** FOLLOWING try BLOCK TRANSFORMS Source TO SimpleXMLType *** */

    try 
    {
      javax.xml.transform.Transformer trans =
           javax.xml.transform.TransformerFactory.newInstance().newTransformer();
      xa_inoutx[0] = null;
      if (a_inout[0]!=null)
      {
        java.io.ByteArrayOutputStream buf = new java.io.ByteArrayOutputStream();
        javax.xml.transform.stream.StreamResult streamr = 
                                new javax.xml.transform.stream.StreamResult(buf);
        trans.transform(a_inout[0], streamr);
        xa_inoutx[0] = new oracle.sql.SimpleXMLType(_getConnection());
        xa_inoutx[0] = xa_inoutx[0].createxml(buf.toString()); 
      }
    }
    catch (java.lang.Throwable t)
    {
      throw OC4JWsDebugPrint(t);
    }

/* *** CALL _foo() FROM BASE CLASS (SUPER CLASS) *** */

    __jRt_0 = super._foo(xa_inoutx, b);

/* *** FOLLOWING try BLOCK TRANSFORMS SimpleXMLType TO Source *** */

    try 
    {
      javax.xml.parsers.DocumentBuilder db = 
      javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder();
      a_inout[0] = null;
      if (xa_inoutx[0]!=null) 
      {
        org.w3c.dom.Document _tmpDocument_ = db.parse
       (new java.io.ByteArrayInputStream(xa_inoutx[0].getstringval().getBytes()));
        a_inout[0]= new javax.xml.transform.dom.DOMSource(_tmpDocument_);
      }
    }
    catch (java.lang.Throwable t)
    {
      throw OC4JWsDebugPrint(t);
    }

/* *** FOLLOWING CODE CONVERTS Source TO SourceHolder *** */

      // convert OUT value to a holder
      if (a_inout!=null) _xa_inout_x.value = a_inout[0];
    if (__jRt_0==null)
    {
       __jRt_1=null;
    }
    else
    {
       __jRt_1=readerToString(__jRt_0.getCharacterStream());
    }

    }  
    catch (Exception except) {
        try {
           Class sutil = Class.forName("com.evermind.util.SystemUtils");
           java.lang.reflect.Method getProp = sutil.getMethod("getSystemBoolean",
                                       new Class[]{String.class, Boolean.TYPE}); 
           if (((Boolean)getProp.invoke(null, new Object[]{"ws.debug",
                       Boolean.FALSE})).booleanValue()) except.printStackTrace();
        }  catch (Throwable except2) {}
        throw new java.rmi.RemoteException(except.getMessage(), except); 
    }
    return __jRt_1;
  }
 private java.lang.String readerToString(java.io.Reader r)
                                                 throws java.sql.SQLException
{
        CharArrayWriter caw = new CharArrayWriter();
        
        try
          {
                //Read from reader and write to writer
                boolean done = false;
         
                while (!done)
                {
                        char[] buf = new char[4096];
                        int len = r.read(buf, 0, 4096);
                        if(len == -1)
                        {
                        done = true;
                        }
                        else
                        {
                                caw.write(buf,0,len);
                        }
                }
           }
         catch(Throwable t)
         {
           throw OC4JWsDebugPrint(t);
         }  
        return caw.toString();
 }
    private void populateClob(oracle.sql.CLOB clb, java.lang.String data)
                                                        throws Exception
    {
        java.io.Writer writer = clb.getCharacterOutputStream();
        writer.write(data.toCharArray());
        writer.flush();
        writer.close();
    }
    private boolean OC4JWsDebug() 
    {
      boolean debug = false;
      try {
        // Server-side Debug Info for "java -Dws.debug=true -jar oc4j.jar" 
        Class sutil = Class.forName("com.evermind.util.SystemUtils");
        java.lang.reflect.Method getProp = sutil.getMethod("getSystemBoolean", 
                                      new Class[]{String.class, Boolean.TYPE});
        if (((Boolean)getProp.invoke(null, new Object[]{"ws.debug", 
                                   Boolean.FALSE})).booleanValue()) 
        {
          debug = true;
        }
      }  catch (Throwable except2) {}
      return debug;
    }
    private java.sql.SQLException OC4JWsDebugPrint(Throwable t) 
    {
      java.sql.SQLException t0 =  new java.sql.SQLException(t.getMessage());
      if (!OC4JWsDebug()) return t0;
      t.printStackTrace();
      try 
      {
        java.lang.reflect.Method getST =
                       Exception.class.getMethod("getStackTrace", new Class[]{});
        java.lang.reflect.Method setST =
                       Exception.class.getMethod("setStackTrace", new Class[]{});
        setST.invoke(t0, new Object[]{getST.invoke(t, new Object[]{})});
      }
      catch (Throwable th){}
      return t0;
    }
}

Generated Code: SQL Statement

This section contains a generated code example for a specified SQL statement, related to the discussion in "Declaration of SQL Statements to Translate".

The example is for the following sample settings of the -sqlstatement option:

-sqlstatement.class=MySqlStatements
-sqlstatement.getEmp="select ename from emp
                      where ename=:{myname VARCHAR}"
-sqlstatement.return=both

Note that for this example:

(For UPDATE, INSERT, or DELETE statements, code is generated both with and without batching for array binds.)

The translated SQLJ code that JPublisher would produce is:

public class MySqlStatements_getEmpRow 
{ 
 
  /* connection management */ 
 
  /* constructors */ 
  public MySqlStatements_getEmpRow() 
  { } 
 
  public String getEname() throws java.sql.SQLException 
  { return ename; } 
 
  public void setEname(String ename) throws java.sql.SQLException 
  { this.ename = ename; } 
 
  private String ename; 
} 
 
/*@lineinfo:filename=MySqlStatements*/
/*@lineinfo:user-code*/
/*@lineinfo:1^1*/
import java.sql.SQLException; 
import sqlj.runtime.ref.DefaultContext; 
import sqlj.runtime.ConnectionContext; 
import java.sql.Connection; 
import oracle.sql.*; 

public class MySqlStatements 
{ 

  /* connection management */ 
  protected DefaultContext __tx = null; 
  protected Connection __onn = null; 
  public void setConnectionContext(DefaultContext ctx) throws SQLException 
  { release(); __tx = ctx; } 
  public DefaultContext getConnectionContext() throws SQLException 
  { if (__tx==null) 
    { __tx = (__onn==null) ? DefaultContext.getDefaultContext() : 
                             new DefaultContext(__onn); } 
    return __tx; 
  }; 
  public Connection getConnection() throws SQLException 
  { return (__onn==null) ? ((__tx==null) ? null : __tx.getConnection()) : __onn; } 
  public void release() throws SQLException 
  { if (__tx!=null && __onn!=null) __tx.close(ConnectionContext.KEEP_CONNECTION); 
    __onn = null; __tx = null; 
  } 
 
  /* constructors */ 
  public MySqlStatements() throws SQLException 
  { __tx = DefaultContext.getDefaultContext(); } 
  public MySqlStatements(DefaultContext c) throws SQLException 
  { __tx = c; } 
  public MySqlStatements(Connection c) throws SQLException 
  {__onn = c; __tx = new DefaultContext(c); } 
/*@lineinfo:generated-code*/
/*@lineinfo:36^1*/ 

//  ************************************************************ 
//  SQLJ iterator declaration: 
//  ************************************************************ 

public static class getEmpIterator 
    extends sqlj.runtime.ref.ResultSetIterImpl 
    implements sqlj.runtime.NamedIterator 
{ 
  public getEmpIterator(sqlj.runtime.profile.RTResultSet resultSet) 
    throws java.sql.SQLException 
  { 
    super(resultSet); 
    enameNdx = findColumn("ename"); 
    m_rs = (oracle.jdbc.OracleResultSet) resultSet.getJDBCResultSet(); 
  } 
  private oracle.jdbc.OracleResultSet m_rs; 
  public String ename() 
    throws java.sql.SQLException 
  { 
    return m_rs.getString(enameNdx); 
  } 
  private int enameNdx; 
} 
 
//  ************************************************************ 
 
/*@lineinfo:user-code*/
/*@lineinfo:36^56*/ 
 
  public MySqlStatements_getEmpRow[] getEmpBeans (String myname) 
         throws SQLException 
  { 
    getEmpIterator iter; 
    /*@lineinfo:generated-code*/
    /*@lineinfo:43^5*/ 
//  ************************************************************ 
//  #sql [getConnectionContext()] 
//                     iter = { select ename from emp where ename=:myname }; 
//  ************************************************************ 
{ 
  // declare temps 
  oracle.jdbc.OraclePreparedStatement __sJT_st = null; 
  sqlj.runtime.ref.DefaultContext __sJT_cc = getConnectionContext(); 
  if (__sJT_c c==null) sqlj.runtime.error.RuntimeRefErrors.raise_NULL_CONN_CTX(); 
  sqlj.runtime.ExecutionContext.OracleContext __sJT_ec = 
        ((__sJT_cc.getExecutionContext()==null) ? 
        sqlj.runtime.ExecutionContext.raiseNullExecCtx() : 
        __sJT_cc.getExecutionContext().getOracleContext()); 
  try { 
   String theSqlTS = "select ename from emp where ename= :1"; 
   __sJT_st = __sJT_ec.prepareOracleStatement
                    (__sJT_cc,"0MySqlStatements",theSqlTS); 
   // set IN parameters 
   __sJT_st.setString(1,myname); 
   // execute query 
   iter = new MySqlStatements.getEmpIterator
             (new sqlj.runtime.ref.OraRTResultSet 
             (__sJT_ec.oracleExecuteQuery(),__sJT_st,"0MySqlStatements",null)); 
  } finally { __sJT_ec.oracleCloseQuery(); } 
} 

//  ************************************************************ 
 
/*@lineinfo:user-code*/
/*@lineinfo:43^84*/ 
    java.util.Vector v = new java.util.Vector(); 
    while (iter.next()) 
    { 
       MySqlStatements_getEmpRow r = new MySqlStatements_getEmpRow(); 
       r.setEname(iter.ename()); 
       v.addElement(r); 
    } 
    MySqlStatements_getEmpRow[] __jPt_result = 
          new MySqlStatements_getEmpRow[v.size()]; 
    for (int i = 0; i < v.size(); i++) 
       __jPt_result[i] = (MySqlStatements_getEmpRow) v.elementAt(i); 
    return __jPt_result; 
  } 
 
  public java.sql.ResultSet getEmp (String myname) 
          throws SQLException 
  { 
    sqlj.runtime.ResultSetIterator iter; 
    /*@lineinfo:generated-code*/
    /*@lineinfo:62^5*/ 
 
//  ************************************************************ 
//  #sql [getConnectionContext()] iter = 
//                     { select ename from emp where ename=:myname }; 
//  ************************************************************ 
 
{ 
  // declare temps 
  oracle.jdbc.OraclePreparedStatement __sJT_st = null; 
  sqlj.runtime.ref.DefaultContext __sJT_cc = getConnectionContext(); 
  if (__sJT_c c==null) sqlj.runtime.error.RuntimeRefErrors.raise_NULL_CONN_CTX(); 
  sqlj.runtime.ExecutionContext.OracleContext __sJT_ec = 
              ((__sJT_cc.getExecutionContext()==null) ?
              sqlj.runtime.ExecutionContext.raiseNullExecCtx() :
              __sJT_cc.getExecutionContext().getOracleContext()); 
  try { 
   String theSqlTS = "select ename from emp where ename= :1"; 
   __sJT_st = __sJT_ec.prepareOracleStatement
                 (__sJT_cc,"1MySqlStatements",theSqlTS); 
   // set IN parameters 
   __sJT_st.setString(1,myname); 
   // execute query 
   iter = new sqlj.runtime.ref.ResultSetIterImpl
         (new sqlj.runtime.ref.OraRTResultSet
         (__sJT_ec.oracleExecuteQuery(),__sJT_st,"1MySqlStatements",null)); 
  } finally { __sJT_ec.oracleCloseQuery(); } 
} 
 
//  ************************************************************ 
 
/*@lineinfo:user-code*/
/*@lineinfo:62^84*/ 
    java.sql.ResultSet __jPt_result = iter.getResultSet(); 
    return __jPt_result; 
  } 
}
/*@lineinfo:generated-code*/ 

Generated Code: Server-Side Java Call-in

JPublisher supports the calling of Java methods in the database from a Java client outside the database. In Oracle Database 10g release 2 (10.2), the JPublisher -dbjava option is used for server-side Java invocation. Unlike the -java option, the -dbjava option supports non-serializable parameter or return types.

This section describes an example of server-side Java invocation. This section comprises:

Note:

You must have the 10g Release 1 (10.2) version of the Oracle Database.

The Source Files

In this example, there are three source files to be created. These are:

  • A server-side Java class

  • A JavaBean used in the server-side Java class

  • An entry point Java class that invokes the methods in the published classes

The source code of these files is as follows:

Server-Side Java Class

The source code of the server-side Java class, Callin2.java, is as follows:

public class Callin2
{
  public static int testInt(int i)
  { return i; }
  public static int[] testInt(int[] i)
  { return i; }
  public static int[][] testInt(int[][] i)
  { return i; }
  public static Integer testInteger(Integer i)
  { return i; }
  public static Integer[] testInteger(Integer[] i)
  { return i; }
  public static Integer[][] testInteger(Integer[][] i)
  { return i; }

  // Test ORAData
  public static oracle.sql.NUMBER testNum(oracle.sql.NUMBER num)
  { return num; }
  public oracle.sql.NUMBER testInstNum(oracle.sql.NUMBER num)
  { return num; }
  public oracle.sql.NUMBER[] testInstNum(oracle.sql.NUMBER[] num)
  { return num; }
  public oracle.sql.NUMBER[][] testInstNum(oracle.sql.NUMBER[][] num)
  { return num; }

  // Test Beans
  public static Callin2Bean testBean()
  { return new Callin2Bean("mybean", new int[]{1,2}); }
  public static Callin2Bean testBean (Callin2Bean b)
  { return b; }
  public static Callin2Bean[] testBean (Callin2Bean[] b)
  { return b; }
  public static Callin2Bean[][] testBean (Callin2Bean[][] b)
  { return b; }
  public Callin2Bean testInstBean (Callin2Bean b)
  { return b; }
  public Callin2Bean[] testInstBean (Callin2Bean[] b)
  { return b; }
  public Callin2Bean[][] testInstBean (Callin2Bean[][] b)
  { return b; }

  // Test Serializable
  public static java.io.Serializable testSer()
  { return new String("test Serializable"); }
  public static java.io.Serializable testSer (java.io.Serializable b)
  { return b; }
  public static java.io.Serializable[] testSer (java.io.Serializable[] b)
  { return b; }
  public static java.io.Serializable[][] testSer (java.io.Serializable[][] b)
  { return b; }
  public java.io.Serializable testInstSer (java.io.Serializable b)
  { return b; }
  public java.io.Serializable[] testInstSer (java.io.Serializable[] b)
  { return b; }
  public java.io.Serializable[][] testInstSer (java.io.Serializable[][] b)
  { return b; }
}

JavaBean Used in the Server-Side Java Class

The source code of the JavaBean, Callin2Bean.java, used in the server-side Java class, Callin2.java, is as follows:

public class Callin2Bean 
{
  private String stringValue = "";
  private int[] numberValue;
  
  public Callin2Bean ()
  {
  }
 
  public Callin2Bean(String string_val, int[] number_val)
  {
    stringValue = string_val;
    numberValue = number_val;
  }
 
  public void setStringValue(String string_val)
  {
    stringValue = string_val;
  }
 
  public String getStringValue ()
  {
    return stringValue;
  }
 
  public void setNumberValue (int[] number_val)
  {
    numberValue = number_val;
  }
 
  public int[] getNumberValue ()
  {
    return numberValue;
  }
 
  public boolean equals(Object other)
  {
    if(other instanceof Callin2Bean)
    {
      Callin2Bean my_bean = (Callin2Bean)other;
      if ( stringValue.equals(my_bean.getStringValue()) && compareIntArray(numberValue, my_bean.getNumberValue()) )
      {
        return true;
      }
    }
    return false;
  }
 
  private boolean compareIntArray(int[] b1, int[] b2)
  {
    try
    { 
      if ((b1 == null) && (b2 == null))
        return true;
 
      if ((b1.length == 0) && (b2.length == 0))
        return true;
 
      if (b1.length != b2.length)
        return false;
      int x;
      for (x = 0; x < b1.length; x++)
      {
        if (b1[x] != b2[x])
          return false;
      }
      return true;
    }
    catch (Exception e)
    {
      return false;
    }
  }
}

Entry Point Java Class

The TestCallin2.java is the entry point Java class for this example. This class invokes the methods in the published class. The source code of the TestCallin2.java file is as follows:

public class TestCallin2
{
  public static void main(String[] args) throws Exception
  {
    java.sql.DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
    oracle.jdbc.OracleConnection conn = (oracle.jdbc.OracleConnection) 
    //java.sql.DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:lsqlj1", "scott", "tiger");
    java.sql.DriverManager.getConnection("jdbc:oracle:oci8:@", "scott", "tiger");
 
   Callin2Client tkpu = new Callin2Client (conn);
 
   System.out.println("testInstNum() returned " + tkpu.testinstnum(new java.math.BigDecimal(1999)));
 
   TblNumber na = new TblNumber(new java.math.BigDecimal[]{new java.math.BigDecimal(2999)});
   System.out.println("testInstNum([]) returned " +
   tkpu.testinstnum(na).getArray()[0]);
 
   ObjCallin2bean mb = new ObjCallin2bean("mybean", na);
   System.out.println("testCallin2Bean() returned " + tkpu.testbean(mb).getStringvalue());
   System.out.println("testCallin2Bean([]) returned " + tkpu.testbean(new TblObjCallin2bean(new ObjCallin2bean[]{mb})).getArray()[0].getStringvalue());
 
   java.io.Serializable s = new java.util.Hashtable();
   ((java.util.Hashtable) s).put("bush", "cheny");
   ((java.util.Hashtable) s).put("kerry", "dean");
   java.io.Serializable[] s1 = new java.io.Serializable[]{s};
   java.io.Serializable[][] s2 = new java.io.Serializable[][]{s1};
   System.out.println("testSer() returned " + ((java.util.Hashtable) tkpu.testser(s)).get("kerry")); 
   System.out.println("testSer([]) returned " + ((java.util.Hashtable) tkpu.testser0(s1)[0]).get("kerry")); 
   System.out.println("testSer([][]) returned " + ((java.util.Hashtable) tkpu.testser1(s2)[0][0]).get("kerry")); 
  }
}

Note:

If you are connecting to the database using the JDBC Thin driver, then you need to uncomment the first call to the getConnection() method in the preceding code and comment the second call to the getConnection() method, which includes a connect statement for an Oracle Call Interface (OCI) driver.

Publishing Server-Side Java Class

After you have created the required source files, you need to publish these files. To publish the server-side Java classes, you need to first load these files on to the database. Ensure that you load both Callin2.java and Callin2Bean.java. The command for loading the files is:

% loadjava -u scott/tiger -r -v -f Callin2.java Callin2Bean.java

To publish these files, issue the following command:

% jpub -u scott/tiger -sysuser=sys/change_on_install -dbjava=Callin2:Callin2Client -dir=tmp

The JPublisher output is:

tmp/Callin2JPub.java
tmp/plsql_wrapper.sql
tmp/plsql_dropper.sql
SCOTT.TBL_NUMBER
SCOTT.TBL_TBL_NUMBER
SCOTT.OBJ_CALLIN2BEAN
SCOTT.TBL_OBJ_CALLIN2BEAN
SCOTT.TBL_TBL_OBJ_CALLI
SCOTT.JPUB_PLSQL_WRAPPER
Executing tmp/plsql_dropper.sql
Executing tmp/plsql_wrapper.sql
Loading Callin2JPub.java

The Generated Files

When you publish the server-side Java classes JPublisher generates a few Java classes and PL/SQL scripts. Some of these files are:

  • Callin2JPub.java

    This is the server-side Java wrapper class for Callin2.java.

  • Callin2Client.java

    This is the client-side Java class.

  • plsql_wrapper.sql

    This is the PL/SQL wrapper for the server-side Java class.

  • plsql_dropper.sql

    This is the PL/SQL script dropping the PL/SQL wrapper.

The other files generated by JPublisher are as follows:

  • TblNumber.java

    A client-side wrapper generated for int[].

  • TblTblNumber.java

    A client-side wrapper generated for int[][].

  • ObjCallin2bean.java

    A client-side wrapper generated for the server-side class Callin2Bean.

  • ObjCallin2beanRef.java

    A client-side wrapper generated for the server-side class Callin2Bean, used as a REF column in a table. This file is generated, but not used in the call-in scenario.

  • TblObjCallin2bean.java

    A client-side wrapper generated for Callin2Bean[].

  • TblTblObjCalli.java

    A client-side wrapper generated for Callin2Bean[][].

Testing the Published Files

After the files have been published, you can test the published classes by issuing the following commands:

% javac -classpath tmp:${CLASSPATH} -d tmp TestCallin2.java
% java -classpath tmp:${CLASSPATH} TestCallin2