Upload
gwendal-daniel
View
1.507
Download
0
Embed Size (px)
Citation preview
UMLtoGraphDB: Mapping Conceptual Schemas to Graph Databases
Jordi CabotICREA-UOC
Gwendal DanielInria - Mines Nantes & Lina
Gerson SunyéInria - Mines Nantes & Lina
17/11/2016 UMLtoGraphDB: Mapping Conceptual Schemas to Graph Databases - G. Daniel 2
Introduction
● NoSQL– Scalability– Availability– Performance
● Graph Databases
– Store highly interconnected data● Vertices, edges, properties
– Expressive query language● Gremlin, Cypher
– Social networks, data provenance analysis
17/11/2016 UMLtoGraphDB: Mapping Conceptual Schemas to Graph Databases - G. Daniel 3
Introduction
● Schemaless
Flexible● Non-uniform data● Schema evolutions
Implicit schema defined by data● Need to acquire this knowledge● Specific to each database● Not formally described
17/11/2016 UMLtoGraphDB: Mapping Conceptual Schemas to Graph Databases - G. Daniel 4
Introduction
Hard to integrate in code-generation architectures
– Few options for mapping ER/UML to NoSQL
– Data consistency challenge
– Lack of support for integrity constraints
→ Goal: create a code generation framework
– Map conceptual schemas to graph databases
– Input: UML + OCL
– Output: graph database + graph queries
17/11/2016 UMLtoGraphDB: Mapping Conceptual Schemas to Graph Databases - G. Daniel 5
UMLtoGraphDB
● MDA methodology
– Platform Independent Model (PIM)
● Conceptual schema
– Platform Specific Model (PSM)
● Refines PIM for a specific implementation
– Code generation from PSM
17/11/2016 UMLtoGraphDB: Mapping Conceptual Schemas to Graph Databases - G. Daniel 6
UMLtoGraphDB – Starting Point
● Conceptual Schema
– UML class diagram
● Concepts
● Data structure
– OCL
● Business rules
● Invariants / Constraints
17/11/2016 UMLtoGraphDB: Mapping Conceptual Schemas to Graph Databases - G. Daniel 7
UMLtoGraphDB
17/11/2016 UMLtoGraphDB: Mapping Conceptual Schemas to Graph Databases - G. Daniel 8
UMLtoGraphDB
17/11/2016 UMLtoGraphDB: Mapping Conceptual Schemas to Graph Databases - G. Daniel 9
UMLtoGraphDB
17/11/2016 UMLtoGraphDB: Mapping Conceptual Schemas to Graph Databases - G. Daniel 10
Class2GraphDB Transformation
17/11/2016 UMLtoGraphDB: Mapping Conceptual Schemas to Graph Databases - G. Daniel 11
GraphDB Metamodel
GraphSpecification
+ baseDB : DBType
VertexDefinition
EdgeDefinition
PropertyDefinition
+ Key : String+ Type : PrimitiveType
GraphElement
+ label : String[*]
<<Enumeration>>
PrimitiveType
ObjectIntegerStringBoolean
<<Enumeration>>
DBType
Neo4jOrientDB
vertices *
inEdges *
head 1
outEdges *
tail 1
edges *
properties*
17/11/2016 UMLtoGraphDB: Mapping Conceptual Schemas to Graph Databases - G. Daniel 12
Class2GraphDB
● (Subset of) UML class diagram to GraphDB
– Non-abtract classes → VertexDefinition
– Attribute → PropertyDefinition
– Association (2 classes) → EdgeDefinition
– Association (n classes) → VertexDefinition + EdgeDefinitions
– Association class → VertexDefinition + EdgeDefinitions
– Support for generalization / specialization
17/11/2016 UMLtoGraphDB: Mapping Conceptual Schemas to Graph Databases - G. Daniel 13
Client
+ name : String+ address : String
Order
+ shipmentDate : Date+ deliveryDate : Date+ paid : Boolean
Product
+ name : String+ price : Integer+ description : String
OrderLine
+ quantity : Integer+ productPrice : Integer
PrivateCustomer
+ cardNumber : String
orders
*
1..**
Running Example
context Product inv validPrice:self.price > 0
context Order inv validOrder:self.shipmentData < self.deliveryDate
context Client inv maxUnpaidOrders:self.orders→select(o | not o.paid)
→size() < 3
Running Example - PIM
17/11/2016 UMLtoGraphDB: Mapping Conceptual Schemas to Graph Databases - G. Daniel 14
Class2GraphDB
Class mapping
Product
+ name : String+ price : Integer+ description : String
v1:VertexDefinition
+ label : String = "Product"
p1:PropertyDefinition
+ key : String = "name"+ type : PrimitiveType = String
p3:PropertyDefinition
+ key : String = "description"+ type : PrimitiveType = String
p2:PropertyDefinition
+ key : String = "price"+ type : PrimitiveType = Integer
17/11/2016 UMLtoGraphDB: Mapping Conceptual Schemas to Graph Databases - G. Daniel 15
Class2GraphDB
Association mapping
v3:VertexDefinition
+ label : String = "Order"
v1:VertexDefinition
+ label : String = "Client"
e1:EdgeDefinition
+ name : String = "orders"
tail
head
Client
Order
orders*
17/11/2016 UMLtoGraphDB: Mapping Conceptual Schemas to Graph Databases - G. Daniel 16
Class2GraphDB
Order
Product
OrderLine
+ quantity : Integer+ productPrice : Integer
1..*
*
AssociationClass mapping
v2:VertexDefinition
+ label : String = "Order"
v3:VertexDefinition
+ label : String = "Product"
v4:VertexDefinition
+ label : String = "OrderLine"
e2:EdgeDefinition
+ name : String = "orderLine"
e3:EdgeDefinition
+ name : String = "orderLine"
p5:PropertyDefinition
+ key : String = "quantity"+ type : PrimitiveType = Integer
p4:PropertyDefinition
+ key : String = "productPrice"+ type : PrimitiveType = Integer
tail
head
head
tail
17/11/2016 UMLtoGraphDB: Mapping Conceptual Schemas to Graph Databases - G. Daniel 17
UMLtoGraphDB
17/11/2016 UMLtoGraphDB: Mapping Conceptual Schemas to Graph Databases - G. Daniel 18
OCL2Gremlin Transformation
17/11/2016 UMLtoGraphDB: Mapping Conceptual Schemas to Graph Databases - G. Daniel 19
Gremlin Metamodel
● Gremlin language
– Graph traversal DSL
– Based on the Blueprints API
– Generic query language for graph databases
17/11/2016 UMLtoGraphDB: Mapping Conceptual Schemas to Graph Databases - G. Daniel 20
Gremlin Metamodel
GremlinScript
Instruction
TraversalElement
Step
OutEStep
+ label : String
InEStep
+ label : String
OutVStep
InVStep
FilterStep
. . .
EdgesStep
+ label : String
VerticesStep
+ id : String
instructions*
next
0..1
17/11/2016 UMLtoGraphDB: Mapping Conceptual Schemas to Graph Databases - G. Daniel 21
OCL2Gremlin
● Adaptation of the Mogwaï* query framework
– Gremlin metamodel definition
– Map OCL expressions to Gremlin steps
– Merge created steps into traversals
– Generate query code from Gremlin AST
* G. Daniel, G. Sunyé, and J. Cabot. Mogwaï: a Framework to Handle Complex Queries on Large Models. In RCIS 2016, Grenoble, FR,June 2016
17/11/2016 UMLtoGraphDB: Mapping Conceptual Schemas to Graph Databases - G. Daniel 22
OCL2Gremlin
context Product inv validPrice:self.price > 0
context Order inv validOrder:self.shipmentData
< self.deliveryDate
context Client inv maxUnpaidOrders:self.orders→select(o | not o.paid)
→size() < 3
// validPricev.property(''price'') > 0;
// validOrderv.property(''shipmentDate'') < v.property(''deliveryDate'')
// maxUnpaidOrdersv.outE(''orders'').inV
.filter{it.property(''paid'') == false}.count() < 3
17/11/2016 UMLtoGraphDB: Mapping Conceptual Schemas to Graph Databases - G. Daniel 23
UMLtoGraphDB
17/11/2016 UMLtoGraphDB: Mapping Conceptual Schemas to Graph Databases - G. Daniel 24
Graph2Code
17/11/2016 UMLtoGraphDB: Mapping Conceptual Schemas to Graph Databases - G. Daniel 25
Graph2Code
● Generate Java beans
– Adapter pattern
● Delegate to database objects
● Lightweight implementation
– Bean factory
● Create new elements
● Reifies database objects
17/11/2016 UMLtoGraphDB: Mapping Conceptual Schemas to Graph Databases - G. Daniel 26
Graph2Code – Client Classpublic class Client extends BlueprintsBean {
public Client(Vertex v, Graph graph, UMLModelFactory factory) {super(v,graph,factory);
}
public String getName() {return (String) this.vertex.property(''name'').value();
}
public void setName(String newName) {this.vertex.property(''name'', newName);
}
public List<Order> getOrders() {Iterator<Vertex> otherEnd = this.vertex.vertices(Direction.OUT,"orders");return new GremlinIterator<Order>(otherEnd, factory);
}
public void addOrder(Order newOrder) {this.vertex.addEdge(“orders”, newOrder.getVertex());
}
17/11/2016 UMLtoGraphDB: Mapping Conceptual Schemas to Graph Databases - G. Daniel 27
Graph2Code – Client Class
[...]
public boolean checkMaxUnpaidOrders() {return this.graph.traversal().V(this.vertex).out(''orders'').filter(
v -> v.get().<Boolean>property(''paid'').value()).count().is(P.lt(3)).hasNext();
}
}
17/11/2016 UMLtoGraphDB: Mapping Conceptual Schemas to Graph Databases - G. Daniel 28
Tooling
● Set of open-source eclipse plugins
– ATL: Model-to-model transformations● ~ 110 rules / helpers
– XTend: Code generation
● Full stack execution: less than 5 seconds
17/11/2016 UMLtoGraphDB: Mapping Conceptual Schemas to Graph Databases - G. Daniel 29
Conclusion
● Chain of model transformations
– UML (class diagram) to GraphDB
– OCL to Gremlin
– Graph to code transformation
● GraphDB metamodel
● Future Work
– Refactoring operations at the PSM level
– Cover multiple database types
– Reverse engineering
17/11/2016 UMLtoGraphDB: Mapping Conceptual Schemas to Graph Databases - G. Daniel 30
Questions?
Websites / Repositories
UMLtoGraphDB: https://github.com/atlanmod/UML2NoSQL
Mogwaï: https://github.com/atlanmod/Mogwai
https://github.com/atlanmod
Thank you for your attention!
https://github.com/SOM-Research