emf scaffolding

27
Scaffol ding EMF Version 1.0

Upload: cedricvidal

Post on 18-Nov-2014

1.434 views

Category:

Technology


3 download

DESCRIPTION

 

TRANSCRIPT

Page 1: EMF Scaffolding

ScaffoldingEMF

Version 1.0

Page 2: EMF Scaffolding

What is scaffolding ?

• Scaffolds are temporary structures that physically support workers while they complete jobs that would otherwise be impossible(HH93, p138)

Page 3: EMF Scaffolding

Scaffolding in software

• Ruby on Rails• *Rails scripting frameworks bring

blazing fast productivity in their own specific technological space

• Mainly through Scaffolding !

Page 4: EMF Scaffolding

Ruby on Rails Scaffolding

• Meta-Programming• Scaffolding works at the code level• Scaffolding engine operates on code as a model• Can be either– Static : on demand– Dynamic : transparently on your behalf

Entity.rb

DAO.rb

Page 5: EMF Scaffolding

Others

• Ruby On Rails• Grails• Spring ROO• Play!• CakePHP• Monorail• Symfony• …

Page 6: EMF Scaffolding

What’s the point ?

• Model-Driven brings quality, durability, maintainability

• What about productivity ?– Goal: Enhance modeling

expressiveness, simplicity and overwhole productivity

Page 7: EMF Scaffolding

What is Scaffolding applied to Modeling ?

• Creating partial model structures on behalf of the designer that he would otherwise have to create by himself

Page 8: EMF Scaffolding

Model Scaffolding taxonomy

• Blind versus In-Place Scaffolding• Static versus Dynamic Scaffolding• The greener the better

Page 9: EMF Scaffolding

Model Scaffolding taxonomy

1. Classical code generation2. Compensated code generation3. « Blind » scaffolding4. « In-Place » scaffolding

• Each static or dynamic

Page 10: EMF Scaffolding

Sample problem domain

• 3-Tiers Architecture• DSL containing concepts– Entity– DAO– Service

• Java code is generated

• Légende

GenerationReference

Model separation

File

Entity or DAO

Service

ScaffoldedGenerated

Hand-written

Color code

Page 11: EMF Scaffolding

Classical code generation 1/2

• Entities are modeled• Entity and DAO source

codes are generated from the modeled Entity

• Problem: What if you want to define queries in your model ?

Entity

Entity.javaDAO.java

Model

Text

Page 12: EMF Scaffolding

Classical code generation 2/2

• Entity and DAOs are modeled• Entity source code is

generated from the modeled Entity

• DAO source code is generated from modeled DAO

• DAOs which are not modeled are not generated

• Problem: You need to define all DAOs…

• Even those that only do CRUD

Entity

Entity.javaDAO.java

Model

Text

DAO

Page 13: EMF Scaffolding

Compensated code generation

• Source code is still generated for modeled elements

• For Entities which have no modeled DAO, we compensate by generating source code for the DAO from the modeled Entity

• Advantage: Only custom DAOs are modeled

• Problem: DAO code generation logic is duplicated– Entity -> DAO.java– DAO -> DAO.java

EntityOne DAO

OneEntityTwo

One.java

OneDAO.java

Two.java

TwoDAO.java

Model

Text

Page 14: EMF Scaffolding

Generation « Blind » Model Scaffolding

• Each model is a step in the MDSD chain

• An intermediate step is introduced• Each model can only « see » the

model before

• Existing elements are copied as is• A DAO is generated for each entity

which has no DAO

• Advantage: Only one DAO code generation logic

• Problem: How do you reference scaffolded elements

EntityOne

EntityOne

EntityTwo DAO

TwoDao

EntityTwo

DAOTwoDao

DAOOneDao

One.java

OneDAO.javaTwo.java

TwoDAO.java

Model i

Model i-bis

Model i+1

Page 15: EMF Scaffolding

How to reference scaffolded elements ?

• The problem is illustrated by introducing a service

• The ‘Alpha’ service can reference the modeled DAO ‘TwoDao’ but not the scaffolded DAO ‘OneDao’

• The scaffolded DAO ‘OneDao’ is located in a model that the ‘Alpha’ service cannot see

• Problem: « Blind » scaffolding doesn’t allow scaffolded elements referencing

EntityOne

EntityOne

DAOOneDao

ServiceAlpha

Modèle i

Modèle i-bis

EntityTwo

DAOTwoDao

Page 16: EMF Scaffolding

« In-place » Model Scaffolding

• ‘OneDao’ DAO is scaffolded in the same model as Entity ‘One’

• The DAO is « visible » without being materialized in the input model

• Advantage: Le ‘Alpha’ service can reference the scaffolded DAO ‘OneDao’

• Problem: How to customize a scaffolded element ?

EntityOne

DAOOneDao

One.java

AlphaService.java

OneDao.java

ServiceAlpha

Model i

Model i+1

Page 17: EMF Scaffolding

Takeover 1/3: Overview

• User can take over scaffolded elements

• The over taken element is then materialized in the input model

• Advantage: The DAO can be customized

EntityOne

DAOOneDao

ServiceAlpha

Iteration n

Iteration n+1

EntityOne

DAOOneDao

ServiceAlpha

Page 18: EMF Scaffolding

Takeover 2/3: Zoom

• After the DAO taking over, CRUD methods are still scaffolded

• Advantage: No need to manually input previously scaffolded elements

EntityOne

ServiceAlpha

Iteration n

EntityOne

ServiceAlpha

DAOOneDao

createread

updatedelete

DAOOneDao

createread

updatedelete

Iteration n+1

Page 19: EMF Scaffolding

Takeover 3/3: Customisation

• Let’s add a finder finder• CRUD methods are still

scaffolded

• Advantage: Only customizations are hand written, CRUD methods are scaffoldedEntity

OneServiceAlpha

DAOOneDaocreateread

updatedelete

myFinder

EntityOne

ServiceAlpha

DAOOneDao

createread

updatedelete

Iteration n+1

Iteration n+2

Page 20: EMF Scaffolding

Deletion 1/2: The problem

• What happens if the user deletes an element for which elements were scaffolded ?

• Scaffolded elements must also be deleted

EntityOne

DAOOneDao

One.java

AlphaService.java

OneDao.java

ServiceAlpha

Model i

Model i+1

Page 21: EMF Scaffolding

Deletion 2/2: solutions

• Need to keep track of scaffolded elements

• Only really a problem with dynamic « in-place » scaffolding

• For static and/or « blind » scaffolding, scaffolded elements can just be computed all over again

Page 22: EMF Scaffolding

Model scaffolding comparison

Page 23: EMF Scaffolding

What Scaffolding engine ?

• A model to model transformation engine ?– ATL– Xtend– QVT Operational– QVT Relational– Obeo Transfo– …

• A rule engine ?– Drools– Any OO Rule Engine …

Page 24: EMF Scaffolding

A rule engine ??

• Scaffolding rules as production rules• The model as a working memory• Model elements as facts• When a given condition is met, new facts are

inserted into working memory• Those new facts are attached to the model as new

elements

Page 25: EMF Scaffolding

Rule engine sync process

EntityOne

DAOOneDao

Working Memory

Model

EntityOne

DAOOneDao

reference

reference

synchroniz

e

synchroniz

e Scaffolding Rule

Page 26: EMF Scaffolding

Drools sample rule

• Sample Drools DAO scaffolding rule

Page 27: EMF Scaffolding

MDSD Scaffolding benefits

• Accelerates modeling• Allows to quickly come up with a working model• The user starts from the begining with a complete model

(complete in the direction the scaffolding takes him)• Provides the user with a fast feedback• Allows to enrich the input model as well as facilitating its usage

for the new user• Brings flexibility while keeping simplicity• Scaffolding can be complemented by code generation and model

validation• The user can whenever he wants take over the scaffolded

elements in order to customize them