Oracle8i JPublisher User's Guide
Release 2 (8.1.6)

A81357-01

Library

Product

Contents

Index

Prev  Chap Top Next

Example: Extending JPublisher Classes

Here is an example of the scenario "Extending JPublisher Classes" describes.

The following is the code that you have written for the class MyAddress.java and stored in the directory demo/corp.

package corp;

import java.sql.SQLException;
import oracle.sql.CustomDatum;
import oracle.sql.CustomDatumFactory;
import oracle.sql.Datum;
import oracle.sql.STRUCT;
import oracle.jpub.runtime.MutableStruct;

public class MyAddress extends JAddress
{
  /* _SQL_NAME inherited from JAddress */
  /* _SQL_TYPECODE inherited from JAddress */

  /* _sqlType inherited from JAddress */

  /* _factory inherited from JAddress */

  /* _struct inherited from JAddress */

  static final MyAddress _MyAddressFactory = new MyAddress();
  public static CustomDatumFactory getFactory()
  {
    return _MyAddressFactory;
  }

  /* constructor */
  public MyAddress()
  {
    super();
  }

  /* CustomDatum interface */
  /* toDatum() inherited from JAddress */

  /* CustomDatumFactory interface */
  public CustomDatum create(Datum d, int sqlType) throws SQLException
  {
     if (d == null) return null;
     MyAddress o = new MyAddress();
     o._struct = new MutableStruct((STRUCT) d, _sqlType, _factory);
     o._ctx = new _Ctx(((STRUCT) d).getConnection());
     return o;
  }

  /* accessor methods inherited from JAddress */

  /* Additional methods go here. These additional methods (not shown)
     are the reason that JAddress was extended.
  */
}
 

To have JPublisher generate code for the JAddress class, recognizing that MyAddress extends JAddress, enter this command line:

jpub -user=scott/tiger -input=demoin -dir=demo -package=corp 
 

where the contents of the demoin file is:

SQL ADDRESS GENERATE JAddress AS MyAddress  

JPublisher will generate these files:

demo/corp/JAddress.java 
demo/corp/MyAddressRef.java 
 

Because an ADDRESS will be represented in the Java program as a MyAddress class, JPublisher generates the class MyAddressRef rather than JAddressRef.

Here is a listing of the demo/corp/JAddress.java class file generated by JPublisher:


Note:

The details of method bodies that JPublisher generates might change in future releases.  


package corp;

import java.sql.SQLException;
import oracle.jdbc.driver.OracleConnection;
import oracle.jdbc.driver.OracleTypes;
import oracle.sql.CustomDatum;
import oracle.sql.CustomDatumFactory;
import oracle.sql.Datum;
import oracle.sql.STRUCT;
import oracle.jpub.runtime.MutableStruct;

public class JAddress implements CustomDatum, CustomDatumFactory
{
  public static final String _SQL_NAME = "SCOTT.ADDRESS";
  public static final int _SQL_TYPECODE = OracleTypes.STRUCT;

  MutableStruct _struct;

  static int[] _sqlType =
  {
    12, 12, 12, 2
  };

  static CustomDatumFactory[] _factory = new CustomDatumFactory[4];

  static final JAddress _JAddressFactory = new JAddress();
  public static CustomDatumFactory getFactory()
  {
    return _JAddressFactory;
  }

  /* constructor */
  public JAddress()
  {
    _struct = new MutableStruct(new Object[4], _sqlType, _factory);
  }

  /* CustomDatum interface */
  public Datum toDatum(OracleConnection c) throws SQLException
  {
    return _struct.toDatum(c, _SQL_NAME);
  }

  /* CustomDatumFactory interface */
  public CustomDatum create(Datum d, int sqlType) throws SQLException
  {
    if (d == null) return null;
    JAddress o = new JAddress();
    o._struct = new MutableStruct((STRUCT) d, _sqlType, _factory);
    return o;
  }

  /* accessor methods */
  public String getStreet() throws SQLException
  { return (String) _struct.getAttribute(0); }

  public void setStreet(String street) throws SQLException
  { _struct.setAttribute(0, street); }

  public String getCity() throws SQLException
  { return (String) _struct.getAttribute(1); }

  public void setCity(String city) throws SQLException
  { _struct.setAttribute(1, city); }

  public String getState() throws SQLException
  { return (String) _struct.getAttribute(2); }

  public void setState(String state) throws SQLException
  { _struct.setAttribute(2, state); }

  public java.math.BigDecimal getZip() throws SQLException
  { return (java.math.BigDecimal) _struct.getAttribute(3); }

  public void setZip(java.math.BigDecimal zip) throws SQLException
  { _struct.setAttribute(3, zip); }

}

Here is a listing of the demo/corp/MyAddressRef.java class file generated by JPublisher:

package corp;

import java.sql.SQLException;
import oracle.jdbc.driver.OracleConnection;
import oracle.jdbc.driver.OracleTypes;
import oracle.sql.CustomDatum;
import oracle.sql.CustomDatumFactory;
import oracle.sql.Datum;
import oracle.sql.REF;
import oracle.sql.STRUCT;

public class MyAddressRef implements CustomDatum, CustomDatumFactory
{
  public static final String _SQL_BASETYPE = "SCOTT.ADDRESS";
  public static final int _SQL_TYPECODE = OracleTypes.REF;

  REF _ref;

  static final MyAddressRef _MyAddressRefFactory = new MyAddressRef();
  public static CustomDatumFactory getFactory()
  {
    return _MyAddressRefFactory;
  }

  /* constructor */
  public MyAddressRef()
  {
  }

  /* CustomDatum interface */
  public Datum toDatum(OracleConnection c) throws SQLException
  {
    return _ref;
  }

  /* CustomDatumFactory interface */
  public CustomDatum create(Datum d, int sqlType) throws SQLException
  {
    if (d == null) return null;
    MyAddressRef r = new MyAddressRef();
    r._ref = (REF) d;
    return r;
  }
  public MyAddress getValue() throws SQLException
  {
     return (MyAddress) MyAddress.getFactory().create(
       _ref.getSTRUCT(), OracleTypes.REF);
  }

  public void setValue(MyAddress c) throws SQLException
  {
    _ref.setValue((STRUCT) c.toDatum(_ref.getConnection()));
  }
}



Prev

Top

Next
Oracle
Copyright © 1999 Oracle Corporation.

All Rights Reserved.

Library

Product

Contents

Index