Association - Generation specific to Oracle

 

Referential constraints

Referential constraints are mapped by the following instructions:

SQL89 CONSTRAINT ... FOREIGN KEY ... REFERENCES.

 

 

Parameterization

Referential constraint names can be parameterized using the SetForeignKeysNames J method which simply has to be redefined under a UML Profile.  The method’s parameters are as follows:

 

The ... parameter

represents ...

ComposedClassName

the name of the composed class

fkDest

the destination "foreign key"

fkOrigin

the origin "foreign key"

 

 

SetForeign-KeysNames method

// Default value for Oracle.

AssociationEnd:default#external#Code#RDB#DDL#Oracle#

   SetForeignKeysNames

      (in String ComposedClassName,

          inout String fkOrigin,

          inout String fkDest)

{

 

   String fkO;

   String fkD;

 

   fkO = SetTableName(ComposedClassName);

   fkD = SetTableName(ComposedClassName);

   fkO.concat("_OFK");

   fkD.concat("_DFK");

   fkOrigin = fkO;

   fkDest = fkD;

 

}  

// method SetForeignKeysNames

 

 

Mulitplicity constraints

The generation of tables for Oracle V8 uses triggers to map multiplicity constraints in associations.

 

Multiplicity constraints are checked after insertion by a trigger named TI_name of the table. However, Oracle cannot be used to generate an AFTER DELETE type trigger, able to manage minimum multiplicities during a deletion.

 

We will generate a multiplicity test through association orientation if the association is mutual with m-n multiplicity.

 

 

Example of multiplicity constraints

DDL generated for an association with the 0-5 multiplicity:

CREATE TRIGGER TI_role2_of_class

    BEFORE INSERT

    ON role2_of_class

    FOR EACH ROW

    DECLARE

        dummy INTEGER;

    BEGIN

        SELECT COUNT(*)

            INTO dummy

            FROM role2_of_class

            WHERE clef = :new.clef;

        IF NOT(dummy < 5)

            THEN raise_application_error(-20501,

                      'role2_of_class : May not insert element');

        END IF;

    END ;

/