SlideShare ist ein Scribd-Unternehmen logo
1 von 31
Our journey from
UML/MDD to Scala
macros
Hayssam Saleh
Summary

• What this talk is about ?
o

Why did we choose UML ?
o Why did we move from UML to DSL
o Our experience in designing a DSL on top of Slick using
Scala macros.

• The macro-based DSL on top of Slick
• Implementation
o

How macros work
o @Model annotation-macro
o Dynamic methods statically compiled
Why did we move from UML
to scala macros ?
Why UML ?

• Encapsulation

o Hide implementation details and expose relevant
abstractions only

• Communication

o Product owner and dev team understand each other

• Quality

o Boilerplate code is generated with respect to the
architect guidelines. Dev team focus on business
rules
Why not UML ?

• Lack of efficiency
o

Any modification require code regeneration
 UML to XMI
(20 % - more or less)
 XMI to code
(78% - more or more)
 Code to bytecode
(2% - much less)
o Excessive generation time
 Code is regenerated for all model entities regardless of
whether they were modified
o Almost inexistent (real life) collaborative capabilities
 Always locked model syndrome
 Anyone tried to merge UML models on a regular basis ?

• Impedance mismatch
o

Not all concepts are easily represented in UML
Why Scala macros ?
Why not Scala macros ?

• DSL design is complex

o We are used to apply existing patterns
o Are we used to design grammars ?

• Difficult to develop and maintain
o Development at the meta-level
o Hey, we’re working on the AST
The DSL
The DSL Goal

• Allow the product owner and the developer
o to share info about the static representation of the
system (The database model in our case)

• The product owner should be able to read it
• The developer should be able to compile it
The good old architecture
http://www.mywebsite.com

Controller
Controller

Service
Service
DAO
DAO
Model
Model
Model

Persistence
Persistence
layer
layer
Why Slick as the persistence framework

• Why Slick as a persistence framework

o Because it ’s not an ORM so we’ve got
  DBA is happy : No more huge SQL requests that
makes SQL auditing difficult
  Network is happy : No unnecessary round trip
  Webserver is happy : no more objects to proxify
€€€ When the customer is happy my boss is
happy too
Why Slick as the persistence framework

• What we lost of columns to update
o Automatic detection
 Who cares ?

•

Unit of I/O defaults to 8K for Postgres, Oracle, SQLServer …

 So for most cases (to say the least), updating the whole object
has no real impact on performance
o Automatic inserts of dependent objects
 Our use case focus is on scalable OLTP applications
 Is it really an issue in OLTP ?

•
•

Do we really want the framework to guess what we’re doing ?
Does it justify the overhead ?

•
•
•

We’ve got actors
We’ve got transactions
We’ve got joins

 We’ve got to rethink our persistence patterns
A Slick-macros example
Timestamp all rows
Timestamp all rows
1..1 relationship
1..1 relationship

0..1 relationship
0..1 relationship

Embedded value
Embedded value

Constraints
Constraints

*..* relationship
*..* relationship
The equivalent Slick Code 1/4
The equivalent Slick Code 2/4
The equivalent Slick Code 3/4
The equivalent Slick Code 4/4
Our UML Model
Slick Mapping generated by the macro
Implementation
Where did the Boilerplate code goes ?
Scala source code
Scala source code

Boilerplat
Boilerplat
ee XML /
XML /
Scala / / …
Scala …

Annotations

Abstract Syntax Tree
Abstract Syntax Tree
Boilerplate code

Java Byte Code
Java Byte Code

Runtime
Runtime
Outputting the Trees

AST nodes have extractors that definitely help
Part 2

Dynamic methods Statically
compiled
Simplify Querying

• Simplify finders
o Instead of this

o Write this (pseudo-code)

def macros
def macros
Simplify Querying

• Simplify update
o Instead of this

o Write this

def macro
def macro

Argument names and types are known at call site only
Argument names and types are known at call site only
and still this code remains typechecked at compile time
and still this code remains typechecked at compile time
Implementation
A mix of Dynamic and Scala-macros

• First the Slick Query object gets the Dynamic
•

trait
Since arguments are all named we define the
applyDynamicNamed method as a macro
o Def macros are applied at call site, we can thus
typecheck at call site against the prefix object.
Conclusion

• As a developer

o It was almost
 A copy/paste task and AST node substitution
o Made easier using the quasiquote feature

• As a user

o Much less code to maintain
o Reduced time to deliver
o No runtime overhead
Source code
•

Slick-macros @hayssams : http://www.github.com/ebiznext/slick-macros
References
•

Scala macros @xeno_by : http://docs.scalalang.org/overviews/macros/usecases.html

•

Slick @szeiger : http://slick.typesafe.com/docs/#talks

Another source about macros you may find useful
Thank you

Weitere ähnliche Inhalte

Was ist angesagt?

Alibaba patches in MariaDB
Alibaba patches in MariaDBAlibaba patches in MariaDB
Alibaba patches in MariaDB
Lixun Peng
 

Was ist angesagt? (20)

MySQL Multi Master Replication
MySQL Multi Master ReplicationMySQL Multi Master Replication
MySQL Multi Master Replication
 
JavaOne 2011 Recap
JavaOne 2011 RecapJavaOne 2011 Recap
JavaOne 2011 Recap
 
Level DB - Quick Cheat Sheet
Level DB - Quick Cheat SheetLevel DB - Quick Cheat Sheet
Level DB - Quick Cheat Sheet
 
MySQL 5.6 Global Transaction Identifier - Use case: Failover
MySQL 5.6 Global Transaction Identifier - Use case: FailoverMySQL 5.6 Global Transaction Identifier - Use case: Failover
MySQL 5.6 Global Transaction Identifier - Use case: Failover
 
Kafka as a message queue
Kafka as a message queueKafka as a message queue
Kafka as a message queue
 
Introduction to Galera
Introduction to GaleraIntroduction to Galera
Introduction to Galera
 
The architecture of oak
The architecture of oakThe architecture of oak
The architecture of oak
 
Galera cluster for MySQL - Introduction Slides
Galera cluster for MySQL - Introduction SlidesGalera cluster for MySQL - Introduction Slides
Galera cluster for MySQL - Introduction Slides
 
Vote NO for MySQL
Vote NO for MySQLVote NO for MySQL
Vote NO for MySQL
 
M|18 Why Abstract Away the Underlying Database Infrastructure
M|18 Why Abstract Away the Underlying Database InfrastructureM|18 Why Abstract Away the Underlying Database Infrastructure
M|18 Why Abstract Away the Underlying Database Infrastructure
 
What's New In PostgreSQL 9.4
What's New In PostgreSQL 9.4What's New In PostgreSQL 9.4
What's New In PostgreSQL 9.4
 
Invitation to the dark side of Ruby
Invitation to the dark side of RubyInvitation to the dark side of Ruby
Invitation to the dark side of Ruby
 
Maccro Strikes Back
Maccro Strikes BackMaccro Strikes Back
Maccro Strikes Back
 
Java 9 sneak peek
Java 9 sneak peekJava 9 sneak peek
Java 9 sneak peek
 
Introducing HerdDB - a distributed JVM embeddable database built upon Apache ...
Introducing HerdDB - a distributed JVM embeddable database built upon Apache ...Introducing HerdDB - a distributed JVM embeddable database built upon Apache ...
Introducing HerdDB - a distributed JVM embeddable database built upon Apache ...
 
Best Practices for Running Kafka on Docker Containers
Best Practices for Running Kafka on Docker ContainersBest Practices for Running Kafka on Docker Containers
Best Practices for Running Kafka on Docker Containers
 
OpenDaylight and YANG
OpenDaylight and YANGOpenDaylight and YANG
OpenDaylight and YANG
 
Alibaba patches in MariaDB
Alibaba patches in MariaDBAlibaba patches in MariaDB
Alibaba patches in MariaDB
 
Avro
AvroAvro
Avro
 
Introduction tomcat7 servlet3
Introduction tomcat7 servlet3Introduction tomcat7 servlet3
Introduction tomcat7 servlet3
 

Andere mochten auch

De Maven à SBT ScalaIO 2013
De Maven à SBT ScalaIO 2013De Maven à SBT ScalaIO 2013
De Maven à SBT ScalaIO 2013
Stephane Manciot
 
Realtime Web avec Kafka, Spark et Mesos
Realtime Web avec Kafka, Spark et MesosRealtime Web avec Kafka, Spark et Mesos
Realtime Web avec Kafka, Spark et Mesos
ebiznext
 
Les modèles NoSQL
Les modèles NoSQLLes modèles NoSQL
Les modèles NoSQL
ebiznext
 
Machine Learning - Spark / MLlib
Machine Learning - Spark / MLlibMachine Learning - Spark / MLlib
Machine Learning - Spark / MLlib
ebiznext
 

Andere mochten auch (14)

PSUG #52 Dataflow and simplified reactive programming with Akka-streams
PSUG #52 Dataflow and simplified reactive programming with Akka-streamsPSUG #52 Dataflow and simplified reactive programming with Akka-streams
PSUG #52 Dataflow and simplified reactive programming with Akka-streams
 
De Maven à SBT ScalaIO 2013
De Maven à SBT ScalaIO 2013De Maven à SBT ScalaIO 2013
De Maven à SBT ScalaIO 2013
 
Packaging et déploiement d'une application avec Docker et Ansible @DevoxxFR 2015
Packaging et déploiement d'une application avec Docker et Ansible @DevoxxFR 2015Packaging et déploiement d'une application avec Docker et Ansible @DevoxxFR 2015
Packaging et déploiement d'une application avec Docker et Ansible @DevoxxFR 2015
 
Realtime Web avec Kafka, Spark et Mesos
Realtime Web avec Kafka, Spark et MesosRealtime Web avec Kafka, Spark et Mesos
Realtime Web avec Kafka, Spark et Mesos
 
Spark / Mesos Cluster Optimization
Spark / Mesos Cluster OptimizationSpark / Mesos Cluster Optimization
Spark / Mesos Cluster Optimization
 
DevOps avec Ansible et Docker
DevOps avec Ansible et DockerDevOps avec Ansible et Docker
DevOps avec Ansible et Docker
 
Machine learning
Machine learningMachine learning
Machine learning
 
Les modèles NoSQL
Les modèles NoSQLLes modèles NoSQL
Les modèles NoSQL
 
JahiaOne - Performance Tuning
JahiaOne - Performance TuningJahiaOne - Performance Tuning
JahiaOne - Performance Tuning
 
Paris Scala User Group #43 - Spray (Magnet Pattern) + RxScala / ElasticSearch
Paris Scala User Group #43 - Spray (Magnet Pattern) + RxScala / ElasticSearchParis Scala User Group #43 - Spray (Magnet Pattern) + RxScala / ElasticSearch
Paris Scala User Group #43 - Spray (Magnet Pattern) + RxScala / ElasticSearch
 
Des principes de la démarche DevOps à sa mise en oeuvre
Des principes de la démarche DevOps à sa mise en oeuvreDes principes de la démarche DevOps à sa mise en oeuvre
Des principes de la démarche DevOps à sa mise en oeuvre
 
Machine Learning - Spark / MLlib
Machine Learning - Spark / MLlibMachine Learning - Spark / MLlib
Machine Learning - Spark / MLlib
 
JavaFX 2 and Scala - Like Milk and Cookies (33rd Degrees)
JavaFX 2 and Scala - Like Milk and Cookies (33rd Degrees)JavaFX 2 and Scala - Like Milk and Cookies (33rd Degrees)
JavaFX 2 and Scala - Like Milk and Cookies (33rd Degrees)
 
Spark une alternative à Hadoop MapReduce pour le Datamining
Spark une alternative à Hadoop MapReduce pour le DataminingSpark une alternative à Hadoop MapReduce pour le Datamining
Spark une alternative à Hadoop MapReduce pour le Datamining
 

Ähnlich wie Scala io2013 : Our journey from UML/MDD to Scala macros

Graal Tutorial at CGO 2015 by Christian Wimmer
Graal Tutorial at CGO 2015 by Christian WimmerGraal Tutorial at CGO 2015 by Christian Wimmer
Graal Tutorial at CGO 2015 by Christian Wimmer
Thomas Wuerthinger
 
NetWork - 15.10.2011 - Applied code generation in .NET
NetWork - 15.10.2011 - Applied code generation in .NET NetWork - 15.10.2011 - Applied code generation in .NET
NetWork - 15.10.2011 - Applied code generation in .NET
Dmytro Mindra
 

Ähnlich wie Scala io2013 : Our journey from UML/MDD to Scala macros (20)

Using Apache Camel as AKKA
Using Apache Camel as AKKAUsing Apache Camel as AKKA
Using Apache Camel as AKKA
 
What`s New in Java 8
What`s New in Java 8What`s New in Java 8
What`s New in Java 8
 
Browser Internals for JS Devs: WebU Toronto 2016 by Alex Blom
Browser Internals for JS Devs: WebU Toronto 2016 by Alex BlomBrowser Internals for JS Devs: WebU Toronto 2016 by Alex Blom
Browser Internals for JS Devs: WebU Toronto 2016 by Alex Blom
 
Sista: Improving Cog’s JIT performance
Sista: Improving Cog’s JIT performanceSista: Improving Cog’s JIT performance
Sista: Improving Cog’s JIT performance
 
A Generic Neural Network Architecture to Infer Heterogeneous Model Transforma...
A Generic Neural Network Architecture to Infer Heterogeneous Model Transforma...A Generic Neural Network Architecture to Infer Heterogeneous Model Transforma...
A Generic Neural Network Architecture to Infer Heterogeneous Model Transforma...
 
Angular Ivy- An Overview
Angular Ivy- An OverviewAngular Ivy- An Overview
Angular Ivy- An Overview
 
Incredible ODI tips to work with Hyperion tools that you ever wanted to know
Incredible ODI tips to work with Hyperion tools that you ever wanted to knowIncredible ODI tips to work with Hyperion tools that you ever wanted to know
Incredible ODI tips to work with Hyperion tools that you ever wanted to know
 
Spark Summit EU talk by Mikhail Semeniuk Hollin Wilkins
Spark Summit EU talk by Mikhail Semeniuk Hollin WilkinsSpark Summit EU talk by Mikhail Semeniuk Hollin Wilkins
Spark Summit EU talk by Mikhail Semeniuk Hollin Wilkins
 
Graal Tutorial at CGO 2015 by Christian Wimmer
Graal Tutorial at CGO 2015 by Christian WimmerGraal Tutorial at CGO 2015 by Christian Wimmer
Graal Tutorial at CGO 2015 by Christian Wimmer
 
Stefan Richter - Writing simple, readable and robust code: Examples in Java, ...
Stefan Richter - Writing simple, readable and robust code: Examples in Java, ...Stefan Richter - Writing simple, readable and robust code: Examples in Java, ...
Stefan Richter - Writing simple, readable and robust code: Examples in Java, ...
 
Introduction to Aspect Oriented Programming by Donald Belcham
Introduction to Aspect Oriented Programming by Donald BelchamIntroduction to Aspect Oriented Programming by Donald Belcham
Introduction to Aspect Oriented Programming by Donald Belcham
 
Introduction To AOP
Introduction To AOPIntroduction To AOP
Introduction To AOP
 
Weblogic - Data management in application servers
Weblogic - Data management in application serversWeblogic - Data management in application servers
Weblogic - Data management in application servers
 
Domain oriented development
Domain oriented developmentDomain oriented development
Domain oriented development
 
Deep Dive of ADBMS Migration to Apache Spark—Use Cases Sharing
Deep Dive of ADBMS Migration to Apache Spark—Use Cases SharingDeep Dive of ADBMS Migration to Apache Spark—Use Cases Sharing
Deep Dive of ADBMS Migration to Apache Spark—Use Cases Sharing
 
Simulation Tracking Object Reference Model (STORM)
Simulation Tracking Object Reference Model (STORM)Simulation Tracking Object Reference Model (STORM)
Simulation Tracking Object Reference Model (STORM)
 
Oracle Fuson Middleware Diagnostics, Performance and Troubleshoot
Oracle Fuson Middleware Diagnostics, Performance and TroubleshootOracle Fuson Middleware Diagnostics, Performance and Troubleshoot
Oracle Fuson Middleware Diagnostics, Performance and Troubleshoot
 
NetWork - 15.10.2011 - Applied code generation in .NET
NetWork - 15.10.2011 - Applied code generation in .NET NetWork - 15.10.2011 - Applied code generation in .NET
NetWork - 15.10.2011 - Applied code generation in .NET
 
OSCon - Performance vs Scalability
OSCon - Performance vs ScalabilityOSCon - Performance vs Scalability
OSCon - Performance vs Scalability
 
ScalaClean at ScalaSphere 2019
ScalaClean at ScalaSphere 2019ScalaClean at ScalaSphere 2019
ScalaClean at ScalaSphere 2019
 

Kürzlich hochgeladen

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Kürzlich hochgeladen (20)

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

Scala io2013 : Our journey from UML/MDD to Scala macros

  • 1. Our journey from UML/MDD to Scala macros Hayssam Saleh
  • 2. Summary • What this talk is about ? o Why did we choose UML ? o Why did we move from UML to DSL o Our experience in designing a DSL on top of Slick using Scala macros. • The macro-based DSL on top of Slick • Implementation o How macros work o @Model annotation-macro o Dynamic methods statically compiled
  • 3. Why did we move from UML to scala macros ?
  • 4. Why UML ? • Encapsulation o Hide implementation details and expose relevant abstractions only • Communication o Product owner and dev team understand each other • Quality o Boilerplate code is generated with respect to the architect guidelines. Dev team focus on business rules
  • 5. Why not UML ? • Lack of efficiency o Any modification require code regeneration  UML to XMI (20 % - more or less)  XMI to code (78% - more or more)  Code to bytecode (2% - much less) o Excessive generation time  Code is regenerated for all model entities regardless of whether they were modified o Almost inexistent (real life) collaborative capabilities  Always locked model syndrome  Anyone tried to merge UML models on a regular basis ? • Impedance mismatch o Not all concepts are easily represented in UML
  • 7. Why not Scala macros ? • DSL design is complex o We are used to apply existing patterns o Are we used to design grammars ? • Difficult to develop and maintain o Development at the meta-level o Hey, we’re working on the AST
  • 9. The DSL Goal • Allow the product owner and the developer o to share info about the static representation of the system (The database model in our case) • The product owner should be able to read it • The developer should be able to compile it
  • 10. The good old architecture http://www.mywebsite.com Controller Controller Service Service DAO DAO Model Model Model Persistence Persistence layer layer
  • 11. Why Slick as the persistence framework • Why Slick as a persistence framework o Because it ’s not an ORM so we’ve got   DBA is happy : No more huge SQL requests that makes SQL auditing difficult   Network is happy : No unnecessary round trip   Webserver is happy : no more objects to proxify €€€ When the customer is happy my boss is happy too
  • 12. Why Slick as the persistence framework • What we lost of columns to update o Automatic detection  Who cares ? • Unit of I/O defaults to 8K for Postgres, Oracle, SQLServer …  So for most cases (to say the least), updating the whole object has no real impact on performance o Automatic inserts of dependent objects  Our use case focus is on scalable OLTP applications  Is it really an issue in OLTP ? • • Do we really want the framework to guess what we’re doing ? Does it justify the overhead ? • • • We’ve got actors We’ve got transactions We’ve got joins  We’ve got to rethink our persistence patterns
  • 13. A Slick-macros example Timestamp all rows Timestamp all rows 1..1 relationship 1..1 relationship 0..1 relationship 0..1 relationship Embedded value Embedded value Constraints Constraints *..* relationship *..* relationship
  • 19. Slick Mapping generated by the macro
  • 21. Where did the Boilerplate code goes ? Scala source code Scala source code Boilerplat Boilerplat ee XML / XML / Scala / / … Scala … Annotations Abstract Syntax Tree Abstract Syntax Tree Boilerplate code Java Byte Code Java Byte Code Runtime Runtime
  • 22. Outputting the Trees AST nodes have extractors that definitely help
  • 23. Part 2 Dynamic methods Statically compiled
  • 24. Simplify Querying • Simplify finders o Instead of this o Write this (pseudo-code) def macros def macros
  • 25. Simplify Querying • Simplify update o Instead of this o Write this def macro def macro Argument names and types are known at call site only Argument names and types are known at call site only and still this code remains typechecked at compile time and still this code remains typechecked at compile time
  • 27. A mix of Dynamic and Scala-macros • First the Slick Query object gets the Dynamic • trait Since arguments are all named we define the applyDynamicNamed method as a macro o Def macros are applied at call site, we can thus typecheck at call site against the prefix object.
  • 28. Conclusion • As a developer o It was almost  A copy/paste task and AST node substitution o Made easier using the quasiquote feature • As a user o Much less code to maintain o Reduced time to deliver o No runtime overhead
  • 29. Source code • Slick-macros @hayssams : http://www.github.com/ebiznext/slick-macros
  • 30. References • Scala macros @xeno_by : http://docs.scalalang.org/overviews/macros/usecases.html • Slick @szeiger : http://slick.typesafe.com/docs/#talks Another source about macros you may find useful

Hinweis der Redaktion

  1. Encapsulation : c’est plus pratique qu’un fichier HBM tuyauterie
  2. Les points faibles Productivit » Faiblesse dans l’’expressivté de certains concepts conduit à multiplier les stéréotypes
  3. Vu que pour toutt I/O de moins de 8K, le sgbd écrit 8K alors updater 1k ou 8k revient au même Si tu ajoutes un adresse à une personne Quand tu persisteras la personne alors hibernate persistera aussi l’adresse
  4. () === Company.apply() qui renvoie en fait un objet Query de Slick
  5. On ne connaît aps le type des paramètres à la définition de la fonction ni le nom des paramètres puisqu’il dépendent du contexte d’appel cad de la table sur laquelle on est entrain de faire l’update et Les colones qu’on veut mettre à jour.
  6. Dans le doupdate on aura toujours des name = bvlue en paramètre Donc dans le cas de Dynamic, c la méthode applyDyn… qui est appelée quand les paramètres sont nommés