Skip to content

Packing/Unpacking Attribute Strings

Attribute strings were the main mechanism used to transfer data from client to server in client frameworks. Sometimes, this mechanism is used to transfer data between server-to-server method calls as well. This has an overhead of packing data to an attribute string before the method call and unpacking data inside the caller method before performing operations on them. If this happens inside a loop, the overhead would be multiplied by the number of iterations.

A more efficient solution would be to use table records which eliminates the above mentioned overhead.

Example

Below method requires all the attributes needed for the new record as individual parameters. The parameters are then packed into an attribute string. The New__ method unpack, validates, and then inserts the record by calling the Unpack___, Check_Insert___ and Insert___ methods. This type of implementation often worsens the performance and also has other disadvantages, including a more complex code which harder to maintain and read.

PROCEDURE New_Unpack (
   company_    IN VARCHAR2,
   address_id_ IN VARCHAR2,
   address_    IN VARCHAR2,
--               ...,
   state_     IN VARCHAR2 )
IS
BEGIN
   -- pack the attr_
   Client_SYS.Clear_Attr(attr_);
   Client_SYS.Add_To_Attr('COMPANY', company_,  attr_);
   Client_SYS.Add_To_Attr('ADDRESS_ID', address_id_,   attr_);
   Client_SYS.Add_To_Attr('ADDRESS', address_, attr_);
   Client_SYS.Add_To_Attr('COUNTRY', country_, attr_);
   Client_SYS.Add_To_Attr('EAN_LOCATION', ean_location_, attr_);
   ....
   ....
   ....
   New__(info_, objid_, objversion_, attr_, 'DO');

END New_Unpack;

Solution

If table record is used as input, then additional overhead of packing data to an attribute string before the method call and unpacking data before performing operations can be mitigated. If business validation is needed you simply call the New___ method (which will call Check_Insert___, where validation is done).

PROCEDURE New_Unpack (
   company_    IN VARCHAR2,
   address_id_ IN VARCHAR2,
   address_    IN VARCHAR2,
--               ...,
   state_     IN VARCHAR2 )
IS
BEGIN   
   newrec_.company := company_;
   newrec_.address_id := address_id_; 
   newrec_.address := address_; 
   newrec_.country := country_; 
   newrec_.ean_location := ean_location_;
   ....
   ....
   ....
   New___(newrec_);   

END New_Unpack;

Validating the data is generally the recommended solution, but if validity of incoming data can be guaranteed then, all validations can be skipped and the Insert___method can be called direct. This will improve the performance even further.

PROCEDURE New_Unpack (
   company_    IN VARCHAR2,
   address_id_ IN VARCHAR2,
   address_    IN VARCHAR2,
--               ...,
   state_     IN VARCHAR2 )
IS
BEGIN   
   newrec_.company := company_;
   newrec_.address_id := address_id_; 
   newrec_.address := address_; 
   newrec_.country := country_; 
   newrec_.ean_location := ean_location_;
   ....
   ....
   ....
   Insert___(objid_, objversion_, newrec_, attr_); 

END New_Unpack;