Oracle8i JPublisher User's Guide Release 2 (8.1.6) Part Number A81357-01 |
Library | Service | Contents | Index

## Example: Generating a SQLData Class

This example is identical to the previous one, except that JPublisher generates a SQLData class rather than a CustomDatum class. The command line for this example is:

jpub -user=scott/tiger -input=demoin -dir=demo -package=corp -mapping=objectjdbc -usertypes=jdbc -methods=false

The option -usertypes=jdbc instructs JPublisher to generate classes that implement the SQLData interface. The SQLData interface supports REF and collection classes generically, using the generic classes java.sql.Ref and java.sql.Array rather than custom classes. Therefore, JPublisher generates only two classes:

    ./demo/corp/Address.java
    ./demo/all/Alltypes.java

#### Listing of Address.java Generated by JPublisher

Because we specified `-usertypes=jdbc` in this example, the `Address` class implements the `java.sql.SQLData` interface rather than the `oracle.sql.CustomDatum` interface. The file `./demo/corp/Address.java` reads as follows:

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 java.sql.SQLData;
    import java.sql.SQLInput;
    import java.sql.SQLOutput;
    import oracle.sql.STRUCT;
    import oracle.jpub.runtime.MutableStruct;

    public class Address implements SQLData
    {
      public static final String _SQL_NAME = "SCOTT.ADDRESS";
      public static final int _SQL_TYPECODE = OracleTypes.STRUCT;

      private String m_street;
      private String m_city;
      private String m_state;
      private java.math.BigDecimal m_zip;

      /* constructor */
      public Address()
      {
      }

      public void readSQL(SQLInput stream, String type)
      throws SQLException
      {
          setStreet(stream.readString());
          setCity(stream.readString());
          setState(stream.readString());
          setZip(stream.readBigDecimal());
      }

      public void writeSQL(SQLOutput stream)
      throws SQLException
      {
          stream.writeString(getStreet());
          stream.writeString(getCity());
          stream.writeString(getState());
          stream.writeBigDecimal(getZip());
      }

      public String getSQLTypeName() throws SQLException
      {
        return _SQL_NAME;
      }

      /* accessor methods */
      public String getStreet()
      { return m_street; }

      public void setStreet(String street)
      { m_street = street; }

      public String getCity()
      { return m_city; }

      public void setCity(String city)
      { m_city = city; }

      public String getState()
      { return m_state; }

      public void setState(String state)
      { m_state = state; }

      public java.math.BigDecimal getZip()
      { return m_zip; }

      public void setZip(java.math.BigDecimal zip)
      { m_zip = zip; }

    }

#### Listing of Alltypes.java Generated by JPublisher

Because we specified `-usertypes=jdbc` in this example, the `Alltypes` class implements the `java.sql.SQLData` interface rather than the `oracle.sql.CustomDatum` interface. Although the SQLData interface is a vendor-neutral standard, there is Oracle-specific code in the `Alltypes class`, because it uses Oracle-specific types such as `oracle.sql.BFILE` and `oracle.sql.CLOB`. The file `./demo/corp/Alltypes.java` reads as follows:

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

    package all;

    import java.sql.SQLException;
    import oracle.jdbc.driver.OracleConnection;
    import oracle.jdbc.driver.OracleTypes;
    import java.sql.SQLData;
    import java.sql.SQLInput;
    import java.sql.SQLOutput;
    import oracle.sql.STRUCT;
    import oracle.jpub.runtime.MutableStruct;

    public class Alltypes implements SQLData
    {
      public static final String _SQL_NAME = "SCOTT.ALLTYPES";
      public static final int _SQL_TYPECODE = OracleTypes.STRUCT;

      private oracle.sql.BFILE m_attr1;
      private oracle.sql.BLOB m_attr2;
      private String m_attr3;
      private oracle.sql.CLOB m_attr4;
      private java.sql.Timestamp m_attr5;
      private java.math.BigDecimal m_attr6;
      private Double m_attr7;
      private Double m_attr8;
      private Integer m_attr9;
      private java.math.BigDecimal m_attr10;
      private java.math.BigDecimal m_attr11;
      private byte[] m_attr12;
      private Float m_attr13;
      private Integer m_attr14;
      private String m_attr15;
      private String m_attr16;
      private corp.Address m_attr17;
      private java.sql.Ref m_attr18;
      private java.sql.Array m_attr19;
      private java.sql.Array m_attr20;

      /* constructor */
      public Alltypes()
      {
      }

      public void readSQL(SQLInput stream, String type)
      throws SQLException
      {
          setAttr1((oracle.sql.BFILE)
    ((oracle.sql.OracleJdbc2SQLInput)stream).readOracleObject());
          setAttr2((oracle.sql.BLOB)
    ((oracle.sql.OracleJdbc2SQLInput)stream).readOracleObject());
          setAttr3(stream.readString());
          setAttr4((oracle.sql.CLOB)
    ((oracle.sql.OracleJdbc2SQLInput)stream).readOracleObject());
          setAttr5(stream.readTimestamp());
          setAttr6(stream.readBigDecimal());
          setAttr7(new Double(stream.readDouble()));
          if (stream.wasNull()) setAttr7(null);
          setAttr8(new Double(stream.readDouble()));
          if (stream.wasNull()) setAttr8(null);
          setAttr9(new Integer(stream.readInt()));
          if (stream.wasNull()) setAttr9(null);
          setAttr10(stream.readBigDecimal());
          setAttr11(stream.readBigDecimal());
          setAttr12(stream.readBytes());
          setAttr13(new Float(stream.readFloat()));
          if (stream.wasNull()) setAttr13(null);
          setAttr14(new Integer(stream.readInt()));
          if (stream.wasNull()) setAttr14(null);
          setAttr15(stream.readString());
          setAttr16(stream.readString());
          setAttr17((corp.Address) stream.readObject());
          setAttr18(stream.readRef());
          setAttr19(stream.readArray());
          setAttr20(stream.readArray());
      }

      public void writeSQL(SQLOutput stream)
      throws SQLException
      {
          ((oracle.sql.OracleSQLOutput)stream).writeOracleObject(getAttr1());
          ((oracle.sql.OracleSQLOutput)stream).writeOracleObject(getAttr2());
          stream.writeString(getAttr3());
          ((oracle.sql.OracleSQLOutput)stream).writeOracleObject(getAttr4());
          stream.writeTimestamp(getAttr5());
          stream.writeBigDecimal(getAttr6());
          if (getAttr7() == null)
            stream.writeBigDecimal(null);
          else
            stream.writeDouble(getAttr7().doubleValue());
          if (getAttr8() == null)
            stream.writeBigDecimal(null);
          else
            stream.writeDouble(getAttr8().doubleValue());
          if (getAttr9() == null)
            stream.writeBigDecimal(null);
          else
            stream.writeInt(getAttr9().intValue());
          stream.writeBigDecimal(getAttr10());
          stream.writeBigDecimal(getAttr11());
          stream.writeBytes(getAttr12());
          if (getAttr13() == null)
            stream.writeBigDecimal(null);
          else
            stream.writeFloat(getAttr13().floatValue());
          if (getAttr14() == null)
            stream.writeBigDecimal(null);
          else
            stream.writeInt(getAttr14().intValue());
          stream.writeString(getAttr15());
          stream.writeString(getAttr16());
          stream.writeObject(getAttr17());
          stream.writeRef(getAttr18());
          stream.writeArray(getAttr19());
          stream.writeArray(getAttr20());
      }

      public String getSQLTypeName() throws SQLException
      {
        return _SQL_NAME;
      }

      /* accessor methods */
      public oracle.sql.BFILE getAttr1()
      { return m_attr1; }

      public void setAttr1(oracle.sql.BFILE attr1)
      { m_attr1 = attr1; }

      public oracle.sql.BLOB getAttr2()
      { return m_attr2; }

      public void setAttr2(oracle.sql.BLOB attr2)
      { m_attr2 = attr2; }

      public String getAttr3()
      { return m_attr3; }

      public void setAttr3(String attr3)
      { m_attr3 = attr3; }

      public oracle.sql.CLOB getAttr4()
      { return m_attr4; }

      public void setAttr4(oracle.sql.CLOB attr4)
      { m_attr4 = attr4; }

      public java.sql.Timestamp getAttr5()
      { return m_attr5; }

      public void setAttr5(java.sql.Timestamp attr5)
      { m_attr5 = attr5; }

      public java.math.BigDecimal getAttr6()
      { return m_attr6; }

      public void setAttr6(java.math.BigDecimal attr6)
      { m_attr6 = attr6; }

      public Double getAttr7()
      { return m_attr7; }

      public void setAttr7(Double attr7)
      { m_attr7 = attr7; }

      public Double getAttr8()
      { return m_attr8; }

      public void setAttr8(Double attr8)
      { m_attr8 = attr8; }

      public Integer getAttr9()
      { return m_attr9; }

      public void setAttr9(Integer attr9)
      { m_attr9 = attr9; }

      public java.math.BigDecimal getAttr10()
      { return m_attr10; }

      public void setAttr10(java.math.BigDecimal attr10)
      { m_attr10 = attr10; }

      public java.math.BigDecimal getAttr11()
      { return m_attr11; }

      public void setAttr11(java.math.BigDecimal attr11)
      { m_attr11 = attr11; }

      public byte[] getAttr12()
      { return m_attr12; }

      public void setAttr12(byte[] attr12)
      { m_attr12 = attr12; }

      public Float getAttr13()
      { return m_attr13; }

      public void setAttr13(Float attr13)
      { m_attr13 = attr13; }

      public Integer getAttr14()
      { return m_attr14; }

      public void setAttr14(Integer attr14)
      { m_attr14 = attr14; }

      public String getAttr15()
      { return m_attr15; }

      public void setAttr15(String attr15)
      { m_attr15 = attr15; }

      public String getAttr16()
      { return m_attr16; }

      public void setAttr16(String attr16)
      { m_attr16 = attr16; }

      public corp.Address getAttr17()
      { return m_attr17; }

      public void setAttr17(corp.Address attr17)
      { m_attr17 = attr17; }

      public java.sql.Ref getAttr18()
      { return m_attr18; }

      public void setAttr18(java.sql.Ref attr18)
      { m_attr18 = attr18; }

      public java.sql.Array getAttr19()
      { return m_attr19; }

      public void setAttr19(java.sql.Array attr19)
      { m_attr19 = attr19; }

      public java.sql.Array getAttr20()
      { return m_attr20; }

      public void setAttr20(java.sql.Array attr20)
      { m_attr20 = attr20; }

    }

| Copyright © 1996-2000, Oracle Corporation. All Rights Reserved. |
Library | Service | Contents | Index