Generate Database Objects

Note: This document is recognized for including obsolete content and is due for being updated. IFS/Design and Rational Rose are no longer used in development of IFS Applications 8. IFS Windows Client and IFS Client Developer are not in use.

The IFS/Design tool will, from the definitions in the model file, generate an Oracle view and packages (PL/SQL). Each LU in the model file will be converted into an Oracle view and a corresponding Oracle package. It is possible to add more views and packages to the LU once it's been generated, but the default is to have one view and one package.

The view is used in queries from the client. According to the query conditions the client will call the view in the database to receive the selected objects for the LU (see LU view structure ).
The package is used in all business logic called from the client. According to changes or checks the client will call the package methods. (See LU Package structure).

Two template files are used in conjunction with the Rose model to create the database objects. The template files include stubs for all standard operations. There are also a number of placeholders corresponding to different code fragments (e.g. Insert and Update statements). IFS/Design combines the templates with code generated from the model to create the actual views and packages representing the different LUs.

Contents

LU attributes

The LU includes all attributes defined in the Rational Rose model file. Some attributes are private and some are public. A public attribute will lead to a public Get method in the package specification of the LU. For the internal use the LU will also include the standard attributes Objid and Objversion. If there is a state machine for the corresponding class, the attributes Objstate, Objevents and State will be added to support this.

LU View structure

The LU view is created with all attributes in a logical unit - including objid, objversion and if necessary objstate, objevents and state.

Example

This is the definition of the view for the LU DemoOrder.

CREATE OR REPLACE VIEW DEMO_ORDER AS
SELECT
      company_id     company_id,
      order_id       order_id, 
      order_date     order_date,
      delivery_date  delivery_date,
      discount       discount,
      comments       comments,
      customer_id    customer_id,
      substrb(Demo_Delivery_Type_API.Decode(delivery_type),1,200) delivery_type,
      delivery_type  delivery_type_db,
      &OBJID         objid,
      &OBJVERSION    objversion,
      &OBJSTATE      objstate,
      &OBJEVENTS     objevents,
      &STATE         state
FROM demo_order_tab
WITH read only;

LU Relations

The table below describes the principles of how the connections in the design (associations between classes) are converted into Oracle PL/SQL code.

Connection - specification  Description
Aggregate - unspecified containment A parent key will be generated in the referenced LU.
Note: This is equivalent to a Has relation in Booch.
Aggregate - by value This will create a duplicate of the referenced class as part of the referencing class. If the referenced class is an instantiated class a single attribute is generated to represent this and the Encode/Decode functions will be used in communication with the server. Two attributes will be added to the view, the client value will be accompanied by the actual database value to speed up queries on IID's.
Note: This is equivalent to a has by value relationship in Booch.
Navigable A foreign key will be generated in the referencing LU.
Association with link class Parent keys referencing both associated classes will be generated in the link class.

LU Package structure

The LU package is created to perform all operations on a single object of the LU. The package is separated in four sections of procedures and functions and methods will be sorted accordingly.

See Template file contents for examples of procedures in the different sections.

Code generation and template file contents

There are several procedures and functions generated from IFS/Design. The code generating part is associated with the LU template files. Two sets of template files (one in older versions) are provided in Foundation1. Depending on the Foundation1 version those files are named:

Template Type Older Foundation1 versions 2.1.3 and later in the 2.1 track 2.2.1 and later
Older template, not performance optimized Template.api
Template.apy
Template.api
Template.apy
TemplateOld.api
TemplateOld.apy
Performance optimized template   TemplatePerformance.api
TemplatePerformance.apy
Template.api
Template.apy

IFS/Design generates different sets of methods depending on if the template is performance optimized or not. The code generated from the performance optimized templates minimizes execution time when running the application.

Major differences between optimized and not optimized templates are in the implementation section. Code generated from performance optimized templates works with tables instead of views, so the datatype &VIEW%ROWTYPE for LU record has been replaced with &TABLE%ROWTYPE. To see what methods are generated from Design see the following list:

Implementation, not performance optimized

Method Description
Lock___ Client-support to lock a specific instance of the logical unit.
Get_Record___ Get LU-record from the database with a specified object identity.
Get_Instance___ Get LU-record from the database with specified key columns.
Check_Exist___ Check if a specific LU-instance already exists in the database.
Get_Objversion___ Get the current OBJVERSION for a specific LU-instance.
Prepare_Insert___ Set all default values for a new instance of this logical unit by calling procedure Add_To_Attr.
Unpack_Check_Insert___ Unpack the attribute list, check all attributes from the client and generate all default values before creation of the new object.
Insert___ Insert a new LU-instance into the database and return the values for OBJID and OBJVERSION.
Unpack_Check_Update___ Unpack the attribute list, check all attributes from the client and generate all default values before modifying the object.
Update___ Update an existing LU-instance in the database and return the new OBJVERSION.
Check_Delete___ Checks whether a specific LU-record may be removed or not. The procedure should check business rules like attribute values as well as database constraints (defined or not).
Delete___ Deletion of the specific LU-object from the database.

The following implementation methods are generated if the LU has a state machine. Those methods should normally not be changed.

Method Description
Finite_State_Machine___ Implementation of the state machine or redirect call to separate Finite State Machine Package if there is one.
Finite_State_Add_To_Attr___ Adds the current state and allowed events to the attribute string.
Finite_State_Init___ Sets the initial finite state indicator for an existing LU-instance and processes any automatic events.
Finite_State_Set___ Sets the state machine to a specified state. Should not be used in business logic. The whole idea behind a state machine is that all state changes occur along transitions as a response to an event.

Implementation, performance optimized

Method Description
Lock_By_Id___ Client-support to lock a specific instance of the logical unit. The record is fetched and returned at the same time.
Lock_By_Keys___ For locking records from the business logic using key columns instead of OBJID. The record is fetched and returned at the same time. The lock is made using the WAIT option.
Get_Object_By_Id___ Get LU-record from the database with a specified object identity.
Get_Object_By_Keys___ Get LU-record from the database with specified key columns.
Check_Exist___ Check if a specific LU-instance already exists in the database.
Get_Id_Version_By_Keys___ Get the current OBJID and OBJVERSION for a specific LU-instance.
Prepare_Insert___ Set all default values for a new instance of this logical unit by calling procedure Add_To_Attr.
Unpack_Check_Insert___ Unpack the attribute list, check all attributes from the client and generate all default values before creation of the new object.
Insert___ Insert a new LU-instance into the database and return the values for OBJID and OBJVERSION.
Unpack_Check_Update___ Unpack the attribute list, check all attributes from the client and generate all default values before modifying the object.
Update___ Update an existing LU-instance in the database and return the new OBJVERSION. Normally update is performed using OBJID, but by setting the argument by_keys_ to TRUE the update can be performed using key columns instead.
Check_Delete___ Checks whether a specific LU-record may be removed or not. The procedure should check business rules like attribute values as well as database constraints (defined or not).
Delete___ Deletion of the specific LU-object from the database.


The following implementation methods are generated if the LU has a state machine:

Method Description
Finite_State_Machine___ Implementation of the state machine or redirect call to separate Finite State Machine Package if there is one. Should not be tampered with.
Finite_State_Add_To_Attr___ Adds the current state and allowed events to the attribute string.
Finite_State_Init___ Sets the initial finite state indicator for an existing LU-instance and processes any automatic events.
Finite_State_Set___ Sets the state machine to a specified state. Should not be used in business logic. The whole idea behind a state machine is that all state changes occur along transitions as a response to an event.

Private

The private methods Lock__, New__, Modify__ and Remove__ are interfaces to the client. Avoid using those methods when writing business logic. Changes should be put in the implementation methods instead.


 
Method Description
Lock__ Client-support to lock a specific instance of the logical unit.
New__ Client-support interface to create LU instances.
 
Action Description
'PREPARE' Default values and handle of information to client. The default values are set in procedure Prepare_Insert___.
'CHECK' Check all attributes before creating new object and handle of information to client. The attribute list is unpacked, checked and prepared (defaults) in procedure Unpack_Check_Insert___.
'DO' Creation of new instances of the logical unit and handle of information to client. The attribute list is unpacked, checked and prepared (defaults) in procedure Unpack_Check_Insert___ before calling procedure Insert___.
Modify__ Client-support interface to modify attributes for LU instances.
 
Action Description
'CHECK' Check all attributes before modifying an existing object and handle of information to client. The attribute list is unpacked, checked and prepared(defaults) in procedure Unpack_Check_Update___.
'DO' Modification of an existing instance of the logical unit. The procedure unpacks the attributes, checks all values before procedure Update___ is called.
Remove__ Client-support interface to remove LU instances.
 
Action Description
'CHECK' Check whether a specific LU-instance may be removed or not. The procedure fetches the complete record by calling procedure Get_Record___. Then the check is made by calling procedure Check_Delete___.
'DO' Remove an existing instance of the logical unit. The procedure fetches the complete LU-record, checks for a delete and then deletes the record by calling procedure Delete___.

The following private methods are generated if the LU has a state machine.

Method Description
Finite_State_Decode__ Returns the client equivalent for any database representation of a state name = objstate.
Finite_State_Encode__ Returns the database equivalent for any client representation of a state name = state.
Enumerate_States__ Returns a list of all possible finite states in client terminology.
Finite_State_Events__ Returns a list of allowed events for a given state. Note: Regardless of conditions if not otherwise encoded.
Enumerate_Events__ Returns a list of all possible events.

Protected

No protected methods will be generated.

Public

Method Description
Exist Checks if given pointer (e.g. primary key) to an instance of this logical unit exists. If not an exception will be raised.
 
Init Dummy procedure that can be called at database startup to ensure that this package is loaded into memory for performance reasons only.

The following public methods are generated for IID's:

Method Description
Encode Returns the client representation of a domain value encoded in the current client language.
Decode Returns the stored database representation of a domain value given the client encoded value in current language.
Get_Db_Value Returns the database representation a domain value given its index.
Get_Client_Value Returns the client representation a domain value given its index.

In addition to these, Get-methods will be generated for all public attributes in a LU. If the performance optimized template is used, a method called Get will be generated as well. This method returns the value of all the public attributes in the current LU. The return type of this function is Public_Rec which is a record defined in the package specification of the current LU. Here is an example how the public Get-method in the Customer LU can be used in the Order LU:

FUNCTION Verify_Order___( order_no_ IN NUMBER ) RETURN BOOLEAN
IS
order_rec_ &TABLE%ROWTYPE;
customer_rec_ Customer_API.Public_Rec; -- this will contain all
-- the public attributes
-- from LU Customer
BEGIN    order_rec_ := Get_Object_By_Id___(order_no_);    customer_rec_ := Customer_API.Get(order_rec_.customer_id);    RETURN (order_rec_.status = 'Ok' and customer_rec_.valid = TRUE            and customer_rec_.credit_limit > 0)
END Cancel;