Table function execution model for Java

For table functions written in Java™ and using PARAMETER STYLE DB2GENERAL, it is important to understand what happens at each point during the processing of a statement by the database manager.

The following table details this information for a typical table function. Covered are both the NO FINAL CALL and the FINAL CALL cases, assuming SCRATCHPAD in both cases.

Point in scan time NO FINAL CALL
LANGUAGE JAVA
SCRATCHPAD
FINAL CALL
LANGUAGE JAVA
SCRATCHPAD
Before the first OPEN for the table function
  • No calls.
  • Class constructor is called (means new scratchpad). UDF method is called with FIRST call.
  • Constructor initializes class and scratchpad variables. Method connects to Web server.
At each OPEN of the table function
  • Class constructor is called (means new scratchpad). UDF method is called with OPEN call.
  • Constructor initializes class and scratchpad variables. Method connect to Web server, and opens the scan for Web data.
  • UDF method is opened with OPEN call.
  • Method opens the scan for whatever Web data it wants. (Might be able to avoid reopen after a CLOSE reposition, depending on what is saved in the scratchpad.)
At each FETCH for a new row of table function data
  • UDF method is called with FETCH call.
  • Method fetches and returns next row of data, or EOT.
  • UDF method is called with FETCH call.
  • Method fetches and returns new row of data, or EOT.
At each CLOSE of the table function
  • UDF method is called with CLOSE call. close() method if it exists for class.
  • Method closes its Web scan and disconnects from the Web server. close() does not need to do anything.
  • UDF method is called with CLOSE call.
  • Method might reposition to the top of the scan, or close the scan. It can save any state in the scratchpad, which will persist.
After the last CLOSE of the table function
  • No calls.
  • UDF method is called with FINAL call. close() method is called if it exists for class.
  • Method disconnects from the Web server. close() method does not need to do anything.
Note:
  1. The term "UDF method" refers to the Java class method that implements the UDF. This is the method identified in the EXTERNAL NAME clause of the CREATE FUNCTION statement.