37.38 PARSE_REFETCH_RESPONSE Function

This function parses the response from a "DML row refetch." A "row refetch" is used for lost update detection in order to verify that nobody else changed the row. To use this function, the REST Data Source must have a "Fetch Single Row" database operation defined.

Syntax

APEX_PLUGIN_UTIL.PARSE_REFETCH_RESPONSE (
    p_web_source_operation IN apex_plugin.t_web_source_operation,
    p_web_source           IN apex_plugin.t_web_source,
    p_values_context       IN apex_exec.t_context,
    --
    p_response             IN CLOB )
RETURN apex_exec.t_context;

Parameters

Table 37-57 PARSE_REFETCH_RESPONSE Parameters

Parameter Description
p_web_source_operation REST Data Source operation (Plug-In) meta data.
p_web_source REST Data Source (Plug-In) meta data.
p_response REST response to parse.
p_values_context Values context, needed for DML column definitions.

Returns

Table 37-58 PARSE_REFETCH_RESPONSE Returns

Parameter Description

*

APEX_EXEC "Values" context object for the plug-in developer to retrieve the checksum or column values.

Example

The following example demonstrates how to perform a "refetch" operation within the Plug-In DML function for a given row to be updated and compare checksums in order to detect lost updates.

apex_plugin_util.parse_refetch_response (
  p_plugin     in            apex_plugin.t_plugin,
  p_web_source in            apex_plugin.t_web_source,
  p_params     in            apex_plugin.t_web_source_dml_params,
  p_result     in out nocopy apex_plugin.t_web_source_dml_result )
IS
  l_web_source_operation apex_plugin.t_web_source_operation;
  l_request_body         clob;
  l_response             clob;

  l_refetch_context      apex_exec.t_context;
  l_checksum             varchar2(32767);
  l_refetched_checksum   varchar2(32767);

BEGIN
  p_result.update_values_context := p_params.update_values_context;

  --
  -- this code performs a "refetch" operation for a row, in order to perform
  -- lost update detection. This happens before the actual DML.
  --
  IF p_web_source.operations.exists( apex_plugin.c_db_operation_fetch_row ) THEN

    l_web_source_operation := apex_plugin_util.get_web_source_operation(
      p_web_source       => p_web_source,
      p_db_operation     => apex_plugin.c_db_operation_fetch_row,
      p_preserve_headers => false,
      p_perform_init     => true );

    -- add some logic to add primary key values to the URL or as HTTP headers here
    -- PK values can be obtained from "p_params.update_values_context"

    apex_plugin_util.make_rest_request(
      p_web_source_operation => l_web_source_operation,
      p_request_body         => l_request_body,
      p_response             => l_response,
      p_response_parameters  => p_result.out_parameters );

    l_refetch_context := apex_plugin_util.parse_refetch_response(
      p_web_source_operation => l_web_source_operation,
      p_web_source           => p_web_source,
      p_response             => l_response,
      p_values_context       => p_params.update_values_context );

    IF apex_exec.next_row( p_context => l_refetch_context ) THEN

      l_checksum           := apex_exec.get_row_version_checksum( p_context => p_params.update_values_context );
      l_refetched_checksum := apex_exec.get_row_version_checksum( p_context => l_refetch_context );

      IF l_checksum != l_refetched_checksum THEN
        apex_exec.set_row_status(
          p_context  => p_result.update_values_context,
          p_sqlcode  => -20987,
          p_sqlerrm  => 'APEX.DATA_HAS_CHANGED' );
      END IF;
    END IF;
  END IF;

  -- continue with DML logic here ...

END plugin_dml;