< Prev - Examples - Next >

Rowtype

Example Description

Important Notes !

Package Specification

The package 'ROWTYPE_DEMO' defines a function with one parameter of Table 'ROWTYPE_EXAMPLE%ROWTYPE' as input and output value.
PL/SQL Package Specification : ROWTYPE_DEMO
create or replace package rowtype_demo
as
/**
 * Rowtype Demo.
 */

/**
 * Input and output parameter of type rowtype.
 *
 * @param io_rec Input parameter record value is modified and returned.
 */
procedure modify_record(io_rowtype_example in out rowtype_example%rowtype);

end rowtype_demo;

Package Body

The package 'ROWTYPE_DEMO' implements a function with one parameter of Table 'ROWTYPE_EXAMPLE%ROWTYPE' as input and output value.
PL/SQL Package Body : ROWTYPE_DEMO
create or replace package body rowtype_demo
as

procedure modify_record(io_rowtype_example in out rowtype_example%rowtype)
is
begin
  io_rowtype_example.n  := io_rowtype_example.n + 1;
  io_rowtype_example.f  := io_rowtype_example.f + 1;
  io_rowtype_example.ts := io_rowtype_example.ts + 1;
  io_rowtype_example.d  := io_rowtype_example.d + 1;
  io_rowtype_example.v  := io_rowtype_example.v || '1';
end modify_record;

end rowtype_demo;

Factory API : Calling the PL/SQL package

Using the static factory to get the remote service.
Java Calling Class : RowtypeDemoFactoryApi.java
package plsql_workbench_examples.factoryapi;

import java.sql.Date;
import java.sql.Timestamp;

import factory.ExamplesRPCFactory;
import service.RowtypeDemoService;
import transferobject.RowtypeExample;

public class RowtypeDemoFactoryApi {
  public static void main(String[] args) {
    try {
      // get the service
      RowtypeDemoService service = ExamplesRPCFactory.getRowtypeDemoService();

      // creating some test data
      RowtypeExample rowtype = new RowtypeExample();
      rowtype.d = new Date(System.currentTimeMillis());
      rowtype.f = 3.14;
      rowtype.n = 4711;
      rowtype.v = "some kind of string";
      rowtype.ts = new Timestamp(System.currentTimeMillis());

      // print record field values before call
      System.out.format("before : d:%1$tD   f:%2$f   n:%3$d   s:%4$s   ts:%5$tD %5$tT%n",
                        rowtype.d,
                        rowtype.f,
                        rowtype.n,
                        rowtype.v,
                        rowtype.ts);

      // call the stored procedure
      rowtype = service.modifyRecord(rowtype);

      // print record field values after call
      System.out.format("after : d:%1$tD   f:%2$f   n:%3$d   s:%4$s   ts:%5$tD %5$tT%n",
                        rowtype.d,
                        rowtype.f,
                        rowtype.n,
                        rowtype.v,
                        rowtype.ts);
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }
}

Spring API : Calling the PL/SQL package

Using Spring annotation to inject the service and call the remote service.
Java Calling Class : RowtypeDemoSpringApi.java
package plsql_workbench_examples.springapi;

import java.sql.Date;
import java.sql.Timestamp;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.stereotype.Component;

import service.RowtypeDemoService;
import transferobject.RowtypeExample;

@Component
public class RowtypeDemoSpringApi {
  @Autowired
  private RowtypeDemoService rowtypeDemoService;

  public static void main(String[] args) {
    // Register Spring Beans, Spring Context and call demo method 
    try (GenericApplicationContext ctx = BaseSpringConfig.getCtx(RowtypeDemoSpringApi.class)) {
      ctx.getBean(RowtypeDemoSpringApi.class).runDemo();
    }
  }

  private void runDemo() {
    try {
      // creating some test data
      RowtypeExample rowtype = new RowtypeExample();
      rowtype.setD(new Date(System.currentTimeMillis()));
      rowtype.setF(3.14);
      rowtype.setN(4711);
      rowtype.setV("some kind of string");
      rowtype.setTs(new Timestamp(System.currentTimeMillis()));

      // print record field values before call
      System.out.format("before : d:%1$tD   f:%2$f   n:%3$d   s:%4$s   ts:%5$tD %5$tT%n",
                        rowtype.getD(),
                        rowtype.getF(),
                        rowtype.getN(),
                        rowtype.getV(),
                        rowtype.getTs());

      // call the stored procedure
      rowtype = rowtypeDemoService.modifyRecord(rowtype);

      // print record field values after call
      System.out.format("after : d:%1$tD   f:%2$f   n:%3$d   s:%4$s   ts:%5$tD %5$tT%n",
                        rowtype.getD(),
                        rowtype.getF(),
                        rowtype.getN(),
                        rowtype.getV(),
                        rowtype.getTs());
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }
}

< Prev - Examples - Next >