siga a doutrina certa
TRANSCRIPT
![Page 1: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/1.jpg)
DoctrineSiga a doutrina certa
Fabio B. Silva :github.com/FabioBatSilva / [email protected] / @FabioBatSilva
![Page 2: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/2.jpg)
Quem é esse cara ai ?• Fabio B. Silva
• Desenvolvedor php
• Desenvolvedor java
• Doctrine core developer
• @FabioBatSilva
• github.com/FabioBatSilva
• Alcoolatra nas horas vagas
![Page 3: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/3.jpg)
AGENDA
![Page 4: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/4.jpg)
ORM● Baseado no JPA (Hibernate / EJB / Nhibernate)● Construído sobre componentes● Data Mapper● Objetos Simples● DQL● Otimizado● Performance
![Page 5: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/5.jpg)
Classe Simples
![Page 6: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/6.jpg)
EntityManagerPonte central de acesso as funcionalidades do ORM
![Page 7: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/7.jpg)
EntityManagerPonte central de acesso as funcionalidades do ORM
![Page 8: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/8.jpg)
EntityManagerPonte central de acesso as funcionalidades do ORM
![Page 9: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/9.jpg)
Relacionamentos
● OneToOne● ManyToOne● OneToMany● ManyToMany
![Page 10: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/10.jpg)
RelacionamentosOneToOne
![Page 11: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/11.jpg)
RelacionamentosManyToOne
![Page 12: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/12.jpg)
RelacionamentosOneToMany
![Page 13: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/13.jpg)
RelacionamentosManyToMany
![Page 14: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/14.jpg)
Fetch Mode
● EAGER● LAZY (default)● EXTRA_LAZY
![Page 15: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/15.jpg)
Fetch ModeEAGER
Relacionamento é carregado junto com a entidade
![Page 16: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/16.jpg)
Fetch ModeLAZY
Carrega o relacionamento apenas quando é invocado
![Page 17: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/17.jpg)
Fetch ModeEXTRA_LAZY
Carrega o relacionamento apenas quando um elemento é invocado
![Page 18: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/18.jpg)
Cascade Operations
● persist● remove● merge● detach● all
Operações executadas nos relacionamentos
![Page 19: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/19.jpg)
Herança
● Concrete Table Inheritance● Single Table Inheritance● Class Table Inheritance
![Page 20: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/20.jpg)
Herança
Uma classe em uma tabela
● Concrete Table Inheritance● Single Table Inheritance● Class Table Inheritance
![Page 21: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/21.jpg)
HerançaConcrete table inheritance
![Page 22: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/22.jpg)
HerançaConcrete table inheritance
![Page 23: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/23.jpg)
Herança
Várias classes em uma mesma tabela
● Concrete Table Inheritance● Single Table Inheritance● Class Table Inheritance
![Page 24: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/24.jpg)
HerançaSingle table inheritance
![Page 25: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/25.jpg)
HerançaSingle table inheritance
![Page 26: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/26.jpg)
Herança
Várias classes em várias tabelas
● Concrete Table Inheritance● Single Table Inheritance● Class Table Inheritance
![Page 27: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/27.jpg)
HerançaClass table inheritance
![Page 28: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/28.jpg)
HerançaClass table inheritance
![Page 29: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/29.jpg)
DQLDoctrine Query Language
● DQL : Doctrine Query Language● Usa Classes e propriedades invés de tabelas e colunas● Normalmente retorna uma lista de entidades● Parseado para SQL nativa● Cross database
![Page 30: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/30.jpg)
DQL
![Page 31: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/31.jpg)
Perguntas ?
![Page 32: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/32.jpg)
ORMs não tem boa performance ...● São lentos● Complicados de usar● Complicados de configurar● Só podem ser usados para coisas simples
![Page 33: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/33.jpg)
ORMs não tem boa performance ...● O problema é cultural● Desenvolvedores usam ORM porque não conhecem SQL e SGBDs● Conheça bancos de dados antes de usar um ORM● ORM não substitui PDO, são construídos sobre ele● A abstração tem um custo● Read the fucking manual
![Page 34: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/34.jpg)
Best Practices.
![Page 35: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/35.jpg)
Best Practices :Não use atributos públicos
![Page 36: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/36.jpg)
Best Practices :Não use caracteres especiais
![Page 37: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/37.jpg)
Best Practices :Atenção no mapeamento dos relacionamentos
Lado inverso apenas realmente quando for usa-lo
![Page 38: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/38.jpg)
Best Practices :Evite chaves compostas
Trabalho extra para resolver o identificador
![Page 39: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/39.jpg)
Best Practices :Evite chaves compostas
![Page 40: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/40.jpg)
Best Practices :Cuidado no uso de eventos
Evento é disparado para todas as entidades persistidas.
![Page 41: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/41.jpg)
Best Practices :Cuidado no uso de eventos
![Page 42: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/42.jpg)
Best Practices :Cuidado no uso de eventos
version_compare(DOCTRINE_VERSION, '2.4-DEV', '>=')
![Page 43: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/43.jpg)
Best Practices :Query builder
WTF ???
![Page 44: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/44.jpg)
Best Practices :Query builder
![Page 45: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/45.jpg)
Best Practices :Get reference
Carrega a entidade apenas para persistir
![Page 46: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/46.jpg)
Best Practices :Get reference
![Page 47: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/47.jpg)
Best Practices :Repository
Evite lógica no Controller
![Page 48: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/48.jpg)
Best Practices :Repository
![Page 49: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/49.jpg)
Best Practices :Fetch join association
Três consultas executadas
![Page 50: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/50.jpg)
Best Practices :Fetch join association
![Page 51: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/51.jpg)
Best Practices :Partial objects
Seleciona todos os atributos da entidade
![Page 52: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/52.jpg)
Best Practices :Partial objects
![Page 53: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/53.jpg)
Best Practices :Named Queries
![Page 54: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/54.jpg)
Best Practices :Named Native Queries
![Page 55: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/55.jpg)
CacheMelhor amigo da performance
● Metadata Cache● Query Cache● Result Cache
![Page 56: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/56.jpg)
CacheMelhor amigo da performance
● Metadata Cache● Query Cache● Result Cache
Cache dos mapeamentos das entidades
![Page 57: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/57.jpg)
CacheMelhor amigo da performance
● Metadata Cache● Query Cache● Result Cache
Cache dos parser de DQL para SQL nativa
![Page 58: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/58.jpg)
CacheMelhor amigo da performance
● Metadata Cache● Query Cache● Result Cache
Cache dos resultados de consultas
![Page 59: Siga a doutrina certa](https://reader034.vdocuments.pub/reader034/viewer/2022051016/5598a06b1a28abaa0a8b45e6/html5/thumbnails/59.jpg)
DoctrineSiga a doutrina certa
Perguntas ???
Fabio B. Silva :github.com/FabioBatSilva / [email protected] / @FabioBatSilva