SlideShare une entreprise Scribd logo
1  sur  51
Télécharger pour lire hors ligne
Transparent Object
                            Persistence
                          (within FLOW3)
                           Karsten Dambekalns <karsten@typo3.org>




                                                                    Inspiring people to
                                                                    share
Samstag, 16. Mai 2009
“DDD persistence”
                        Domain Models encapsulate behavior and data

                        Concerned about the problem – only

                        Infrastructure is of no relevance



                        Unfortunately you need to be aware of the infrastructure at
                        some point – at least a little




                                                                        Inspiring people to
                                                                        share
Samstag, 16. Mai 2009
Entities
                        Identity is important

                        Are not defined by their attributes

                        Examples could be...

                        •   Projects

                        •   Developers




                                                             Inspiring people to
                                                             share
Samstag, 16. Mai 2009
Value objects
                        Have no indentity

                        Their value is of importance

                        Are interchangeable

                        Examples could be...

                        •   Colors

                        •   Numbers

                        •   Tags in Forge



                                                       Inspiring people to
                                                       share
Samstag, 16. Mai 2009
Aggregates
                        Cluster associated objects

                        Have a boundary and a root

                        The root is a specific entity

                        References from outside point to the root

                        An example for an aggregate:

                        •   Project




                                                                    Inspiring people to
                                                                    share
Samstag, 16. Mai 2009
Repositories
                        Provide access to entities (and aggregates)

                        Allow to find a starting point for traversal

                        Persisted objects can be searched for

                        Queries can be built in various ways

                        Handle storage of additions and updates




                                                                      Inspiring people to
                                                                      share
Samstag, 16. Mai 2009
A Domain Model
            Project
           Repository

                        Project
                                        Developer


                                   SVN                twitter
                                  Account             Account

                                             Inspiring people to
                                             share
Samstag, 16. Mai 2009
A Domain Model
            Project
           Repository
                   it


                        Project
              Repos



                                        Developer


                                   SVN                twitter
                                  Account             Account

                                             Inspiring people to
                                             share
Samstag, 16. Mai 2009
A Domain Model
            Project
           Repository
                   it


                        Project
              Repos



                                        Developer


                                   SVN                twitter
                                  Account             Account

                                             Inspiring people to
                                             share
Samstag, 16. Mai 2009
A Domain Model
            Project
           Repository
                   it


                        Project
              Repos



                                        Developer


                                   SVN                twitter
                                  Account             Account

                                             Inspiring people to
                                             share
Samstag, 16. Mai 2009
A Domain Model
            Project
           Repository
                   it


                            Project
              Repos



                                            Developer
                        Aggre-
                        gates          SVN                twitter
                                      Account             Account

                                                 Inspiring people to
                                                 share
Samstag, 16. Mai 2009
A Domain Model

                              Developer


                         SVN          twitter
                        Account       Account


                                                Inspiring people to
                                                share
Samstag, 16. Mai 2009
Using FLOW3...
                        You just implement the model

                        No need to care about persisting your model

                        FLOW3 handles this for you – transparently

                        Even a Repository only needs little work

                        Define relevant metadata in the source file using annotations




                                                                       Inspiring people to
                                                                       share
Samstag, 16. Mai 2009
@nnotations used




                               Inspiring people to
                               share
Samstag, 16. Mai 2009
@nnotations used
                        @entity




                                  Inspiring people to
                                  share
Samstag, 16. Mai 2009
@nnotations used
                        @entity

                        @valueobject




                                       Inspiring people to
                                       share
Samstag, 16. Mai 2009
@nnotations used
                        @entity

                        @valueobject

                        @var




                                       Inspiring people to
                                       share
Samstag, 16. Mai 2009
@nnotations used
                        @entity

                        @valueobject

                        @var

                        @transient




                                       Inspiring people to
                                       share
Samstag, 16. Mai 2009
@nnotations used
                        @entity

                        @valueobject

                        @var

                        @transient

                        @uuid




                                       Inspiring people to
                                       share
Samstag, 16. Mai 2009
@nnotations used
                        @entity

                        @valueobject

                        @var

                        @transient

                        @uuid

                        @identity




                                       Inspiring people to
                                       share
Samstag, 16. Mai 2009
@nnotations used
                        @entity

                        @valueobject

                        @var

                        @transient

                        @uuid

                        @identity

                        @lazy



                                       Inspiring people to
                                       share
Samstag, 16. Mai 2009
Persistence Manager
                        Mostly invisible to developers

                        Manages additions of and updates to objects

                        Concerned only about objects in repositories

                        Collects objects and hands over to backend

                        Allows for objects being persisted at any time

                        Automatically called to persist at end of script run




                                                                          Inspiring people to
                                                                          share
Samstag, 16. Mai 2009
Simplified stack




                        SQLite   PgSQL   MySQL   ...

                                                       Inspiring people to
                                                       share
Samstag, 16. Mai 2009
Simplified stack



                                 PDO                   ...
                        SQLite         PgSQL   MySQL         ...

                                                                   Inspiring people to
                                                                   share
Samstag, 16. Mai 2009
Simplified stack


                                 TYPO3 Content Repository
                                 PDO                   ...
                        SQLite         PgSQL   MySQL         ...

                                                                   Inspiring people to
                                                                   share
Samstag, 16. Mai 2009
Simplified stack

                                    FLOW3 Persistence

                                 TYPO3 Content Repository
                                 PDO                    ...
                        SQLite         PgSQL   MySQL          ...

                                                                    Inspiring people to
                                                                    share
Samstag, 16. Mai 2009
Simplified stack
                        Application            Application

                                    FLOW3 Persistence

                                 TYPO3 Content Repository
                                 PDO                    ...
                        SQLite         PgSQL   MySQL          ...

                                                                    Inspiring people to
                                                                    share
Samstag, 16. Mai 2009
Simplified stack
                         FLOW3     Persistence




                                   Persistence
                        TYPO3 CR
                                    Backend

                                            Inspiring people to
                                            share
Samstag, 16. Mai 2009
TYPO3 CR
                        FLOW3

                                   Inspiring people to
                                   share
Samstag, 16. Mai 2009
Transparent persistence
                        Explicit support for Domain-Driven Design

                        Class Schemata are defined by the Domain Model class

                        •   No need to write an XML or YAML schema definition

                        •   No need to define the database model and object model
                            multiple times at different places

                        Automatic persistence in the JSR-283 based Content Repository

                        Legacy data sources can be mounted




                                                                       Inspiring people to
                                                                       share
Samstag, 16. Mai 2009
Query Factory
                        Creates a query for you

                        Decouples persistence layer from backend

                        Must be implemented by backend

                        API with one method:

                        •   public function create($className);




                                                                   Inspiring people to
                                                                   share
Samstag, 16. Mai 2009
Query objects
                        Represent a query for an object type

                        Allow criteria to be attached

                        Must be implemented by backend

                        Simple API

                        •   execute()

                        •   matching()

                        •   equals(), lessThan(), ...

                        •   ...

                                                               Inspiring people to
                                                               share
Samstag, 16. Mai 2009
Object reconstitution
                        When fetching objects the content repository looks for
                        matching nodes

                        The nodes are mapped to objects by a data mapper

                        Reconstitution

                        •   does not call __construct()

                        •   restores all non-transient properties

                        •   reinjects dependencies (skips constructor arguments)




                                                                        Inspiring people to
                                                                        share
Samstag, 16. Mai 2009
Object reconstitution
                public function map(F3PHPCRNodeIteratorInterface $nodes) {
                    $objects = array();
                    foreach ($nodes as $node) {
                        $object = $this->mapSingleNode($node);
                        $this->persistenceManager->getSession()->registerReconstitutedObject($object);
                        $objects[] = $object;
                    }

                        return $objects;
                }



                               F3TYPO3CRFLOW3PersistenceDataMapper




                                                                                     Inspiring people to
                                                                                     share
Samstag, 16. Mai 2009
Object reconstitution
                $explodedNodeTypeName = explode(':', $node->getPrimaryNodeType()->getName(), 2);
                $className = str_replace('_', '', $explodedNodeTypeName[1]);
                $classSchema = $this->persistenceManager->getClassSchema($className);
                $objectConfiguration = $this->objectManager->getObjectConfiguration($className);

                $object = $this->objectBuilder->createEmptyObject($className,
                $objectConfiguration);
                $this->identityMap->registerObject($object, $node->getIdentifier());

                $this->objectBuilder->reinjectDependencies($object, $objectConfiguration);
                $this->thawProperties($object, $node, $classSchema);
                $object->FLOW3_Persistence_memorizeCleanState();



                          F3TYPO3CRFLOW3PersistenceDataMapper




                                                                                 Inspiring people to
                                                                                 share
Samstag, 16. Mai 2009
Object reconstitution
                public function createEmptyObject($objectName, F3FLOW3ObjectConfiguration
                                               $objectConfiguration) {
                    $className = $objectConfiguration->getClassName();

                        if (!in_array('F3FLOW3AOPProxyInterface', class_implements($className))) {
                            throw new F3FLOW3ObjectExceptionCannotReconstituteObject('Cannot create
                            empty instance of the class quot;' . $className . 'quot; because it does not implement
                            the AOP Proxy Interface.', 1234386924);
                        }

                        $object = unserialize('O:' . strlen($className) . ':quot;' . $className . 'quot;:0:{};');
                        $object->FLOW3_AOP_Proxy_setProperty('objectFactory', $this->objectFactory);
                        $object->FLOW3_AOP_Proxy_setProperty('objectManager', $this->objectManager);
                        $object->FLOW3_AOP_Proxy_declareMethodsAndAdvices();

                        return $object;
                }



                                            F3FLOW3ObjectBuilder

                                                                                         Inspiring people to
                                                                                         share
Samstag, 16. Mai 2009
Lazy Loading
                        Loading a full object tree makes sense – or not

                        It does most of the time

                        If your domain model has small aggregates eager loading
                        makes sense

                        If you have expensive to create objects or a lot of smaller ones
                        you don’t always need, lazy loading helps

                        Example: displaying a list of projects doesn’t need the projects
                        details, just the names




                                                                          Inspiring people to
                                                                          share
Samstag, 16. Mai 2009
Lazy Loading
                        Ideally you would not think about lazy loading beyond the
                        addition of the @lazy annotation

                        In practice you need to be aware of some technical issues

                        In place of the real object you get a proxy, so

                        •   you can’t use it at type hinted places

                        •   pass it around without some thinking

                        Using it otherwise works as expected

                        After first use the proxy will be completely gone


                                                                           Inspiring people to
                                                                           share
Samstag, 16. Mai 2009
The LazyLoadingProxy
                public function _loadRealInstance() {
                    $realInstance = $this
                        ->F3_FLOW3_Persistence_LazyLoadingProxy_population
                        ->__invoke();
                    $this
                        ->F3_FLOW3_Persistence_LazyLoadingProxy_parent
                        ->FLOW3_AOP_Proxy_setProperty(
                            $this->F3_FLOW3_Persistence_LazyLoadingProxy_propertyName,
                            $realInstance
                        );

                        return $realInstance;
                }



                               F3FLOW3PersistenceLazyLoadingProxy


                                                                               Inspiring people to
                                                                               share
Samstag, 16. Mai 2009
$dataMapper = $this; // make available to closure...
                $objectStorage = new F3FLOW3PersistenceLazyLoadingProxy(
                    $parent,
                    $propertyName,
                    function() use ($proxyNode, $dataMapper) {
                        $objectStorage = new SplObjectStorage();
                        $itemNodes = $proxyNode->getNodes();
                        foreach ($itemNodes as $itemNode) {
                            $objectNode = $itemNode->getNode('flow3:object');
                            if ($objectNode->getPrimaryNodeType()->getName() ===
                                F3TYPO3CRFLOW3PersistenceBackend::NODETYPE_OBJECTPROXY) {
                                $object = $dataMapper->mapObjectProxyNode($objectNode);
                            } else {
                                $object = $dataMapper->mapSingleNode($objectNode);
                            }
                            $objectStorage->attach($object);
                        }
                        return $objectStorage;
                    }
                );



                          F3TYPO3CRFLOW3PersistenceDataMapper

                                                                               Inspiring people to
                                                                               share
Samstag, 16. Mai 2009
Node structure
                        PHP has more data structures than a content repository, e.g.

                        •   JSR-283 defines multi-valued properties without keys and
                            without stable ordering

                        •   Arrays in PHP have keys and order that are stable and might
                            be important for your code

                        Thus we do some more mapping to node structures




                                                                        Inspiring people to
                                                                        share
Samstag, 16. Mai 2009
Inspiring people to
                        share
Samstag, 16. Mai 2009
Inspiring people to
                        share
Samstag, 16. Mai 2009
Inspiring people to
                        share
Samstag, 16. Mai 2009
Inspiring people to
                        share
Samstag, 16. Mai 2009
Inspiring people to
                        share
Samstag, 16. Mai 2009
Questions!

                                Inspiring people to
                                share
Samstag, 16. Mai 2009
Inspiring people to
                        share
Samstag, 16. Mai 2009
Links
                        FLOW3
                        http://flow3.typo3.org/



                        TYPO3CR
                        http://forge.typo3.org/projects/show/package-typo3cr



                        JSR-283
                        http://jcp.org/en/jsr/detail?id=283




                                                                 Inspiring people to
                                                                 share
Samstag, 16. Mai 2009
Samstag, 16. Mai 2009
Flickr photo credits:
                megapixel13 (barcode), rmrayner (ring), Ducatirider (grapes), Here’s Kate (book shelf)
                Pumpkin pictures:
                http://ptnoticias.com/pumpkinway/


                                                                                     Inspiring people to
                                                                                     share
Samstag, 16. Mai 2009

Contenu connexe

En vedette

Mls Preso March 1 2010
Mls Preso March 1 2010Mls Preso March 1 2010
Mls Preso March 1 2010Hack the Hood
 
Qlubb 101 Webinar Notes
Qlubb 101 Webinar NotesQlubb 101 Webinar Notes
Qlubb 101 Webinar NotesQlubb Info
 
Ataque Al Corazon
Ataque Al CorazonAtaque Al Corazon
Ataque Al CorazonJoel Ferro
 
P6.C Explaining Refraction
P6.C Explaining RefractionP6.C Explaining Refraction
P6.C Explaining Refractionpaulbhill
 
A Kaleidoscopic Analysis of the Sing Up Project [clip]
A Kaleidoscopic Analysis of the Sing Up Project [clip]A Kaleidoscopic Analysis of the Sing Up Project [clip]
A Kaleidoscopic Analysis of the Sing Up Project [clip]Antia G. Ben
 
VIBEWELL Hard Chrome Process
VIBEWELL Hard Chrome Process VIBEWELL Hard Chrome Process
VIBEWELL Hard Chrome Process flyrr
 
03 - Dynamique d’instauration d’une gouvernance régionalisée de la formation ...
03 - Dynamique d’instauration d’une gouvernance régionalisée de la formation ...03 - Dynamique d’instauration d’une gouvernance régionalisée de la formation ...
03 - Dynamique d’instauration d’une gouvernance régionalisée de la formation ...Mohamed Larbi BEN YOUNES
 
Improving the quality of school and out of-school time nutrition programs
Improving the quality of school and out of-school time nutrition programsImproving the quality of school and out of-school time nutrition programs
Improving the quality of school and out of-school time nutrition programsmambrosefrac
 
Social media in the educational workplace
Social media in the educational workplaceSocial media in the educational workplace
Social media in the educational workplaceJosh Allen
 
Implementing a JSR-283 Content Repository in PHP
Implementing a JSR-283 Content Repository in PHPImplementing a JSR-283 Content Repository in PHP
Implementing a JSR-283 Content Repository in PHPKarsten Dambekalns
 
ITALIAN STUDENTS PRESENTED
ITALIAN STUDENTS PRESENTEDITALIAN STUDENTS PRESENTED
ITALIAN STUDENTS PRESENTEDRositsa Dimova
 
March 2009 Build Yr Brand Thru Social Media
March 2009 Build Yr Brand Thru Social MediaMarch 2009 Build Yr Brand Thru Social Media
March 2009 Build Yr Brand Thru Social MediaHack the Hood
 

En vedette (20)

Linux fest 2013
Linux fest 2013Linux fest 2013
Linux fest 2013
 
Mls Preso March 1 2010
Mls Preso March 1 2010Mls Preso March 1 2010
Mls Preso March 1 2010
 
Oreilly Preso Final
Oreilly Preso FinalOreilly Preso Final
Oreilly Preso Final
 
Qlubb 101 Webinar Notes
Qlubb 101 Webinar NotesQlubb 101 Webinar Notes
Qlubb 101 Webinar Notes
 
Virussen Pp De Goeie
Virussen Pp De GoeieVirussen Pp De Goeie
Virussen Pp De Goeie
 
Ataque Al Corazon
Ataque Al CorazonAtaque Al Corazon
Ataque Al Corazon
 
P6.C Explaining Refraction
P6.C Explaining RefractionP6.C Explaining Refraction
P6.C Explaining Refraction
 
A Kaleidoscopic Analysis of the Sing Up Project [clip]
A Kaleidoscopic Analysis of the Sing Up Project [clip]A Kaleidoscopic Analysis of the Sing Up Project [clip]
A Kaleidoscopic Analysis of the Sing Up Project [clip]
 
VIBEWELL Hard Chrome Process
VIBEWELL Hard Chrome Process VIBEWELL Hard Chrome Process
VIBEWELL Hard Chrome Process
 
Plumps for garbage
Plumps for garbagePlumps for garbage
Plumps for garbage
 
03 - Dynamique d’instauration d’une gouvernance régionalisée de la formation ...
03 - Dynamique d’instauration d’une gouvernance régionalisée de la formation ...03 - Dynamique d’instauration d’une gouvernance régionalisée de la formation ...
03 - Dynamique d’instauration d’une gouvernance régionalisée de la formation ...
 
Improving the quality of school and out of-school time nutrition programs
Improving the quality of school and out of-school time nutrition programsImproving the quality of school and out of-school time nutrition programs
Improving the quality of school and out of-school time nutrition programs
 
The Measure
The MeasureThe Measure
The Measure
 
Social media in the educational workplace
Social media in the educational workplaceSocial media in the educational workplace
Social media in the educational workplace
 
Implementing a JSR-283 Content Repository in PHP
Implementing a JSR-283 Content Repository in PHPImplementing a JSR-283 Content Repository in PHP
Implementing a JSR-283 Content Repository in PHP
 
Comic strip i
Comic strip iComic strip i
Comic strip i
 
ITALIAN STUDENTS PRESENTED
ITALIAN STUDENTS PRESENTEDITALIAN STUDENTS PRESENTED
ITALIAN STUDENTS PRESENTED
 
March 2009 Build Yr Brand Thru Social Media
March 2009 Build Yr Brand Thru Social MediaMarch 2009 Build Yr Brand Thru Social Media
March 2009 Build Yr Brand Thru Social Media
 
Linkedin 6.0
Linkedin 6.0Linkedin 6.0
Linkedin 6.0
 
Task 1
Task 1Task 1
Task 1
 

Plus de Karsten Dambekalns

The Perfect Neos Project Setup
The Perfect Neos Project SetupThe Perfect Neos Project Setup
The Perfect Neos Project SetupKarsten Dambekalns
 
Sawubona! Content Dimensions with Neos
Sawubona! Content Dimensions with NeosSawubona! Content Dimensions with Neos
Sawubona! Content Dimensions with NeosKarsten Dambekalns
 
Deploying TYPO3 Neos websites using Surf
Deploying TYPO3 Neos websites using SurfDeploying TYPO3 Neos websites using Surf
Deploying TYPO3 Neos websites using SurfKarsten Dambekalns
 
Profiling TYPO3 Flow Applications
Profiling TYPO3 Flow ApplicationsProfiling TYPO3 Flow Applications
Profiling TYPO3 Flow ApplicationsKarsten Dambekalns
 
Using Document Databases with TYPO3 Flow
Using Document Databases with TYPO3 FlowUsing Document Databases with TYPO3 Flow
Using Document Databases with TYPO3 FlowKarsten Dambekalns
 
How Git and Gerrit make you more productive
How Git and Gerrit make you more productiveHow Git and Gerrit make you more productive
How Git and Gerrit make you more productiveKarsten Dambekalns
 
The agile future of a ponderous project
The agile future of a ponderous projectThe agile future of a ponderous project
The agile future of a ponderous projectKarsten Dambekalns
 
How Domain-Driven Design helps you to migrate into the future
How Domain-Driven Design helps you to migrate into the futureHow Domain-Driven Design helps you to migrate into the future
How Domain-Driven Design helps you to migrate into the futureKarsten Dambekalns
 
Content Repository, Versioning and Workspaces in TYPO3 Phoenix
Content Repository, Versioning and Workspaces in TYPO3 PhoenixContent Repository, Versioning and Workspaces in TYPO3 Phoenix
Content Repository, Versioning and Workspaces in TYPO3 PhoenixKarsten Dambekalns
 
Transparent Object Persistence with FLOW3
Transparent Object Persistence with FLOW3Transparent Object Persistence with FLOW3
Transparent Object Persistence with FLOW3Karsten Dambekalns
 
Implementing a JSR-283 Content Repository in PHP
Implementing a JSR-283 Content Repository in PHPImplementing a JSR-283 Content Repository in PHP
Implementing a JSR-283 Content Repository in PHPKarsten Dambekalns
 
Knowledge Management in der TYPO3 Community
Knowledge Management in der TYPO3 CommunityKnowledge Management in der TYPO3 Community
Knowledge Management in der TYPO3 CommunityKarsten Dambekalns
 
A Content Repository for TYPO3 5.0
A Content Repository for TYPO3 5.0A Content Repository for TYPO3 5.0
A Content Repository for TYPO3 5.0Karsten Dambekalns
 
Introduction to Source Code Management
Introduction to Source Code ManagementIntroduction to Source Code Management
Introduction to Source Code ManagementKarsten Dambekalns
 

Plus de Karsten Dambekalns (20)

The Perfect Neos Project Setup
The Perfect Neos Project SetupThe Perfect Neos Project Setup
The Perfect Neos Project Setup
 
Sawubona! Content Dimensions with Neos
Sawubona! Content Dimensions with NeosSawubona! Content Dimensions with Neos
Sawubona! Content Dimensions with Neos
 
Deploying TYPO3 Neos websites using Surf
Deploying TYPO3 Neos websites using SurfDeploying TYPO3 Neos websites using Surf
Deploying TYPO3 Neos websites using Surf
 
Profiling TYPO3 Flow Applications
Profiling TYPO3 Flow ApplicationsProfiling TYPO3 Flow Applications
Profiling TYPO3 Flow Applications
 
Using Document Databases with TYPO3 Flow
Using Document Databases with TYPO3 FlowUsing Document Databases with TYPO3 Flow
Using Document Databases with TYPO3 Flow
 
i18n and L10n in TYPO3 Flow
i18n and L10n in TYPO3 Flowi18n and L10n in TYPO3 Flow
i18n and L10n in TYPO3 Flow
 
FLOW3-Workshop F3X12
FLOW3-Workshop F3X12FLOW3-Workshop F3X12
FLOW3-Workshop F3X12
 
Doctrine in FLOW3
Doctrine in FLOW3Doctrine in FLOW3
Doctrine in FLOW3
 
How Git and Gerrit make you more productive
How Git and Gerrit make you more productiveHow Git and Gerrit make you more productive
How Git and Gerrit make you more productive
 
The agile future of a ponderous project
The agile future of a ponderous projectThe agile future of a ponderous project
The agile future of a ponderous project
 
How Domain-Driven Design helps you to migrate into the future
How Domain-Driven Design helps you to migrate into the futureHow Domain-Driven Design helps you to migrate into the future
How Domain-Driven Design helps you to migrate into the future
 
Content Repository, Versioning and Workspaces in TYPO3 Phoenix
Content Repository, Versioning and Workspaces in TYPO3 PhoenixContent Repository, Versioning and Workspaces in TYPO3 Phoenix
Content Repository, Versioning and Workspaces in TYPO3 Phoenix
 
JavaScript for PHP Developers
JavaScript for PHP DevelopersJavaScript for PHP Developers
JavaScript for PHP Developers
 
Transparent Object Persistence with FLOW3
Transparent Object Persistence with FLOW3Transparent Object Persistence with FLOW3
Transparent Object Persistence with FLOW3
 
TDD (with FLOW3)
TDD (with FLOW3)TDD (with FLOW3)
TDD (with FLOW3)
 
Implementing a JSR-283 Content Repository in PHP
Implementing a JSR-283 Content Repository in PHPImplementing a JSR-283 Content Repository in PHP
Implementing a JSR-283 Content Repository in PHP
 
Knowledge Management in der TYPO3 Community
Knowledge Management in der TYPO3 CommunityKnowledge Management in der TYPO3 Community
Knowledge Management in der TYPO3 Community
 
Unicode & PHP6
Unicode & PHP6Unicode & PHP6
Unicode & PHP6
 
A Content Repository for TYPO3 5.0
A Content Repository for TYPO3 5.0A Content Repository for TYPO3 5.0
A Content Repository for TYPO3 5.0
 
Introduction to Source Code Management
Introduction to Source Code ManagementIntroduction to Source Code Management
Introduction to Source Code Management
 

Dernier

TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 

Dernier (20)

TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 

Transparent Object Persistence (within FLOW3)

  • 1. Transparent Object Persistence (within FLOW3) Karsten Dambekalns <karsten@typo3.org> Inspiring people to share Samstag, 16. Mai 2009
  • 2. “DDD persistence” Domain Models encapsulate behavior and data Concerned about the problem – only Infrastructure is of no relevance Unfortunately you need to be aware of the infrastructure at some point – at least a little Inspiring people to share Samstag, 16. Mai 2009
  • 3. Entities Identity is important Are not defined by their attributes Examples could be... • Projects • Developers Inspiring people to share Samstag, 16. Mai 2009
  • 4. Value objects Have no indentity Their value is of importance Are interchangeable Examples could be... • Colors • Numbers • Tags in Forge Inspiring people to share Samstag, 16. Mai 2009
  • 5. Aggregates Cluster associated objects Have a boundary and a root The root is a specific entity References from outside point to the root An example for an aggregate: • Project Inspiring people to share Samstag, 16. Mai 2009
  • 6. Repositories Provide access to entities (and aggregates) Allow to find a starting point for traversal Persisted objects can be searched for Queries can be built in various ways Handle storage of additions and updates Inspiring people to share Samstag, 16. Mai 2009
  • 7. A Domain Model Project Repository Project Developer SVN twitter Account Account Inspiring people to share Samstag, 16. Mai 2009
  • 8. A Domain Model Project Repository it Project Repos Developer SVN twitter Account Account Inspiring people to share Samstag, 16. Mai 2009
  • 9. A Domain Model Project Repository it Project Repos Developer SVN twitter Account Account Inspiring people to share Samstag, 16. Mai 2009
  • 10. A Domain Model Project Repository it Project Repos Developer SVN twitter Account Account Inspiring people to share Samstag, 16. Mai 2009
  • 11. A Domain Model Project Repository it Project Repos Developer Aggre- gates SVN twitter Account Account Inspiring people to share Samstag, 16. Mai 2009
  • 12. A Domain Model Developer SVN twitter Account Account Inspiring people to share Samstag, 16. Mai 2009
  • 13. Using FLOW3... You just implement the model No need to care about persisting your model FLOW3 handles this for you – transparently Even a Repository only needs little work Define relevant metadata in the source file using annotations Inspiring people to share Samstag, 16. Mai 2009
  • 14. @nnotations used Inspiring people to share Samstag, 16. Mai 2009
  • 15. @nnotations used @entity Inspiring people to share Samstag, 16. Mai 2009
  • 16. @nnotations used @entity @valueobject Inspiring people to share Samstag, 16. Mai 2009
  • 17. @nnotations used @entity @valueobject @var Inspiring people to share Samstag, 16. Mai 2009
  • 18. @nnotations used @entity @valueobject @var @transient Inspiring people to share Samstag, 16. Mai 2009
  • 19. @nnotations used @entity @valueobject @var @transient @uuid Inspiring people to share Samstag, 16. Mai 2009
  • 20. @nnotations used @entity @valueobject @var @transient @uuid @identity Inspiring people to share Samstag, 16. Mai 2009
  • 21. @nnotations used @entity @valueobject @var @transient @uuid @identity @lazy Inspiring people to share Samstag, 16. Mai 2009
  • 22. Persistence Manager Mostly invisible to developers Manages additions of and updates to objects Concerned only about objects in repositories Collects objects and hands over to backend Allows for objects being persisted at any time Automatically called to persist at end of script run Inspiring people to share Samstag, 16. Mai 2009
  • 23. Simplified stack SQLite PgSQL MySQL ... Inspiring people to share Samstag, 16. Mai 2009
  • 24. Simplified stack PDO ... SQLite PgSQL MySQL ... Inspiring people to share Samstag, 16. Mai 2009
  • 25. Simplified stack TYPO3 Content Repository PDO ... SQLite PgSQL MySQL ... Inspiring people to share Samstag, 16. Mai 2009
  • 26. Simplified stack FLOW3 Persistence TYPO3 Content Repository PDO ... SQLite PgSQL MySQL ... Inspiring people to share Samstag, 16. Mai 2009
  • 27. Simplified stack Application Application FLOW3 Persistence TYPO3 Content Repository PDO ... SQLite PgSQL MySQL ... Inspiring people to share Samstag, 16. Mai 2009
  • 28. Simplified stack FLOW3 Persistence Persistence TYPO3 CR Backend Inspiring people to share Samstag, 16. Mai 2009
  • 29. TYPO3 CR FLOW3 Inspiring people to share Samstag, 16. Mai 2009
  • 30. Transparent persistence Explicit support for Domain-Driven Design Class Schemata are defined by the Domain Model class • No need to write an XML or YAML schema definition • No need to define the database model and object model multiple times at different places Automatic persistence in the JSR-283 based Content Repository Legacy data sources can be mounted Inspiring people to share Samstag, 16. Mai 2009
  • 31. Query Factory Creates a query for you Decouples persistence layer from backend Must be implemented by backend API with one method: • public function create($className); Inspiring people to share Samstag, 16. Mai 2009
  • 32. Query objects Represent a query for an object type Allow criteria to be attached Must be implemented by backend Simple API • execute() • matching() • equals(), lessThan(), ... • ... Inspiring people to share Samstag, 16. Mai 2009
  • 33. Object reconstitution When fetching objects the content repository looks for matching nodes The nodes are mapped to objects by a data mapper Reconstitution • does not call __construct() • restores all non-transient properties • reinjects dependencies (skips constructor arguments) Inspiring people to share Samstag, 16. Mai 2009
  • 34. Object reconstitution public function map(F3PHPCRNodeIteratorInterface $nodes) { $objects = array(); foreach ($nodes as $node) { $object = $this->mapSingleNode($node); $this->persistenceManager->getSession()->registerReconstitutedObject($object); $objects[] = $object; } return $objects; } F3TYPO3CRFLOW3PersistenceDataMapper Inspiring people to share Samstag, 16. Mai 2009
  • 35. Object reconstitution $explodedNodeTypeName = explode(':', $node->getPrimaryNodeType()->getName(), 2); $className = str_replace('_', '', $explodedNodeTypeName[1]); $classSchema = $this->persistenceManager->getClassSchema($className); $objectConfiguration = $this->objectManager->getObjectConfiguration($className); $object = $this->objectBuilder->createEmptyObject($className, $objectConfiguration); $this->identityMap->registerObject($object, $node->getIdentifier()); $this->objectBuilder->reinjectDependencies($object, $objectConfiguration); $this->thawProperties($object, $node, $classSchema); $object->FLOW3_Persistence_memorizeCleanState(); F3TYPO3CRFLOW3PersistenceDataMapper Inspiring people to share Samstag, 16. Mai 2009
  • 36. Object reconstitution public function createEmptyObject($objectName, F3FLOW3ObjectConfiguration $objectConfiguration) { $className = $objectConfiguration->getClassName(); if (!in_array('F3FLOW3AOPProxyInterface', class_implements($className))) { throw new F3FLOW3ObjectExceptionCannotReconstituteObject('Cannot create empty instance of the class quot;' . $className . 'quot; because it does not implement the AOP Proxy Interface.', 1234386924); } $object = unserialize('O:' . strlen($className) . ':quot;' . $className . 'quot;:0:{};'); $object->FLOW3_AOP_Proxy_setProperty('objectFactory', $this->objectFactory); $object->FLOW3_AOP_Proxy_setProperty('objectManager', $this->objectManager); $object->FLOW3_AOP_Proxy_declareMethodsAndAdvices(); return $object; } F3FLOW3ObjectBuilder Inspiring people to share Samstag, 16. Mai 2009
  • 37. Lazy Loading Loading a full object tree makes sense – or not It does most of the time If your domain model has small aggregates eager loading makes sense If you have expensive to create objects or a lot of smaller ones you don’t always need, lazy loading helps Example: displaying a list of projects doesn’t need the projects details, just the names Inspiring people to share Samstag, 16. Mai 2009
  • 38. Lazy Loading Ideally you would not think about lazy loading beyond the addition of the @lazy annotation In practice you need to be aware of some technical issues In place of the real object you get a proxy, so • you can’t use it at type hinted places • pass it around without some thinking Using it otherwise works as expected After first use the proxy will be completely gone Inspiring people to share Samstag, 16. Mai 2009
  • 39. The LazyLoadingProxy public function _loadRealInstance() { $realInstance = $this ->F3_FLOW3_Persistence_LazyLoadingProxy_population ->__invoke(); $this ->F3_FLOW3_Persistence_LazyLoadingProxy_parent ->FLOW3_AOP_Proxy_setProperty( $this->F3_FLOW3_Persistence_LazyLoadingProxy_propertyName, $realInstance ); return $realInstance; } F3FLOW3PersistenceLazyLoadingProxy Inspiring people to share Samstag, 16. Mai 2009
  • 40. $dataMapper = $this; // make available to closure... $objectStorage = new F3FLOW3PersistenceLazyLoadingProxy( $parent, $propertyName, function() use ($proxyNode, $dataMapper) { $objectStorage = new SplObjectStorage(); $itemNodes = $proxyNode->getNodes(); foreach ($itemNodes as $itemNode) { $objectNode = $itemNode->getNode('flow3:object'); if ($objectNode->getPrimaryNodeType()->getName() === F3TYPO3CRFLOW3PersistenceBackend::NODETYPE_OBJECTPROXY) { $object = $dataMapper->mapObjectProxyNode($objectNode); } else { $object = $dataMapper->mapSingleNode($objectNode); } $objectStorage->attach($object); } return $objectStorage; } ); F3TYPO3CRFLOW3PersistenceDataMapper Inspiring people to share Samstag, 16. Mai 2009
  • 41. Node structure PHP has more data structures than a content repository, e.g. • JSR-283 defines multi-valued properties without keys and without stable ordering • Arrays in PHP have keys and order that are stable and might be important for your code Thus we do some more mapping to node structures Inspiring people to share Samstag, 16. Mai 2009
  • 42. Inspiring people to share Samstag, 16. Mai 2009
  • 43. Inspiring people to share Samstag, 16. Mai 2009
  • 44. Inspiring people to share Samstag, 16. Mai 2009
  • 45. Inspiring people to share Samstag, 16. Mai 2009
  • 46. Inspiring people to share Samstag, 16. Mai 2009
  • 47. Questions! Inspiring people to share Samstag, 16. Mai 2009
  • 48. Inspiring people to share Samstag, 16. Mai 2009
  • 49. Links FLOW3 http://flow3.typo3.org/ TYPO3CR http://forge.typo3.org/projects/show/package-typo3cr JSR-283 http://jcp.org/en/jsr/detail?id=283 Inspiring people to share Samstag, 16. Mai 2009
  • 51. Flickr photo credits: megapixel13 (barcode), rmrayner (ring), Ducatirider (grapes), Here’s Kate (book shelf) Pumpkin pictures: http://ptnoticias.com/pumpkinway/ Inspiring people to share Samstag, 16. Mai 2009