< Prev - Examples - Next >

Bulk Processing - Insert Rows Using Collections of Rowtypes

Example Description

Create Table Statement

Table : BULK_PROCESSING_TABLE
create table bulk_processing_table
(
n    number not null,
d    date not null,
s    varchar2(100) not null
);

PL/SQL Package Specification

PL/SQL Package Specification : BULK_ROWTYPE
create or replace package bulk_rowtype
/**
 * Bulk collection demo package demonstration of collection of Rowtype elements.
 */
as

type table_rowtype is table of bulk_processing_table%rowtype;

/**
 * Bulk collection demo with Rowtype element.
 * 
 * @param i_table_rowtype List of record elements of type 'BULK_PROCESSING_TABLE%ROWTYPE' to insert into table 'BULK_PROCESSING_TABLE'.  
 */
procedure doit
(
  i_table_rowtype   in table_rowtype 
);

end bulk_rowtype;

PL/SQL Package Implementation

PL/SQL Package Body : BULK_ROWTYPE
create or replace package body bulk_rowtype
as

/**
 * Bulk collection demo with Rowtype element.
 * 
 * @param i_table_rowtype List of record elements of type 'BULK_PROCESSING_TABLE%ROWTYPE' to insert into table 'BULK_PROCESSING_TABLE'.  
 */
procedure doit
(
  i_table_rowtype   in table_rowtype 
)
is
begin
  forall i in 1..i_table_rowtype.count
    insert into bulk_processing_table
      (n,d,s)
      values
      (i_table_rowtype(i).n, i_table_rowtype(i).d, i_table_rowtype(i).s);
end doit;

end bulk_rowtype;

Factory API : Calling the PL/SQL package

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

import java.sql.Date;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import factory.ExamplesRPCFactory;
import plsql_workbench_examples.timer.TimerCounter;
import service.BulkRowtypeService;
import transferobject.BulkProcessingTable;

public class BulkCollectionRowtypeFactoryApi {
  private final static int ELEMENTS = 50000;

  public static void main(String[] args) {
    try {
      // getting the service
      BulkRowtypeService service = ExamplesRPCFactory.getBulkRowtypeService();

      // generating 50000 elements to transfer to the stored procedure 
      List<BulkProcessingTable> list = new ArrayList<>();
      for (int i = 0; i < ELEMENTS; i++) {
        BulkProcessingTable o = new BulkProcessingTable();
        o.d = new Date(System.currentTimeMillis() + (long) (Math.random() * Integer.MAX_VALUE));
        o.s = UUID.randomUUID().toString();
        o.n = (int) (Math.random() * Integer.MAX_VALUE);
        list.add(o);
      }

      // timer to check the throughput
      TimerCounter tc = new TimerCounter();

      // calling the stored procedure
      service.doit(list);

      // print out throughput
      System.out.println(tc.perSecond("collection of rowtype element bulk performance", ELEMENTS));
    }
    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 : BulkCollectionRowtypeSpringApi.java
package plsql_workbench_examples.springapi;

import java.sql.Date;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

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

import plsql_workbench_examples.timer.TimerCounter;
import service.BulkRowtypeService;
import transferobject.BulkProcessingTable;

@Component
public class BulkCollectionRowtypeSpringApi {
  private final static int   ELEMENTS = 50000;

  @Autowired
  private BulkRowtypeService bulkRowtypeService;

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

  private void runDemo() {
    try {
      // generating 50000 elements to transfer to the stored procedure 
      List<BulkProcessingTable> list = new ArrayList<>();
      for (int i = 0; i < ELEMENTS; i++) {
        BulkProcessingTable o = new BulkProcessingTable();
        o.setD(new Date(System.currentTimeMillis() + (long) (Math.random() * Integer.MAX_VALUE)));
        o.setS(UUID.randomUUID().toString());
        o.setN((int) (Math.random() * Integer.MAX_VALUE));
        list.add(o);
      }

      // timer to check the throughput
      TimerCounter tc = new TimerCounter();

      // calling the stored procedure
      bulkRowtypeService.doit(list);

      // print out throughput
      System.out.println(tc.perSecond("collection of rowtype element bulk performance", ELEMENTS));
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }
}

< Prev - Examples - Next >