使用JPublisher生成Oracle自定义类型的Java对象

来源:互联网 发布:淘宝月销售怎么查看 编辑:程序博客网 时间:2024/06/05 17:09

一:环境变量:

set JPUB_HOME=D:\tools\jpub_102
set ORACLE_HOME=D:\oracle\product\11.2.0\dbhome_1
set CLASSPATH=%CLASSPATH%;%JPUB_HOME%\sqlj\lib\translator.jar
set CLASSPATH=%CLASSPATH%;%JPUB_HOME%\sqlj\lib\runtime12.jar
set CLASSPATH=%CLASSPATH%;%ORACLE_HOME%\jdbc\lib\ojdbc6.jar
SET PATH=%PATH%;%JPUB_HOME%\sqlj\bin

二:Oracle Object Type:

KID:

CREATE OR REPLACE TYPE KID AS OBJECT(  FIRST_NAME VARCHAR(60),  LAST_NAME  VARCHAR(60),  AGE        INTEGER)

KID_TAB:

CREATE OR REPLACE TYPE KID_TAB AS TABLE OF KID

MEMBER:

CREATE OR REPLACE TYPE MEMBER AS OBJECT(  FIRST_NAME VARCHAR(60),  LAST_NAME  VARCHAR(60),  AGE        INTEGER,  CHILDREN KID_TAB)

MEMBER_TAB:

CREATE OR REPLACE TYPE MEMBER_TAB AS TABLE OF MEMBER

MANAGER:

CREATE OR REPLACE TYPE MANAGER AS OBJECT (ID NUMBER,FIRST_NAME VARCHAR2(60),LAST_NAME VARCHAR2(60),AGE INTEGER,GENDER char)

LEADER:

CREATE OR REPLACE TYPE LEADER AS OBJECT (ID NUMBER,FIRST_NAME VARCHAR2(60),LAST_NAME VARCHAR2(60),AGE INTEGER,HIRE_DTSTAMP timestamp,BOSS MANAGER)


PROJECTS:

CREATE OR REPLACE TYPE PROJECTS AS OBJECT (PROJECT_NAME VARCHAR2(60),START_DATE DATE,END_DATE DATE,PROJECT_LEADER LEADER,PARTNER MEMBER_TAB)

三:运行命令

jpub -user=test_user/bid4tool -sql=KID:com.test.object.KidType,KID_TAB:com.test.object.KidTabType,MEMBER:com.test.object.MemberType,MEMBER_TAB:com.test.object.MemberTabType,MANAGER:com.test.object.ManagerType,LEADER:com.test.object.LeaderType,PROJECTS:com.test.object.ProjectsType -url=jdbc:oracle:thin:@localhost:1521:testdb


四:生成代码

ProjectsType.java

package com.test.object;import java.sql.SQLException;import java.sql.Connection;import oracle.jdbc.OracleTypes;import oracle.sql.ORAData;import oracle.sql.ORADataFactory;import oracle.sql.Datum;import oracle.sql.STRUCT;import oracle.jpub.runtime.MutableStruct;public class ProjectsType implements ORAData, ORADataFactory{  public static final String _SQL_NAME = "TEST_USER.PROJECTS";  public static final int _SQL_TYPECODE = OracleTypes.STRUCT;  protected MutableStruct _struct;  protected static int[] _sqlType =  { 12,91,91,2002,2003 };  protected static ORADataFactory[] _factory = new ORADataFactory[5];  static  {    _factory[3] = LeaderType.getORADataFactory();    _factory[4] = MemberTabType.getORADataFactory();  }  protected static final ProjectsType _ProjectsTypeFactory = new ProjectsType();  public static ORADataFactory getORADataFactory()  { return _ProjectsTypeFactory; }  /* constructors */  protected void _init_struct(boolean init)  { if (init) _struct = new MutableStruct(new Object[5], _sqlType, _factory); }  public ProjectsType()  { _init_struct(true); }  public ProjectsType(String projectName, java.sql.Timestamp startDate, java.sql.Timestamp endDate, LeaderType projectLeader, MemberTabType partner) throws SQLException  { _init_struct(true);    setProjectName(projectName);    setStartDate(startDate);    setEndDate(endDate);    setProjectLeader(projectLeader);    setPartner(partner);  }  /* ORAData interface */  public Datum toDatum(Connection c) throws SQLException  {    return _struct.toDatum(c, _SQL_NAME);  }  /* ORADataFactory interface */  public ORAData create(Datum d, int sqlType) throws SQLException  { return create(null, d, sqlType); }  protected ORAData create(ProjectsType o, Datum d, int sqlType) throws SQLException  {    if (d == null) return null;     if (o == null) o = new ProjectsType();    o._struct = new MutableStruct((STRUCT) d, _sqlType, _factory);    return o;  }  /* accessor methods */  public String getProjectName() throws SQLException  { return (String) _struct.getAttribute(0); }  public void setProjectName(String projectName) throws SQLException  { _struct.setAttribute(0, projectName); }  public java.sql.Timestamp getStartDate() throws SQLException  { return (java.sql.Timestamp) _struct.getAttribute(1); }  public void setStartDate(java.sql.Timestamp startDate) throws SQLException  { _struct.setAttribute(1, startDate); }  public java.sql.Timestamp getEndDate() throws SQLException  { return (java.sql.Timestamp) _struct.getAttribute(2); }  public void setEndDate(java.sql.Timestamp endDate) throws SQLException  { _struct.setAttribute(2, endDate); }  public LeaderType getProjectLeader() throws SQLException  { return (LeaderType) _struct.getAttribute(3); }  public void setProjectLeader(LeaderType projectLeader) throws SQLException  { _struct.setAttribute(3, projectLeader); }  public MemberTabType getPartner() throws SQLException  { return (MemberTabType) _struct.getAttribute(4); }  public void setPartner(MemberTabType partner) throws SQLException  { _struct.setAttribute(4, partner); }}

MemberTabType.java

package com.test.object;import java.sql.SQLException;import java.sql.Connection;import oracle.jdbc.OracleTypes;import oracle.sql.ORAData;import oracle.sql.ORADataFactory;import oracle.sql.Datum;import oracle.sql.ARRAY;import oracle.sql.ArrayDescriptor;import oracle.jpub.runtime.MutableArray;public class MemberTabType implements ORAData, ORADataFactory{  public static final String _SQL_NAME = "TEST_USER.MEMBER_TAB";  public static final int _SQL_TYPECODE = OracleTypes.ARRAY;  MutableArray _array;private static final MemberTabType _MemberTabTypeFactory = new MemberTabType();  public static ORADataFactory getORADataFactory()  { return _MemberTabTypeFactory; }  /* constructors */  public MemberTabType()  {    this((MemberType[])null);  }  public MemberTabType(MemberType[] a)  {    _array = new MutableArray(2002, a, MemberType.getORADataFactory());  }  /* ORAData interface */  public Datum toDatum(Connection c) throws SQLException  {    return _array.toDatum(c, _SQL_NAME);  }  /* ORADataFactory interface */  public ORAData create(Datum d, int sqlType) throws SQLException  {    if (d == null) return null;     MemberTabType a = new MemberTabType();    a._array = new MutableArray(2002, (ARRAY) d, MemberType.getORADataFactory());    return a;  }  public int length() throws SQLException  {    return _array.length();  }  public int getBaseType() throws SQLException  {    return _array.getBaseType();  }  public String getBaseTypeName() throws SQLException  {    return _array.getBaseTypeName();  }  public ArrayDescriptor getDescriptor() throws SQLException  {    return _array.getDescriptor();  }  /* array accessor methods */  public MemberType[] getArray() throws SQLException  {    return (MemberType[]) _array.getObjectArray(      new MemberType[_array.length()]);  }  public MemberType[] getArray(long index, int count) throws SQLException  {    return (MemberType[]) _array.getObjectArray(index,      new MemberType[_array.sliceLength(index, count)]);  }  public void setArray(MemberType[] a) throws SQLException  {    _array.setObjectArray(a);  }  public void setArray(MemberType[] a, long index) throws SQLException  {    _array.setObjectArray(a, index);  }  public MemberType getElement(long index) throws SQLException  {    return (MemberType) _array.getObjectElement(index);  }  public void setElement(MemberType a, long index) throws SQLException  {    _array.setObjectElement(a, index);  }}

MemberType.java

package com.test.object;import java.sql.SQLException;import java.sql.Connection;import oracle.jdbc.OracleTypes;import oracle.sql.ORAData;import oracle.sql.ORADataFactory;import oracle.sql.Datum;import oracle.sql.STRUCT;import oracle.jpub.runtime.MutableStruct;public class MemberType implements ORAData, ORADataFactory{  public static final String _SQL_NAME = "TEST_USER.MEMBER";  public static final int _SQL_TYPECODE = OracleTypes.STRUCT;  protected MutableStruct _struct;  protected static int[] _sqlType =  { 12,12,4,2003 };  protected static ORADataFactory[] _factory = new ORADataFactory[4];  static  {    _factory[3] = KidTabType.getORADataFactory();  }  protected static final MemberType _MemberTypeFactory = new MemberType();  public static ORADataFactory getORADataFactory()  { return _MemberTypeFactory; }  /* constructors */  protected void _init_struct(boolean init)  { if (init) _struct = new MutableStruct(new Object[4], _sqlType, _factory); }  public MemberType()  { _init_struct(true); }  public MemberType(String firstName, String lastName, Integer age, KidTabType children) throws SQLException  { _init_struct(true);    setFirstName(firstName);    setLastName(lastName);    setAge(age);    setChildren(children);  }  /* ORAData interface */  public Datum toDatum(Connection c) throws SQLException  {    return _struct.toDatum(c, _SQL_NAME);  }  /* ORADataFactory interface */  public ORAData create(Datum d, int sqlType) throws SQLException  { return create(null, d, sqlType); }  protected ORAData create(MemberType o, Datum d, int sqlType) throws SQLException  {    if (d == null) return null;     if (o == null) o = new MemberType();    o._struct = new MutableStruct((STRUCT) d, _sqlType, _factory);    return o;  }  /* accessor methods */  public String getFirstName() throws SQLException  { return (String) _struct.getAttribute(0); }  public void setFirstName(String firstName) throws SQLException  { _struct.setAttribute(0, firstName); }  public String getLastName() throws SQLException  { return (String) _struct.getAttribute(1); }  public void setLastName(String lastName) throws SQLException  { _struct.setAttribute(1, lastName); }  public Integer getAge() throws SQLException  { return (Integer) _struct.getAttribute(2); }  public void setAge(Integer age) throws SQLException  { _struct.setAttribute(2, age); }  public KidTabType getChildren() throws SQLException  { return (KidTabType) _struct.getAttribute(3); }  public void setChildren(KidTabType children) throws SQLException  { _struct.setAttribute(3, children); }}

KidTabType.java

package com.test.object;import java.sql.SQLException;import java.sql.Connection;import oracle.jdbc.OracleTypes;import oracle.sql.ORAData;import oracle.sql.ORADataFactory;import oracle.sql.Datum;import oracle.sql.ARRAY;import oracle.sql.ArrayDescriptor;import oracle.jpub.runtime.MutableArray;public class KidTabType implements ORAData, ORADataFactory{  public static final String _SQL_NAME = "TEST_USER.KID_TAB";  public static final int _SQL_TYPECODE = OracleTypes.ARRAY;  MutableArray _array;private static final KidTabType _KidTabTypeFactory = new KidTabType();  public static ORADataFactory getORADataFactory()  { return _KidTabTypeFactory; }  /* constructors */  public KidTabType()  {    this((KidType[])null);  }  public KidTabType(KidType[] a)  {    _array = new MutableArray(2002, a, KidType.getORADataFactory());  }  /* ORAData interface */  public Datum toDatum(Connection c) throws SQLException  {    return _array.toDatum(c, _SQL_NAME);  }  /* ORADataFactory interface */  public ORAData create(Datum d, int sqlType) throws SQLException  {    if (d == null) return null;     KidTabType a = new KidTabType();    a._array = new MutableArray(2002, (ARRAY) d, KidType.getORADataFactory());    return a;  }  public int length() throws SQLException  {    return _array.length();  }  public int getBaseType() throws SQLException  {    return _array.getBaseType();  }  public String getBaseTypeName() throws SQLException  {    return _array.getBaseTypeName();  }  public ArrayDescriptor getDescriptor() throws SQLException  {    return _array.getDescriptor();  }  /* array accessor methods */  public KidType[] getArray() throws SQLException  {    return (KidType[]) _array.getObjectArray(      new KidType[_array.length()]);  }  public KidType[] getArray(long index, int count) throws SQLException  {    return (KidType[]) _array.getObjectArray(index,      new KidType[_array.sliceLength(index, count)]);  }  public void setArray(KidType[] a) throws SQLException  {    _array.setObjectArray(a);  }  public void setArray(KidType[] a, long index) throws SQLException  {    _array.setObjectArray(a, index);  }  public KidType getElement(long index) throws SQLException  {    return (KidType) _array.getObjectElement(index);  }  public void setElement(KidType a, long index) throws SQLException  {    _array.setObjectElement(a, index);  }}

KidType.java

package com.test.object;import java.sql.SQLException;import java.sql.Connection;import oracle.jdbc.OracleTypes;import oracle.sql.ORAData;import oracle.sql.ORADataFactory;import oracle.sql.Datum;import oracle.sql.STRUCT;import oracle.jpub.runtime.MutableStruct;public class KidType implements ORAData, ORADataFactory{  public static final String _SQL_NAME = "TEST_USER.KID";  public static final int _SQL_TYPECODE = OracleTypes.STRUCT;  protected MutableStruct _struct;  protected static int[] _sqlType =  { 12,12,4 };  protected static ORADataFactory[] _factory = new ORADataFactory[3];  protected static final KidType _KidTypeFactory = new KidType();  public static ORADataFactory getORADataFactory()  { return _KidTypeFactory; }  /* constructors */  protected void _init_struct(boolean init)  { if (init) _struct = new MutableStruct(new Object[3], _sqlType, _factory); }  public KidType()  { _init_struct(true); }  public KidType(String firstName, String lastName, Integer age) throws SQLException  { _init_struct(true);    setFirstName(firstName);    setLastName(lastName);    setAge(age);  }  /* ORAData interface */  public Datum toDatum(Connection c) throws SQLException  {    return _struct.toDatum(c, _SQL_NAME);  }  /* ORADataFactory interface */  public ORAData create(Datum d, int sqlType) throws SQLException  { return create(null, d, sqlType); }  protected ORAData create(KidType o, Datum d, int sqlType) throws SQLException  {    if (d == null) return null;     if (o == null) o = new KidType();    o._struct = new MutableStruct((STRUCT) d, _sqlType, _factory);    return o;  }  /* accessor methods */  public String getFirstName() throws SQLException  { return (String) _struct.getAttribute(0); }  public void setFirstName(String firstName) throws SQLException  { _struct.setAttribute(0, firstName); }  public String getLastName() throws SQLException  { return (String) _struct.getAttribute(1); }  public void setLastName(String lastName) throws SQLException  { _struct.setAttribute(1, lastName); }  public Integer getAge() throws SQLException  { return (Integer) _struct.getAttribute(2); }  public void setAge(Integer age) throws SQLException  { _struct.setAttribute(2, age); }}

LeaderType.java

package com.test.object;import java.sql.SQLException;import java.sql.Connection;import oracle.jdbc.OracleTypes;import oracle.sql.ORAData;import oracle.sql.ORADataFactory;import oracle.sql.Datum;import oracle.sql.STRUCT;import oracle.jpub.runtime.MutableStruct;public class LeaderType implements ORAData, ORADataFactory{  public static final String _SQL_NAME = "TEST_USER.LEADER";  public static final int _SQL_TYPECODE = OracleTypes.STRUCT;  protected MutableStruct _struct;  protected static int[] _sqlType =  { 2,12,12,4,93,2002 };  protected static ORADataFactory[] _factory = new ORADataFactory[6];  static  {    _factory[5] = ManagerType.getORADataFactory();  }  protected static final LeaderType _LeaderTypeFactory = new LeaderType();  public static ORADataFactory getORADataFactory()  { return _LeaderTypeFactory; }  /* constructors */  protected void _init_struct(boolean init)  { if (init) _struct = new MutableStruct(new Object[6], _sqlType, _factory); }  public LeaderType()  { _init_struct(true); }  public LeaderType(java.math.BigDecimal id, String firstName, String lastName, Integer age, java.sql.Timestamp hireDtstamp, ManagerType boss) throws SQLException  { _init_struct(true);    setId(id);    setFirstName(firstName);    setLastName(lastName);    setAge(age);    setHireDtstamp(hireDtstamp);    setBoss(boss);  }  /* ORAData interface */  public Datum toDatum(Connection c) throws SQLException  {    return _struct.toDatum(c, _SQL_NAME);  }  /* ORADataFactory interface */  public ORAData create(Datum d, int sqlType) throws SQLException  { return create(null, d, sqlType); }  protected ORAData create(LeaderType o, Datum d, int sqlType) throws SQLException  {    if (d == null) return null;     if (o == null) o = new LeaderType();    o._struct = new MutableStruct((STRUCT) d, _sqlType, _factory);    return o;  }  /* accessor methods */  public java.math.BigDecimal getId() throws SQLException  { return (java.math.BigDecimal) _struct.getAttribute(0); }  public void setId(java.math.BigDecimal id) throws SQLException  { _struct.setAttribute(0, id); }  public String getFirstName() throws SQLException  { return (String) _struct.getAttribute(1); }  public void setFirstName(String firstName) throws SQLException  { _struct.setAttribute(1, firstName); }  public String getLastName() throws SQLException  { return (String) _struct.getAttribute(2); }  public void setLastName(String lastName) throws SQLException  { _struct.setAttribute(2, lastName); }  public Integer getAge() throws SQLException  { return (Integer) _struct.getAttribute(3); }  public void setAge(Integer age) throws SQLException  { _struct.setAttribute(3, age); }  public java.sql.Timestamp getHireDtstamp() throws SQLException  { return (java.sql.Timestamp) _struct.getAttribute(4); }  public void setHireDtstamp(java.sql.Timestamp hireDtstamp) throws SQLException  { _struct.setAttribute(4, hireDtstamp); }  public ManagerType getBoss() throws SQLException  { return (ManagerType) _struct.getAttribute(5); }  public void setBoss(ManagerType boss) throws SQLException  { _struct.setAttribute(5, boss); }}

ManagerType.java

package com.test.object;import java.sql.SQLException;import java.sql.Connection;import oracle.jdbc.OracleTypes;import oracle.sql.ORAData;import oracle.sql.ORADataFactory;import oracle.sql.Datum;import oracle.sql.STRUCT;import oracle.jpub.runtime.MutableStruct;public class ManagerType implements ORAData, ORADataFactory{  public static final String _SQL_NAME = "TEST_USER.MANAGER";  public static final int _SQL_TYPECODE = OracleTypes.STRUCT;  protected MutableStruct _struct;  protected static int[] _sqlType =  { 2,12,12,4,1 };  protected static ORADataFactory[] _factory = new ORADataFactory[5];  protected static final ManagerType _ManagerTypeFactory = new ManagerType();  public static ORADataFactory getORADataFactory()  { return _ManagerTypeFactory; }  /* constructors */  protected void _init_struct(boolean init)  { if (init) _struct = new MutableStruct(new Object[5], _sqlType, _factory); }  public ManagerType()  { _init_struct(true); }  public ManagerType(java.math.BigDecimal id, String firstName, String lastName, Integer age, String gender) throws SQLException  { _init_struct(true);    setId(id);    setFirstName(firstName);    setLastName(lastName);    setAge(age);    setGender(gender);  }  /* ORAData interface */  public Datum toDatum(Connection c) throws SQLException  {    return _struct.toDatum(c, _SQL_NAME);  }  /* ORADataFactory interface */  public ORAData create(Datum d, int sqlType) throws SQLException  { return create(null, d, sqlType); }  protected ORAData create(ManagerType o, Datum d, int sqlType) throws SQLException  {    if (d == null) return null;     if (o == null) o = new ManagerType();    o._struct = new MutableStruct((STRUCT) d, _sqlType, _factory);    return o;  }  /* accessor methods */  public java.math.BigDecimal getId() throws SQLException  { return (java.math.BigDecimal) _struct.getAttribute(0); }  public void setId(java.math.BigDecimal id) throws SQLException  { _struct.setAttribute(0, id); }  public String getFirstName() throws SQLException  { return (String) _struct.getAttribute(1); }  public void setFirstName(String firstName) throws SQLException  { _struct.setAttribute(1, firstName); }  public String getLastName() throws SQLException  { return (String) _struct.getAttribute(2); }  public void setLastName(String lastName) throws SQLException  { _struct.setAttribute(2, lastName); }  public Integer getAge() throws SQLException  { return (Integer) _struct.getAttribute(3); }  public void setAge(Integer age) throws SQLException  { _struct.setAttribute(3, age); }  public String getGender() throws SQLException  { return (String) _struct.getAttribute(4); }  public void setGender(String gender) throws SQLException  { _struct.setAttribute(4, gender); }}





0 0
原创粉丝点击