0
Doctrine 2 – Next Generation ORM Juozas „Joe“ Kaziukėnas (@juokaz) Benjamin Eberlei (@beberlei)
ORM Doctrine 2
PHP and ORMs <ul><li>Object relational mapping
Current frameworks </li><ul><li>Propel (http://www.propelorm.org/)
Doctrine 1.2 (http://www.doctrine-project.org/) </li></ul></ul>
OOP
Object relational mapping <ul><li>Models (objects)
Relations </li></ul>
ORM (Active Record)
Querying <ul><li>Different than SQL </li><ul><li>DQL in Doctrine </li></ul><li>Working with models, not tables </li><ul><l...
Database driver specific functionality </li></ul>
<ul>Performance and overhead </ul><ul><li>Hydration (from SQL results to objects)
SQL optimization
Memory usage
Lots of classes and very complicated underlying code
Other issues </li></ul>
Why do you need all this? <ul><li>Faster coding
“Logical” application
Clear business logic
Standards
Not limited to (relational) databases
... Much more </li></ul>
ORM Doctrine 2
Doctrine 2 <ul><li>Complete Rewrite of Doctrine 1
PHP 5.3 and Namespaces
3 Main Packages </li><ul><li>Common
DBAL
ORM </li></ul><li>To be released on  September 1 st  2010
http://www.doctrine-project.org   </li></ul>
DoctrineCommon <ul><li>Cache
ClassLoader
AnnotationParser
Collections (OO-Arrays)
Events </li></ul>
DoctrineDBAL <ul><li>„Implements“ PDO API
Upcoming SlideShare
Loading in...5
×

Doctrine 2 - Next Generation ORM

5,239

Published on

Published in: Technology, Education
0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
5,239
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
66
Comments
0
Likes
5
Embeds 0
No embeds

No notes for slide

Transcript of "Doctrine 2 - Next Generation ORM"

  1. 1. Doctrine 2 – Next Generation ORM Juozas „Joe“ Kaziukėnas (@juokaz) Benjamin Eberlei (@beberlei)
  2. 2. ORM Doctrine 2
  3. 3. PHP and ORMs <ul><li>Object relational mapping
  4. 4. Current frameworks </li><ul><li>Propel (http://www.propelorm.org/)
  5. 5. Doctrine 1.2 (http://www.doctrine-project.org/) </li></ul></ul>
  6. 6. OOP
  7. 7. Object relational mapping <ul><li>Models (objects)
  8. 8. Relations </li></ul>
  9. 9. ORM (Active Record)
  10. 10. Querying <ul><li>Different than SQL </li><ul><li>DQL in Doctrine </li></ul><li>Working with models, not tables </li><ul><li>SELECT * FROM Model_Blog B WHERE B.id = 1 </li></ul><li>Very complicated internals
  11. 11. Database driver specific functionality </li></ul>
  12. 12. <ul>Performance and overhead </ul><ul><li>Hydration (from SQL results to objects)
  13. 13. SQL optimization
  14. 14. Memory usage
  15. 15. Lots of classes and very complicated underlying code
  16. 16. Other issues </li></ul>
  17. 17. Why do you need all this? <ul><li>Faster coding
  18. 18. “Logical” application
  19. 19. Clear business logic
  20. 20. Standards
  21. 21. Not limited to (relational) databases
  22. 22. ... Much more </li></ul>
  23. 23. ORM Doctrine 2
  24. 24. Doctrine 2 <ul><li>Complete Rewrite of Doctrine 1
  25. 25. PHP 5.3 and Namespaces
  26. 26. 3 Main Packages </li><ul><li>Common
  27. 27. DBAL
  28. 28. ORM </li></ul><li>To be released on September 1 st 2010
  29. 29. http://www.doctrine-project.org </li></ul>
  30. 30. DoctrineCommon <ul><li>Cache
  31. 31. ClassLoader
  32. 32. AnnotationParser
  33. 33. Collections (OO-Arrays)
  34. 34. Events </li></ul>
  35. 35. DoctrineDBAL <ul><li>„Implements“ PDO API
  36. 36. Inspired by Zend_Db, ezcDatabase and PEAR MDB2
  37. 37. Convenience Methods
  38. 38. Database Schema Abstraction
  39. 39. Database Type Abstraction
  40. 40. Soon: SQL Query Object </li></ul>
  41. 41. Supported DoctrineDBAL Vendors <ul><li>PDO </li><ul><li>MySQL
  42. 42. PostgreSQL
  43. 43. Sqlite
  44. 44. DB2
  45. 45. SqlSrv </li></ul><li>OCI8
  46. 46. IBM_DB2 </li></ul>
  47. 47. DoctrineDBALSchema
  48. 48. DoctrineDBALSchema
  49. 49. DoctrineORM Architecture <ul><li>DataMapper (no Active Record) </li><ul><li>Plain Old PHP Object (No Base Class or Interface)
  50. 50. Using PHP 5.3 Reflection </li></ul><li>Clean API
  51. 51. Killed the Magic
  52. 52. Focus on Persistence
  53. 53. Based on JSR-317/JPA Specification </li></ul>
  54. 54. DoctrineORM Architecture <ul><li>Entities </li><ul><li>Not a final class or contain any final methods.
  55. 55. Restrictions for __wakeup() or __clone()
  56. 56. Constructor is never invoked by Doctrine (!)
  57. 57. May contain non-optional constructor arguments
  58. 58. May be part of inheritance hierachy
  59. 59. Object Assocations are Relations in Database </li></ul></ul>
  60. 60. Example Entity
  61. 61. DoctrineORM Metadata Mapping <ul><li>Several Supported Mapping Drivers </li><ul><li>Annotations (In PHPDoc)
  62. 62. XML
  63. 63. YAML
  64. 64. Plain PHP
  65. 65. Database (Reverse Engineering) </li></ul></ul>
  66. 66. DoctrineORM Annotation Mapping
  67. 67. DoctrineORM XML Mapping
  68. 68. DoctrineORMUnitOfWork <ul><li>DoctrineORMEntityManager Primary API
  69. 69. Transactional Write Behind (uff?) </li><ul><li>Aggregate Database Writes with EntityManager::flush()
  70. 70. Always wrapped in single Transaction
  71. 71. No explicit update trigger necessary
  72. 72. Impressive Write Performance: </li><ul><li>Insert 10000 Objects in 3.5 (Sqlite), 6.4 (MySQL), 9.1 (Postgres) or 9.8 (Oracle) seconds
  73. 73. Magnitudes Faster than Propel 1.5 (5x) and Doctrine 1 (9x) </li></ul></ul></ul>
  74. 74. Lifecycle: Persist New Entities
  75. 75. Lifecycle: Find Entities By ID
  76. 76. Lifecycle: Update and Remove
  77. 77. Doctrine Query Language <ul><li>Object Query Language
  78. 78. SQL Like Syntax using Class- and Field-Names
  79. 79. DQL Query transformed into: </li><ul><li>SQL Query
  80. 80. Column to Class & Field Mappings
  81. 81. Both cached for zero overhead of DQL! </li></ul><li>SELECT, UPDATE, DELETE
  82. 82. Optionally Query Builder
  83. 83. Full Result Set Hydration or Iterator </li></ul>
  84. 84. Doctrine Query Language <ul><li>High read performance, 10000 Rows </li><ul><li>A Scalar set of rows: 0.17 secs
  85. 85. Array Hydration: 0.34 secs
  86. 86. Two-Level Nested Array Hydration: 0.75 secs
  87. 87. Objects without Proxies: 0.68 secs
  88. 88. Objects with Proxies: 2.73 </li></ul><li>How does this relate? </li><ul><li>About as fast as Propel 1.5
  89. 89. 20-700% faster as Doctrine 1 </li></ul></ul>
  90. 90. Simple DQL Query
  91. 91. Advanced DQL Query
  92. 92. DQL Array Hydration
  93. 93. DQL Array Hydration SQL <ul>SELECT z0_.bug_description AS bug_description0, z0_.bug_created AS bug_created1, z0_.bug_status AS bug_status2, z0_.bug_id AS bug_id3, z1_.account_name AS account_name4, z1_.account_id AS account_id5, z2_.account_name AS account_name6, z2_.account_id AS account_id7, z3_.product_name AS product_name8, z3_.product_id AS product_id9 FROM zf_bugs z0_ INNER JOIN zf_accounts z1_ ON z0_.engineer_id = z1_.account_id INNER JOIN zf_accounts z2_ ON z0_.reporter_id = z2_.account_id INNER JOIN zf_bugs_products z4_ ON z0_.bug_id = z4_.bug_id INNER JOIN zf_products z3_ ON z3_.product_id = z4_.product_id ORDER BY z0_.bug_created DESC </ul>
  94. 94. Native SQL <ul><li>Remember: DQL = SQL + Result Mapping
  95. 95. Support for Native SQL Queries </li></ul>
  96. 96. More Features <ul><li>Inheritance (All of Fowlers Three)
  97. 97. Optimistic and Pessimistic Locking
  98. 98. Mapping to DDL SQL Generation (Create, Update, Drop Schema)
  99. 99. Ordered Collections (by foreign field)
  100. 100. Lifecycle Event System
  101. 101. Composite Key Support
  102. 102. … and lots of stuff planned! </li></ul>
  103. 103. Thank you! Rate a talk: http://joind.in/talk/view/1769
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×