< Prev - Examples - Next >

Scalar Types Returning A Transfer Object

Use Case

Fetch data from a single row.

Example Description

PL/SQL Procedure : SERVER_INFO
create or replace procedure server_info
(
  i_diff        in   number,
  o_date        out  date,
  o_timestamp   out  timestamp,
  o_instance    out  varchar2,
  o_db_version  out  number,
  o_db_release  out  number
)
/**
 * Database server information.
 *
 * @param i_diff Offset of date and timestamp value.
 * @param o_date System date plus i_diff offset.
 * @param o_timestamp System timestamp plus i_diff offset.
 * @param o_instance Instance information.
 * @param o_db_version Oracle version.
 * @param o_db_release Oracle release.
 */
is
begin
  o_date := sysdate + i_diff;
  o_timestamp := systimestamp - i_diff;
  select sys_context('USERENV','INSTANCE_NAME')
    into o_instance
    from dual;
  o_db_version := DBMS_DB_VERSION.VERSION;
  o_db_release := DBMS_DB_VERSION.RELEASE;
end server_info;
Java Transfer Object : ServerInfoTO.java
/*
 * This file is generated by PL/SQL Enterprise Workbench Connector Builder.
 * PL/SQL Enterprise Workbench Copyright (c) Jan Richter, Germany, Hamburg, 2015-2018. 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;

/**
 * Transfer object returned from PL/SQL procedure <em>SERVER_INFO</em>.<p>
 */
final public class ServerInfoTO implements Serializable {
  private static final long serialVersionUID = 1L;

  /** System date plus iDiff offset. */ 
  public Date oDate;

  /** System timestamp plus iDiff offset. */ 
  public Timestamp oTimestamp;

  /** Instance information. */ 
  public String oInstance;

  /** Oracle version. */ 
  public int oDbVersion;

  /** Oracle release. */ 
  public int oDbRelease;
}
Java Calling Class : ServerInfo.java
package plsql_workbench_examples;

import factory.JavaEeRPCFactory;
import service.ServerInfoService;
import transferobject.ServerInfoTO;

public class ServerInfo {
  public static void main(String[] args) {
    try {
      int diff = 10;

      // get the service
      ServerInfoService service = JavaEeRPCFactory.getServerInfoService();

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

      // print server information
      System.out.println("database date(+" + diff + "):" + info.oDate);
      System.out.println("database timestamp(-" + diff + "):" + info.oTimestamp);
      System.out.println("database instance name:" + info.oInstance);
      System.out.println("database version:" + info.oDbVersion + "." + info.oDbRelease);
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }
}