< Prev - Examples - Next >

Simple Object

This example is a simple demonstration how object types in stored procedures work and how they are handled by the JDBC driver and the Connector Builder.

Example Description

Important Notes !

Object Type Specification : SIMPLE_OBJECT
create or replace type simple_object force as object (
  d           date,
  ts          timestamp,
  instance    varchar2(100),
  db_version  number(9),
  db_release  number(9),
  constructor function simple_object(i_diff number) return self as result  
);
Object Type Specification : SIMPLE_OBJECT
create or replace type body simple_object
as
  constructor function simple_object(i_diff number)
    return self as result
  as
  begin
    self.d := sysdate + i_diff;
    self.ts := systimestamp - i_diff;
    select sys_context('USERENV','INSTANCE_NAME')
      into self.instance
      from dual;
    self.db_version := DBMS_DB_VERSION.VERSION;
    self.db_release := DBMS_DB_VERSION.RELEASE;
    return;
  end;
end;
PL/SQL Procedure : SERVER_INFO_SIMPLE_OBJECT
create or replace function server_info_simple_object
(
  i_diff 			in	 	number
)
return simple_object
is
begin
  return simple_object(i_diff);
end server_info_simple_object;
Java Transfer Object : SimpleObject.java
/*
 * This file is generated by PL/SQL Enterprise Workbench Connector Builder.
 * PL/SQL Enterprise Workbench Copyright (c) Jan Richter, Hamburg, Germany, 2015-2016. All rights reserved.
 *
 * THIS FILE IS NOT INTENDED TO BE MODIFIED - IT WILL BE OVERWRITTEN ON EVERY RUN OF THE CONNECTOR BUILDER
 */

package transferobject;

import java.io.Serializable;
import java.sql.Date;
import java.sql.Timestamp;

final public class SimpleObject implements Serializable {
  private static final long serialVersionUID = 1L;

  public Date d;
  public Timestamp ts;
  public String instance;
  public int dbVersion;
  public int dbRelease;
}
Java Calling Class : ServerInfoSimpleObject.java
package plsql_workbench_examples;

import factory.ExamplesRPCFactory;
import service.ServerInfoSimpleObjectService;
import transferobject.SimpleObject;

public class ServerInfoSimpleObject {
  public static void main(String[] args) {
    try {
      int diff = 10;
      
      // get the service
      ServerInfoSimpleObjectService service = ExamplesRPCFactory.getServerInfoSimpleObjectService();

      // calling the stored procedure, receiving a transfer object
      SimpleObject info = service.call(diff);

      // print server information
      System.out.println("database date(+" + diff + "):" + info.d);
      System.out.println("database timestamp(-" + diff + "):" + info.ts);
      System.out.println("database instance name:" + info.instance);
      System.out.println("database version:" + info.dbVersion + "." + info.dbRelease);
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }
}