SlideShare une entreprise Scribd logo
1  sur  40
Télécharger pour lire hors ligne
ORM Hero
Hello!
I am Simone Di Maulo
Software Engineer @ AdEspresso
OOP
FP
BEER
@toretto460
Why do you need
an ORM
?
IMPEDANCE
MISMATCH
RBDMS
Objects
Object reference
Integer
Float
Double
String
DateTime
…
Table Row
ForeignKey
Integer
Float
Double
String
Date
…
PHP
Author Book
Author
Book
Book
Common
mistake
Magic
Magic
> Mapping to a relational database involves lots of repetitive,
boiler-plate code.
A framework that allows me to avoid 80% of that is
worthwhile even if it is only 80%.
The problem is in me for pretending it's 100%.
http://martinfowler.com/bliki/OrmHate.html
- Martin Fowler -
HOW DOES IT
WORK ¿
METADATA
/**
* @ORMTable(name=“author")
* @ORMEntity
*/
class Author
{
/**
* @ORMColumn(name=“id", type=“string")
* @ORMId
*/
private $id;
/**
* @ORMColumn(name=“name", type="string", length=255)
*/
private $name;
/**
* @ORMOneToMany(targetEntity=“Book", mappedBy=“author",
* cascade={“persist"})
*/
private $books;
}
MAPPING
/** @ORMTable(name="book") @ORMEntity */
class Book
{
/**@ORMColumn(name="id", type="string") @ORMId()*/
private $id;
/**@ORMManyToOne(targetEntity="Author", inversedBy="books") */
private $author;
/**@ORMColumn(name="publisher", type="string", length=255) */
private $publisher;
/**@ORMColumn(name="title", type="string", length=255) */
private $title;
/**@ORMColumn(name="published_at", type="datetime",
* nullable=false)
*/
private $publishedAt;
}
MAPPING
IDENTITY
MAP
$em->find(Author::class, $authorId);
// query
$author1 = $em->find(Author::class, 1);
// no query
$author2 = $em->find(Author::class, 1);
$author1 === $author2
// bypass the identity map
// a query were submitted to the DB
$authorRepository->findByName($authorName);
IDENTIFIERS
$user = User::register(/*..*/);
$em->persist($user);
$em->flush()
$user = User::register(/*..*/);
$em->persist($user);
$em->flush()
UUId
Auto Increment
Sequence
$user = User::register(/*..*/);
$em->persist($user);
$em->flush()
UUId
Auto Increment
Sequence
echo $user->getId();
echo $user->getId();
echo $user->getId();
$user = User::register(/*..*/);
$em->persist($user);
$em->flush()
UUId
// null
// 1
// 1
Auto Increment
Sequence
echo $user->getId();
echo $user->getId();
echo $user->getId();
$user = User::register(/*..*/);
$em->persist($user);
$em->flush()
UUId
// null
// 1
// 1
Auto Increment
// null
// null
// 1
Sequence
echo $user->getId();
echo $user->getId();
echo $user->getId();
$user = User::register(/*..*/);
$em->persist($user);
$em->flush()
UUId
// 2840555c-54ab-aa68-96
// 2840555c-54ab-aa68-96
// 2840555c-54ab-aa68-96
// null
// 1
// 1
Auto Increment
// null
// null
// 1
Sequence
echo $user->getId();
echo $user->getId();
echo $user->getId();
Unit of work
Unit of Work
$this->em->persist($author);
DETECT 

CHANGES
$author = $em->find(Author::class, $authorId);


$author->addBook(. . .);


$this->em->flush();
IMPLICIT
/**
* @Entity
* @ChangeTrackingPolicy(
* “DEFERRED_IMPLICIT"
* )
*/
class Author{}
/**
* @Entity
* @ChangeTrackingPolicy("DEFERRED_EXPLICIT")
*/
class Author{}
$this->em->persist($alessandro);
$this->em->flush();
EXPLICIT
use DoctrineCommonNotifyPropertyChanged,
DoctrineCommonPropertyChangedListener;
/**
* @Entity
* @ChangeTrackingPolicy(“NOTIFY")
*/
class Author implements NotifyPropertyChanged
{
private $_listeners = array();
public function addPropertyChangedListener(PropertyChangedListener
$listener)
{
$this->_listeners[] = $listener;
}
}
foreach ($this->_listeners as $listener) {
$listener->propertyChanged($this, $propName, $oldValue, $newValue);
}
NOTIFY
Read
DEMO
Thanks to https://github.com/Ocramius/Doctrine2StepHydration
DON’T
complain
caches DOMAIN
ENTITY MANAGER
UNIT OF WORK REPOSITORY
See DoctrineCache @ SymfonyDayIt 2015 - https://vimeo.com/144858752
caches DOMAIN
ENTITY MANAGER
UNIT OF WORK REPOSITORY
metadata
cache
sql cache
result
cache
identity
map
2° level
cache
See DoctrineCache @ SymfonyDayIt 2015 - https://vimeo.com/144858752
USE THE
RIGHT TOOL
consider alternatives for :
Reporting
Append only data
CQRS
QUESTIONS
THANKS
https://joind.in/talk/0cc4f

Contenu connexe

En vedette

ORM, JPA, & Hibernate Overview
ORM, JPA, & Hibernate OverviewORM, JPA, & Hibernate Overview
ORM, JPA, & Hibernate Overview
Brett Meyer
 
Operational risk management (orm)
Operational risk management (orm)Operational risk management (orm)
Operational risk management (orm)
Bushra Angbeen
 

En vedette (8)

Why not ORM
Why not ORMWhy not ORM
Why not ORM
 
ORM is offensive
ORM is offensiveORM is offensive
ORM is offensive
 
ORM: Object-relational mapping
ORM: Object-relational mappingORM: Object-relational mapping
ORM: Object-relational mapping
 
ORM을 활용할 경우의 설계, 개발 과정
ORM을 활용할 경우의 설계, 개발 과정ORM을 활용할 경우의 설계, 개발 과정
ORM을 활용할 경우의 설계, 개발 과정
 
Reform: путь к лучшему ORM
Reform: путь к лучшему ORMReform: путь к лучшему ORM
Reform: путь к лучшему ORM
 
Hibernate ORM: Tips, Tricks, and Performance Techniques
Hibernate ORM: Tips, Tricks, and Performance TechniquesHibernate ORM: Tips, Tricks, and Performance Techniques
Hibernate ORM: Tips, Tricks, and Performance Techniques
 
ORM, JPA, & Hibernate Overview
ORM, JPA, & Hibernate OverviewORM, JPA, & Hibernate Overview
ORM, JPA, & Hibernate Overview
 
Operational risk management (orm)
Operational risk management (orm)Operational risk management (orm)
Operational risk management (orm)
 

Similaire à Orm hero

Open Source Package Php Mysql 1228203701094763 9
Open Source Package Php Mysql 1228203701094763 9Open Source Package Php Mysql 1228203701094763 9
Open Source Package Php Mysql 1228203701094763 9
isadorta
 
DDD on example of Symfony (SfCampUA14)
DDD on example of Symfony (SfCampUA14)DDD on example of Symfony (SfCampUA14)
DDD on example of Symfony (SfCampUA14)
Oleg Zinchenko
 
Debugging and Error handling
Debugging and Error handlingDebugging and Error handling
Debugging and Error handling
Suite Solutions
 

Similaire à Orm hero (20)

Don't scrape, Glean!
Don't scrape, Glean!Don't scrape, Glean!
Don't scrape, Glean!
 
A Toda Maquina Con Ruby on Rails
A Toda Maquina Con Ruby on RailsA Toda Maquina Con Ruby on Rails
A Toda Maquina Con Ruby on Rails
 
Um2010
Um2010Um2010
Um2010
 
Ruby Hell Yeah
Ruby Hell YeahRuby Hell Yeah
Ruby Hell Yeah
 
John Rowley Notes
John Rowley NotesJohn Rowley Notes
John Rowley Notes
 
/Regex makes me want to (weep|give up|(╯°□°)╯︵ ┻━┻)\.?/i
/Regex makes me want to (weep|give up|(╯°□°)╯︵ ┻━┻)\.?/i/Regex makes me want to (weep|give up|(╯°□°)╯︵ ┻━┻)\.?/i
/Regex makes me want to (weep|give up|(╯°□°)╯︵ ┻━┻)\.?/i
 
REST in practice with Symfony2
REST in practice with Symfony2REST in practice with Symfony2
REST in practice with Symfony2
 
Rest in practice con Symfony2
Rest in practice con Symfony2Rest in practice con Symfony2
Rest in practice con Symfony2
 
Write your Ruby in Style
Write your Ruby in StyleWrite your Ruby in Style
Write your Ruby in Style
 
Open Source Package PHP & MySQL
Open Source Package PHP & MySQLOpen Source Package PHP & MySQL
Open Source Package PHP & MySQL
 
Open Source Package Php Mysql 1228203701094763 9
Open Source Package Php Mysql 1228203701094763 9Open Source Package Php Mysql 1228203701094763 9
Open Source Package Php Mysql 1228203701094763 9
 
Origami, a monadic fold library for Scala
Origami, a monadic fold library for ScalaOrigami, a monadic fold library for Scala
Origami, a monadic fold library for Scala
 
PHP MySQL
PHP MySQLPHP MySQL
PHP MySQL
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Code with Style - PyOhio
Code with Style - PyOhioCode with Style - PyOhio
Code with Style - PyOhio
 
Hacking 101 for developers
Hacking 101 for developersHacking 101 for developers
Hacking 101 for developers
 
Code with style
Code with styleCode with style
Code with style
 
How Xslate Works
How Xslate WorksHow Xslate Works
How Xslate Works
 
DDD on example of Symfony (SfCampUA14)
DDD on example of Symfony (SfCampUA14)DDD on example of Symfony (SfCampUA14)
DDD on example of Symfony (SfCampUA14)
 
Debugging and Error handling
Debugging and Error handlingDebugging and Error handling
Debugging and Error handling
 

Dernier

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Dernier (20)

MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
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
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

Orm hero