< Prev - Examples - Next >

Collections Of Objects

Example Description

Important Notes !

Object Type Specification : BULK_PROCESSING_TABLE
create or replace type col_object force as object (
  d           date,
  ts          timestamp,
  s           varchar2(100)
);
Collection Table Type : TABLE_OF_COL_OBJECT
create or replace type table_of_col_object as table of col_object;
Collection Table Type : BULK_TABLE_OBJECT
create or replace type bulk_table_object force as table of bulk_object;
PL/SQL Procedure : COLLECTIONS_OF_OBJECTS
create or replace procedure collections_of_objects
(
  i_delta_d         in    number,
  i_delta_ts        in    number,
  i_col_objects     in    table_of_col_object,
  o_col_objects     out   table_of_col_object
)
is
begin
  -- initialize output collection
  o_col_objects := table_of_col_object();

  -- append elements to collection
  for i in 1..i_col_objects.count loop
    o_col_objects.extend();
    o_col_objects(i) := col_object(i_col_objects(i).d + i_delta_d + i, i_col_objects(i).ts + i_delta_ts + i, i_col_objects(i).s || ' - ' || DBMS_RANDOM.string('A',10));
  end loop;
end collections_of_objects;
Java Calling Class : CollectionsOfObjects.java
package plsql_workbench_examples;

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

import factory.ExamplesRPCFactory;
import service.CollectionsOfObjectsService;
import transferobject.ColObject;

public class CollectionsOfObjects {
  public static void main(String[] args) {
    try {
      // get the service
      CollectionsOfObjectsService service = ExamplesRPCFactory.getCollectionsOfObjectsService();

      // create some test data
      List<ColObject> objectList = new ArrayList<ColObject>();
      for (int i = 0; i < 3; i++) {
        ColObject o = new ColObject();
        o.d = new Date(System.currentTimeMillis());
        o.s = "init value";
        o.ts = new Timestamp(System.currentTimeMillis());
        objectList.add(o);
      }

      // call the service and receive result list of transfer objects
      List<ColObject> resultList = service.call(3, 7, objectList);

      // printing the result list
      for (ColObject o : resultList) {
        System.out.println(String.format("d[%s] ts[%s] s[%s]", o.d, o.ts, o.s));
      }
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }
}