Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.

Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.

656 views

Published on

Talk @ FASE 2013

Published in:
Technology

No Downloads

Total views

656

On SlideShare

0

From Embeds

0

Number of Embeds

1

Shares

0

Downloads

12

Comments

0

Likes

2

No embeds

No notes for slide

- 1. Implementing QVT-R Bidirectional Model Transformations using Alloy Nuno Macedo Alcino Cunha FASE 2013 March 22, Rome, Italy
- 2. Introduction QVT-R QVT-R/Alloy Example Conclusions Introduction • In model-driven engineering models are the primary development artifact; • Several models must coexist in a consistent manner; • OMG has proposed standards for the speciﬁcation of models (UML) and constraints over them (OCL); • The QVT (Query/View/Transformation) standard has been proposed to specify model transformations and consistency. Nuno Macedo, Alcino Cunha 2 / 28
- 3. Introduction QVT-R QVT-R/Alloy Example Conclusions Query/View/Transformation • The QVT standard proposes three diﬀerent languages; • We focus on QVT Relations (QVT-R); • Declarative language where the speciﬁcation denotes the consistency relation between models; • Two running modes should be derived: • checkonly mode (checks consistency); • enforce mode (updates are propagated in one direction in order to restore consistency). Nuno Macedo, Alcino Cunha 3 / 28
- 4. Introduction QVT-R QVT-R/Alloy Example Conclusions QVT Relations • A QVT-R transformation consists of set of QVT-R relations between elements of the models; • In each relation there is a set of domain patterns that specify related elements; • It may also contain when and where constraints, that act as pre- and post-conditions. Nuno Macedo, Alcino Cunha 4 / 28
- 5. Introduction QVT-R QVT-R/Alloy Example Conclusions Example: object/relational mapping RDBMS UML Class Attribute 1 * name : String name : String attribute persistent : Bool * 0..1 * Package 1 name : String general namespace Table name : String * * Column name : String 1 1 Schema name : String column schema context Class inv: not self.closure(general)->includes(self) Nuno Macedo, Alcino Cunha 5 / 28
- 6. Introduction QVT-R QVT-R/Alloy Example Conclusions Example: object/relational mapping top relation Package2Schema { n:String; domain uml p:Package { name = n }; domain rdbms s:Schema { name = n }; } Package2Schema «domain» p : Package name = n Nuno Macedo, Alcino Cunha uml : UML rdbms : RDBMS «domain» s : Schema name = n 6 / 28
- 7. Introduction QVT-R QVT-R/Alloy Example Conclusions Example: object/relational mapping Class2Table «domain» c : Class uml : UML rdbms : RDBMS name = n «domain» t : Table name = n namespace schema p : Package s : Schema when Package2Schema(p,s) where Attribute2Column(c,t) Attribute2Column «domain» c : Class uml : UML g.attributes->includes(a) and a.name = cn and (c->closure(general)->includes(g) or g = c) Nuno Macedo, Alcino Cunha rdbms : RDBMS «domain» t : Table column cl : Column 7 / 28
- 8. Introduction QVT-R QVT-R/Alloy Example Conclusions Bidirectional Transformations • Since updates can be propagated to either model, enforce mode entails a bidirectional transformation (BX); • These need to be inferred from a single QVT-R speciﬁcation; • Since models may contain diﬀerent information, they are not bijective; • The exact edit-sequence of the update is unknown; • Information from the original target model must be retrieved. Nuno Macedo, Alcino Cunha 8 / 28
- 9. Introduction QVT-R QVT-R/Alloy Example Conclusions QVT-R Semantics Adoption of QVT as a standard has been slow: • The standard is ambiguous and incomplete regarding semantics; • Some work on the formalization of the checking semantics has been done... • ...but not on the formalization of enforcement semantics (at least until the paper just presented!); • Tools implement diﬀerent interpretations or disregard it at all; • No tool has support for enforce mode over metamodels with OCL constraints. Nuno Macedo, Alcino Cunha 9 / 28
- 10. Introduction QVT-R QVT-R/Alloy Example Conclusions QVT-R Checking semantics • Checking: for all candidates in the source there must exist a candidate in the target that matches it; • The standard is omissive about what should happen in circular recursion; • We chose not to allow circular recursion; • However, we can resort to the transitive closure (which has recently been added to the OCL standard); • We were able to rewrite the classic recursive QVT-R examples to use the transitive closure. Nuno Macedo, Alcino Cunha 10 / 28
- 11. Introduction QVT-R QVT-R/Alloy Example Conclusions QVT-R Enforcement semantics • Enforcement: • if keys are deﬁned, update the matching object; • otherwise, create matching elements and delete unbound ones; • The standard enforces strong syntactic restrictions to guarantee determinism; • Writing BX with the expected behavior becomes diﬃcult (not even the example from the standard is bidirectional!); • Deterministic but unpredictable: without keys, new elements are always created, discarding existing ones; • Disregards the OCL constraints of the metamodel; • Instead, we follow the clear and predictable principle of least change. Nuno Macedo, Alcino Cunha 11 / 28
- 12. Introduction QVT-R QVT-R/Alloy Example Conclusions Formalization • For every QVT-R transformation T between M and N we have: • a relation T ⊆ M × N that checks the consistency; → − ← − • transformations T : M × N → N and T : M × N → M that propagate updates; • For every metamodel M, we have a function ∆M : M × M → N that calculates the distance between instances. Nuno Macedo, Alcino Cunha 12 / 28
- 13. Introduction QVT-R QVT-R/Alloy Example Conclusions Formalization • Correctness: → − ∀ m ∈ M, n ∈ N : m T ( T (m, n)) ← − ∀ m ∈ M, n ∈ N : ( T (m, n)) T n • Hippocraticness (check-before-enforce): → − ← − ∀ m ∈ M, n ∈ N : m T n ⇒ m = T (m, n) ∧ n = T (m, n) Nuno Macedo, Alcino Cunha 13 / 28
- 14. Introduction QVT-R QVT-R/Alloy Example Conclusions Formalization • Correctness: → − ∀ m ∈ M, n ∈ N : m T ( T (m, n)) ← − ∀ m ∈ M, n ∈ N : ( T (m, n)) T n • Hippocraticness (check-before-enforce): → − ← − ∀ m ∈ M, n ∈ N : m T n ⇒ m = T (m, n) ∧ n = T (m, n) • Principle of least change (⇒ hippocraticness for ∆ = 0): → − ∀ m ∈ M, n, n ∈ N : m T n ⇒ ∆N ( T (m, n), n) ← − ∀ m, m ∈ M, n ∈ N : m T n ⇒ ∆M ( T (m, n), m) Nuno Macedo, Alcino Cunha ∆N (n , n) ∆M (m , m) 14 / 28
- 15. Introduction QVT-R QVT-R/Alloy Example Conclusions Alloy • Alloy is a lightweight model-checking tool based on relational calculus; • Allows automatic bounded veriﬁcation of properties and generation of instances via SAT solving; • We have already developed a tool for the transformation of UML+OCL class diagrams to Alloy; • Building up on that, we propose the translation of QVT-R to Alloy. Nuno Macedo, Alcino Cunha 15 / 28
- 16. Introduction QVT-R QVT-R/Alloy Example Conclusions QVT-R to Alloy Translation Check Enforce Alloy Command Alloy Command Alloy model Alloy Instances Alloy Speciﬁcation Alloy Predicates Source metamodel XMI Nuno Macedo, Alcino Cunha UML OCL Alloy Speciﬁcation Alloy Instances Target metamodel QVT-R UML OCL XMI 16 / 28
- 17. Introduction QVT-R QVT-R/Alloy Example Conclusions Models • UML classes and their attributes are directly translated to Alloy signatures and relations; sig Class { class : set UML, attribute : Attribute -> UML, general : Class -> UML, ... } • Alloy is static, so we resort to the local state idiom; • OCL annotations are translated to Alloy constraints. Nuno Macedo, Alcino Cunha 17 / 28
- 18. Introduction QVT-R QVT-R/Alloy Example Conclusions Transformations: Checking semantics • Each domain pattern produces a predicate in Alloy that represents candidate elements; pred Pattern_P2S_UML [m:UML,p:Package,n:String] { n in p.name.m } • These are then used in a forall-there-exists test; pred Top_P2S_RDBMS [m:UML,n:RDBMS] { all p:package.m, n:String | Pattern_P2S_UML[m,p,n] => some s:schema.n | Pattern_P2S_RDBMS[n,t,n,s] } • These tests are directional (a dual Top_P2S_UML is deﬁned). Nuno Macedo, Alcino Cunha 18 / 28
- 19. Introduction QVT-R QVT-R/Alloy Example Conclusions Transformations: Enforcement semantics • We follow the principle of least change by incrementally asking for the smallest updates; • We need to calculate the distance ∆ between Alloy models; • Non-deterministic (for ∆ = 0); • Two alternatives: • graph edit distance (GED); • parametrized edit distance. Nuno Macedo, Alcino Cunha 19 / 28
- 20. Introduction QVT-R QVT-R/Alloy Example Conclusions Transformations: Enforcement semantics • Since Alloy atoms are mainly uninterpreted, GED is a natural distance; • Counts the addition and deletion of vertices and edges; fun Delta_UML [m,m’:UML] : Int { (#((class.m-class.m’)+(class.m’-class.m))).plus[ (#((name.m-name.m’)+(name.m’-name.m))).plus[...]] } • General, but “oblivious” metric; • Hard to control the behavior and non-determinism. Nuno Macedo, Alcino Cunha 20 / 28
- 21. Introduction QVT-R QVT-R/Alloy Example Conclusions Transformations: Enforcement semantics • UML class diagrams can be enhanced with edit operations speciﬁed in OCL; • We can infer the number of operations required to reach a consistent model; fact { all m:UML, m’:m.next | { some p:package.m, n:String | setName[p,n,m,m’] or some p:package.m, n:String | addClass[p,n,m,m’] or ... } } • Finer control over distance but with the overhead of deﬁning operations in OCL. Nuno Macedo, Alcino Cunha 21 / 28
- 22. Introduction QVT-R QVT-R/Alloy Example Conclusions Instances • Object instances are represented in Alloy as singleton sets belonging to the signature representing its type; one sig M extends UML {} one sig P extends Package {} one sig A,B extends Class {} • Their attributes can be simply deﬁned as relations between those signatures. fact { class.M = A + B && package.M = P && namespace.M = A -> P + B -> P && ... } Nuno Macedo, Alcino Cunha 22 / 28
- 23. Introduction QVT-R QVT-R/Alloy Example Conclusions Execution: Checkonly mode • Runs the checks in all directions; pred Uml2Rdbms [m:UML,n:RDBMS] { Top_P2S_RDBMS[m,n] && Top_P2S_UML[m,n] && Top_C2T_RDBMS[m,n] && Top_C2T_UML[m,n] } • The scope is the number of existing elements; check { Uml2Rdbms[Src,Trg] } for 0 but 1 Schema, 1 Table, 2 Column, 1 Package, 2 Class, 2 Attribute Nuno Macedo, Alcino Cunha 23 / 28
- 24. Introduction QVT-R QVT-R/Alloy Example Conclusions Execution: Enforce mode • Asks for consistent models by increasing distance ∆; • The scope is the number of existing elements plus ∆ on the elements of the target model; run { Uml2Rdbms[Src,Trg’] && Dist_UML[Trg,Trg’] = ∆ } for 0 but 1 Schema, 1 Table, 3 Column, log(∆+1)+1 Int, (1+∆) Package, (2+∆) Class, (2+∆) Attribute • Guarantees the properties by construction. Nuno Macedo, Alcino Cunha 24 / 28
- 25. Introduction QVT-R QVT-R/Alloy Example Conclusions Example: Check mode check { Uml2Rdbms[Src,Trg] } for 0 but 1 Schema, 1 Table, 3 Column, 1 Package, 2 Class, 2 Attribute Nuno Macedo, Alcino Cunha 25 / 28
- 26. Introduction QVT-R QVT-R/Alloy Example Conclusions Example: Enforce mode run { Uml2Rdbms[Src,Trg’] && Dist_UML[Trg,Trg’] = 3 } for 0 but 1 Schema, 1 Table, 3 Column, 4 Package, 5 Class, 5 Attribute, 3 Int Nuno Macedo, Alcino Cunha 26 / 28
- 27. Introduction QVT-R QVT-R/Alloy Example Conclusions Example: Enforce mode run { Uml2Rdbms[Src,Trg’] && Dist_UML[Trg,Trg’] = 3 } for 0 but 1 Schema, 1 Table, 3 Column, 4 Package, 5 Class, 5 Attribute, 3 Int Nuno Macedo, Alcino Cunha 27 / 28
- 28. Introduction QVT-R QVT-R/Alloy Example Conclusions Conclusions • We propose a BX framework for QVT-R with clear semantics where both the metamodels and the transformations can be annotated with unrestricted OCL; • Implementation over the Eclipse Modeling Framework (EMF) available at http://github.com/haslab/echo; • Working on optimization (by simplifying the Alloy predicates and inferring further restrictions from the speciﬁcations); • Studying a generic mechanism to detect and deal with circular recursion (either by resorting to the transitive closure or not). Nuno Macedo, Alcino Cunha 28 / 28

No public clipboards found for this slide

×
### Save the most important slides with Clipping

Clipping is a handy way to collect and organize the most important slides from a presentation. You can keep your great finds in clipboards organized around topics.

Be the first to comment