18
© AtlanMod - [email protected] Extracting UML/OCL Integrity Constraints and Derived Types from Relational Databases Valerio Cosentino Salvador Martínez {valerio.cosentino, salvador.martinez}@mines-nantes.fr

Extracting UML/OCL Integrity Constraints and Derived Types from Relational Databases

Embed Size (px)

DESCRIPTION

Relational databases usually enforce relevant organizational business rules. This aspect is ignored by current database reverse engineering approaches which only focus on the extraction of the structural part of the conceptual schema. Other database elements like triggers, views, column constraints, etc. are not considered by those methods. As a result, the generated conceptual schema is incomplete since integrity constraints and derivation rules enforced by the database are not represented. In this sense, this paper extends existing approaches by enriching the generated (UML) conceptual schema with a set of OCL integrity constraints and derivation rules inferred from the database schema. Our method has been implemented in a prototype tool for the Oracle database management system.

Citation preview

Page 1: Extracting UML/OCL Integrity Constraints and Derived Types from Relational Databases

© AtlanMod - [email protected]

Extracting UML/OCL Integrity Constraints andDerived Types from Relational Databases

Valerio CosentinoSalvador Martínez

{valerio.cosentino, salvador.martinez}@mines-nantes.fr

Page 2: Extracting UML/OCL Integrity Constraints and Derived Types from Relational Databases

07/10/13 © AtlanMod - [email protected]

Outline

Introduction Approach overview Model Extraction Constraint Extraction Conclusion and future work

Page 3: Extracting UML/OCL Integrity Constraints and Derived Types from Relational Databases

07/10/13 © AtlanMod - [email protected]

Introduction

Relational databases play a key role in most organizations

They store relevant information according to:– Schema: data structure definitions and relations– Integrity constraints (declarative, operational):

implementation of organization policies/business rules

These constraints should evolve together with the organization policies

Page 4: Extracting UML/OCL Integrity Constraints and Derived Types from Relational Databases

07/10/13 © AtlanMod - [email protected]

Introduction

Discovering/understanding the business rules in a db is:– Time-consuming (querying/browsing the database) – Error-prone (manual analysis)– Tailored process (each SQL vendor offers slight

variations for the standard language) Model Driven Engineering offers:

– Homogeneous representation (schema + constraints)– Higher abstraction level (no SQL vendor specificities)– Automatation of repetitive activities (extraction of

schema and constraints)

Page 5: Extracting UML/OCL Integrity Constraints and Derived Types from Relational Databases

07/10/13 © AtlanMod - [email protected]

Approach overview

Model Extraction translates tables, relations and views into UML classes and associations

Constraint Extraction focuses on inferring the OCL expressions required to complement the UML model

Page 6: Extracting UML/OCL Integrity Constraints and Derived Types from Relational Databases

07/10/13 © AtlanMod - [email protected]

Model Extraction

Mappings:– Tables → classes– Views → derived classes– Columns → class's attributes– Database data types → UML data types

CHAR(n), VARCHAR2(n) → String Integer, Float, Date → Integer, Real, Date Number(precision, scale) → if precision = 0 Integer else Real

– Foreign keys → associations between classes– SQL queries → associations' cardinalities

Page 7: Extracting UML/OCL Integrity Constraints and Derived Types from Relational Databases

07/10/13 © AtlanMod - [email protected]

Model Extraction

Example: human resource database

Page 8: Extracting UML/OCL Integrity Constraints and Derived Types from Relational Databases

07/10/13 © AtlanMod - [email protected]

Constraint Extraction

Declarative constraints:– PRIMARY KEY– UNIQUE– NOT NULL– CHECK

Operational constraints:– Triggers: PL/SQL - SQL code automatically executed in

response to certain database events Key elements: SQL-to-OCL and PL/SQL-to-OCL

– they map SQL and PL/SQL constructs to OCL

Page 9: Extracting UML/OCL Integrity Constraints and Derived Types from Relational Databases

07/10/13 © AtlanMod - [email protected]

Declarative constraints

Declarative constraints:

Example:

Page 10: Extracting UML/OCL Integrity Constraints and Derived Types from Relational Databases

07/10/13 © AtlanMod - [email protected]

SQL to OCL

Projection and selection:

Example:

Page 11: Extracting UML/OCL Integrity Constraints and Derived Types from Relational Databases

07/10/13 © AtlanMod - [email protected]

SQL to OCL

Join:

Example:

Page 12: Extracting UML/OCL Integrity Constraints and Derived Types from Relational Databases

07/10/13 © AtlanMod - [email protected]

SQL to OCL

Group and having clause:

Example:

Page 13: Extracting UML/OCL Integrity Constraints and Derived Types from Relational Databases

07/10/13 © AtlanMod - [email protected]

Triggers

Triggers are composed by:– Triggering event: SQL statement, database or user event– Trigger condition (optional): boolean expression– Triggered action: PL/SQL block (procedural and SQL code)

They can be executed: instead of, before or after performing the triggering event

Example:

Page 14: Extracting UML/OCL Integrity Constraints and Derived Types from Relational Databases

07/10/13 © AtlanMod - [email protected]

PL/SQL to OCL

All triggers that embed in their action a PL/SQL statement raising an exception defined by the user are classified as business-relevant– Two ways to use user exceptions:

RAISE statement (Override an already-defined exception) RAISE APPLICATION ERROR statement

These exceptions are generally nested in conditional statements. For each exception, the conditions triggering the exception are mapped to an equivalent OCL expression.

Page 15: Extracting UML/OCL Integrity Constraints and Derived Types from Relational Databases

07/10/13 © AtlanMod - [email protected]

PL/SQL to OCL

Trigger:

Example:SQL to OCL mappings

Page 16: Extracting UML/OCL Integrity Constraints and Derived Types from Relational Databases

07/10/13 © AtlanMod - [email protected]

Refining OCL Constraints

UML stereotype mechanisms are used to annotate each OCL constraint extracted from a Trigger with the information of the events that apply to it (insert, update, delete)

Annotated OCL constraints can be merged together when:– they are semantically-equivalent– they are applied to different events

Example:

Page 17: Extracting UML/OCL Integrity Constraints and Derived Types from Relational Databases

07/10/13 © AtlanMod - [email protected]

Conclusion and future work

MDE benefits:– Modular and generic approach– Automatic extraction of the organization policies in

databases Future work

– Test the framework on a real database application– Extend the OCL language with additional libraries for

representing calendar-based constraints– Integrate the extracted business rules with those ones

extracted from other system's components

Page 18: Extracting UML/OCL Integrity Constraints and Derived Types from Relational Databases

07/10/13 © AtlanMod - [email protected]

Questions