ColdFusion
    Advanced ORM

    Himavanth Rachamsetty
    ColdFusion Engineer




Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.   1
Agenda

       Advanced Mapping
       CF-ORM Internals
       Sessions &Transactions
       Concurrency Control (Optimistic Locking)
       Performance Optimization
               Lazy – Loading
               Caching

       Q&A




                                                                                              ®




    Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.   2
Advanced Mapping

     Collection Mapping
     Embedded Mapping
     Join Mapping
     Inheritance Mapping




                                                                                          ®




Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.   3
Collection Mapping

     Similar to 1:n relationship
     Useful when target table need not be mapped as persistent CFC
              Just need information from the target table

     Demo




                                                                                          ®




Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.   4
Embedded Mapping

     One entity with multiple CFC
     Mapping needs to be specified in *.hbmxml


<hibernate-mapping>
  <class name="cfc:Employees" entity-name="employee"
  table="Employees">
      <id name="ID" type="integer" column="EmployeeID">
         <generator class="native"/>
      </id>
      <component name="Name" class="cfc:cname">
         <property name="FirstName" type="string" column="FirstName"/>
         <property name="LastName" type="string" column="LastName"/>
      </component>
      <property name="Title" type="string" column="Title"/>
      <property name="BirthDate" type="date" column="BirthDate"/>
      <property name="HireDate" type="date" column="HireDate"/>
  </class>
</hibernate-mapping>
                                                                                          ®




Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.   5
Join Mapping

     Useful when using one CFC for multiple tables


<cfcomponent persistent="true“ table=“employee”>
    <cfproperty name="id">
    <cfproperty name="name">
    <cfproperty name="city"
                table="Address” joincolumn="addressId">
    <cfproperty name="country"
                table="Address“ joincolumn="addressId">
</cfcomponent>




                                                                                          ®




Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.   6
Inheritance Mapping

     Three Types
     Table per hierarchy                                                                 Payment Table




                                                                                                          ®




Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.   7
Inheritance Mapping

     Demo




                                                                                          ®




Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.   8
Inheritance Mapping

     Three Types
     Table per hierarchy                                                                     Payment Table

     Table per subclass (without discriminator)



                                                                                          CreidtCardPayment Table




                                                                                          Cheque Payment Table




                                                                                                                    ®




Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.   9
Inheritance Mapping

     Demo




                                                                                           ®




Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.   10
Inheritance Mapping

     Three Types
     Table per hierarchy                                                                    Payment Table
     Table per subclass (without discriminator)
     Table per subclass (with discriminator)

                                                                                           CreidtCardPayment Table




                                                                                           Cheque Payment Table




                                                                                                                     ®




Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.   11
Inheritance Mapping

     Demo




                                                                                           ®




Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.   12
ORM Internals - Initialization




                            false




                                                                                           Inspect
                                                             true




                                                                                                     ®




Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.   13
ORM Session

     All the ORM operations happen in a session
     Ensures a single instance of an entity.
     Tracks changes made to the objects
     SQLs are executed when session is flushed
              Typically when the transaction is committed or when the request completes
              Can use ORMFlush to force

     Provides First Level Caching
     Automatically managed by CF
              In most cases, you don’t need to worry about it

     A unit of work – a transaction




                                                                                           ®




Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.   14
ORM Session Management


                                                                     New Request




                                                                                           ®




Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.   15
Object States

     Transient
     Persistent
     Detached

EntityNew()/ new()/
CreateObject                                                                                                 Session ends

                                                                                                                                         Detached
                                          EntitySave()                                                                      EnityMerge
                                                                                        EntitySave
    Transient Entity



                                                                                 Session
                              EntityDelete

                                                                                      Persistent Entities   EntityLoad
                                                                                                            ORMExecuteQuery



                                                                                                                                                    ®




Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.            16
ORM Session Management – Transactions


                                                                     New Request




                                                                                           ®




                                                                                      17
Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.   17
Concurrency Control
     Optimistic lock for high concurrency
     Update only if the entity is not modified by other thread or externally.
     optimisticlock attribute on cfc
              All
                      All properties are included in where clause of update
                           Update myTbl set col1= newVal
                                      where col1= oldVal and col2= oldVal2
              Dirty
                      Includes only modified fields in the current session
                           Update myTbl set col1= newVal where col1= oldVal
              Version (default)
                      Checks only version or timestamp column
                  <cfproperty name="lastModified“ fieldtype="timestamp|version“>
              None
     Also available at property level. <cfproperty .. optimisticlock=“true”>
                                                                                           ®




Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.   18
Fetching Strategy

     Lazy fetching
              Default strategy, lazy=true
              Extra Lazy : lazy = “extra” gets pk of arts and then all art columns from db

     Immediate fetching
              Fetch target relationship in a separate SQL, immediately
         <cfproperty name=“artist" fieldtype="one-to-many" cfc=“art"
                          fkcolumn=“ARTISTID“ lazy="false" fetch="select">

     Eager fetching
              Fetch together in a single SQL, fetch=“join”
              Useful for 1:1 frequently used relationships

     Batch fetching                                 < cfcomponent persistent="true" batchsize="100“ >
              When fetching relationship, get some more that maybe required later
              Get Addr1 for emp101, plus address for emp102, 103 etc depending on batch size

                                                                                                         ®




Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.   19
Caching

     Session Level
              Ensures a single instance for a given ID
              EntityLoad fetches data for the first time
              Data is cached for the session
              Next request in the same session will use cached data
              EntyReload re-fetches




                                                                                           ®




Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.   20
Secondary Level Cache

     Caches data across sessions
     In-memory/disk/clustered
     Pluggable cache impls
     Default – EHCache




                                                                                           …

                                                                                               ®




Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.   21
Secondary Level caching ...

     Configuration in Application.cfc
              ormsettings.secondarycacheenabled
              ormsettings.Cacheprovider
                      JBossCache, OSCache, SwarmCache, Hashtable, DEFAULT - ehcache

              ormsettings.cacheconfig
                      Appropriate config file for cache, e.g. ehcache.xml




     What is being cached
     How (caching strategy)
     3 Things in                                4 Ways




                                                                                           ®




Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.   22
Secondary Level Cache – 3 Things in 4 Ways


     3 Things                                                                            4 Ways          (cacheuse)
     Component                                                                           Read-only
              cfcomponent                                                                Nonrestrict-read-write
     Collection/Association                                                              Read-write
              cfproperty
                                                                                          Transactional
     Query
              EntityLoad/OrmExecuteQuery




                                                                                                                        ®




Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.   23
Caching - examples

     Component
              <cfcomponent persistent="true“
                             cachename=“foo_region" cacheuse="read-only">

     Relationship/Association/Collection
              Primary Key of the associated object is cached
              The associated object itself is cached if specified as below
         <cfproperty name="arts" fieldtype="one-to-many“
               cachename="foo_region" cacheuse="read-write">

     Query data
              ORMExecuteQuery("from Art where issold=0", {}, false,
                   {cacheable=true, cachename=“foo_region"});




                                                                                           ®




Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.   24
Caching – cacheuse

     Read-only
              Best performance for read only data

     Read-write
              Use if your data needs to be updated
              More overhead

     Nonrestrict-read-write
              Use when data is updated occasionally

     Transactional
              Transactional cache
              Can only be used if the cache provider is transaction aware




                                                                                           ®




Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.   25
Caching - cleanup

     ORMEvictEntity
         ORMEvictEntity("<component_name>", [primarykey])

     ORMEvictCollection
         ORMEvictCollection("<component_name>", "<relation_name>",
                             [primarykey])

     ORMEvictQueries
         ORMEvictQueries([cachename])




                                                                                           ®




Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.   26
Thank You !
                                                    - himar@adobe.com




Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.   27

More Related Content

PDF
Flash performance tuning (EN)
PDF
PPTX
Accelerate your ColdFusion Applications using Caching
PDF
Quality Best Practices & Toolkit for Enterprise Flex
PPTX
ColdFusion ORM - Part II
PDF
In The Future We All Use Symfony2
PDF
Adobe AIR - Mobile Performance – Tips & Tricks
PPT
ColdFusion 9 ORM
Flash performance tuning (EN)
Accelerate your ColdFusion Applications using Caching
Quality Best Practices & Toolkit for Enterprise Flex
ColdFusion ORM - Part II
In The Future We All Use Symfony2
Adobe AIR - Mobile Performance – Tips & Tricks
ColdFusion 9 ORM

Similar to Advanced orm (20)

PDF
HBase and Hadoop at Adobe
PDF
Flex 3 Deep Dive
PPT
JEE Course - EJB
PDF
Ria2010 workshop dev mobile
PDF
Paremus Cloud and OSGi Beyond the VM - OSGi Cloud Workshop March 2012
PDF
Xebia adobe flash mobile applications
PDF
Flex Continuous Quality Builds Flex & (Ant || Maven)
PDF
Smart analytic optimizer how it works
PPTX
Concurrent Programming with ActionScript workers
PDF
NLJUG: Content Management, Standards, Opensource & JCP
PDF
Jopenmeraverse introduction
PDF
Adopting Agile Tools & Methods In A Legacy Context
PDF
AD109 - Using the IBM Sametime Proxy SDK: WebSphere Portal, IBM Connections -...
PDF
MMT 28: Adobe »Edge to the Flash«
PDF
On Failure and Resilience
PDF
Devoxx France 2013 Cloud Best Practices
PDF
Cloud Best Practices
PPTX
ColdFusion ORM - Advanced : Adobe Max 2009
PDF
Docker bdxio
PPS
Cr java concept by vikas jagtap
HBase and Hadoop at Adobe
Flex 3 Deep Dive
JEE Course - EJB
Ria2010 workshop dev mobile
Paremus Cloud and OSGi Beyond the VM - OSGi Cloud Workshop March 2012
Xebia adobe flash mobile applications
Flex Continuous Quality Builds Flex & (Ant || Maven)
Smart analytic optimizer how it works
Concurrent Programming with ActionScript workers
NLJUG: Content Management, Standards, Opensource & JCP
Jopenmeraverse introduction
Adopting Agile Tools & Methods In A Legacy Context
AD109 - Using the IBM Sametime Proxy SDK: WebSphere Portal, IBM Connections -...
MMT 28: Adobe »Edge to the Flash«
On Failure and Resilience
Devoxx France 2013 Cloud Best Practices
Cloud Best Practices
ColdFusion ORM - Advanced : Adobe Max 2009
Docker bdxio
Cr java concept by vikas jagtap
Ad

Recently uploaded (20)

PDF
WOOl fibre morphology and structure.pdf for textiles
PDF
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
A novel scalable deep ensemble learning framework for big data classification...
PDF
August Patch Tuesday
PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PPTX
observCloud-Native Containerability and monitoring.pptx
PDF
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
PPTX
Chapter 5: Probability Theory and Statistics
PDF
Unlock new opportunities with location data.pdf
PDF
Taming the Chaos: How to Turn Unstructured Data into Decisions
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
DOCX
search engine optimization ppt fir known well about this
PDF
sustainability-14-14877-v2.pddhzftheheeeee
PPTX
Web Crawler for Trend Tracking Gen Z Insights.pptx
PPT
What is a Computer? Input Devices /output devices
PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PDF
Enhancing emotion recognition model for a student engagement use case through...
WOOl fibre morphology and structure.pdf for textiles
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Group 1 Presentation -Planning and Decision Making .pptx
A novel scalable deep ensemble learning framework for big data classification...
August Patch Tuesday
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
observCloud-Native Containerability and monitoring.pptx
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
Chapter 5: Probability Theory and Statistics
Unlock new opportunities with location data.pdf
Taming the Chaos: How to Turn Unstructured Data into Decisions
NewMind AI Weekly Chronicles – August ’25 Week III
search engine optimization ppt fir known well about this
sustainability-14-14877-v2.pddhzftheheeeee
Web Crawler for Trend Tracking Gen Z Insights.pptx
What is a Computer? Input Devices /output devices
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
Final SEM Unit 1 for mit wpu at pune .pptx
Enhancing emotion recognition model for a student engagement use case through...
Ad

Advanced orm

  • 1. ColdFusion Advanced ORM Himavanth Rachamsetty ColdFusion Engineer Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 1
  • 2. Agenda  Advanced Mapping  CF-ORM Internals  Sessions &Transactions  Concurrency Control (Optimistic Locking)  Performance Optimization  Lazy – Loading  Caching  Q&A ® Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 2
  • 3. Advanced Mapping  Collection Mapping  Embedded Mapping  Join Mapping  Inheritance Mapping ® Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 3
  • 4. Collection Mapping  Similar to 1:n relationship  Useful when target table need not be mapped as persistent CFC  Just need information from the target table  Demo ® Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 4
  • 5. Embedded Mapping  One entity with multiple CFC  Mapping needs to be specified in *.hbmxml <hibernate-mapping> <class name="cfc:Employees" entity-name="employee" table="Employees"> <id name="ID" type="integer" column="EmployeeID"> <generator class="native"/> </id> <component name="Name" class="cfc:cname"> <property name="FirstName" type="string" column="FirstName"/> <property name="LastName" type="string" column="LastName"/> </component> <property name="Title" type="string" column="Title"/> <property name="BirthDate" type="date" column="BirthDate"/> <property name="HireDate" type="date" column="HireDate"/> </class> </hibernate-mapping> ® Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 5
  • 6. Join Mapping  Useful when using one CFC for multiple tables <cfcomponent persistent="true“ table=“employee”> <cfproperty name="id"> <cfproperty name="name"> <cfproperty name="city" table="Address” joincolumn="addressId"> <cfproperty name="country" table="Address“ joincolumn="addressId"> </cfcomponent> ® Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 6
  • 7. Inheritance Mapping  Three Types  Table per hierarchy Payment Table ® Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 7
  • 8. Inheritance Mapping  Demo ® Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 8
  • 9. Inheritance Mapping  Three Types  Table per hierarchy Payment Table  Table per subclass (without discriminator) CreidtCardPayment Table Cheque Payment Table ® Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 9
  • 10. Inheritance Mapping  Demo ® Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 10
  • 11. Inheritance Mapping  Three Types  Table per hierarchy Payment Table  Table per subclass (without discriminator)  Table per subclass (with discriminator) CreidtCardPayment Table Cheque Payment Table ® Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 11
  • 12. Inheritance Mapping  Demo ® Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 12
  • 13. ORM Internals - Initialization false Inspect true ® Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 13
  • 14. ORM Session  All the ORM operations happen in a session  Ensures a single instance of an entity.  Tracks changes made to the objects  SQLs are executed when session is flushed  Typically when the transaction is committed or when the request completes  Can use ORMFlush to force  Provides First Level Caching  Automatically managed by CF  In most cases, you don’t need to worry about it  A unit of work – a transaction ® Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 14
  • 15. ORM Session Management New Request ® Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 15
  • 16. Object States  Transient  Persistent  Detached EntityNew()/ new()/ CreateObject Session ends Detached EntitySave() EnityMerge EntitySave Transient Entity Session EntityDelete Persistent Entities EntityLoad ORMExecuteQuery ® Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 16
  • 17. ORM Session Management – Transactions New Request ® 17 Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 17
  • 18. Concurrency Control  Optimistic lock for high concurrency  Update only if the entity is not modified by other thread or externally.  optimisticlock attribute on cfc  All  All properties are included in where clause of update Update myTbl set col1= newVal where col1= oldVal and col2= oldVal2  Dirty  Includes only modified fields in the current session Update myTbl set col1= newVal where col1= oldVal  Version (default)  Checks only version or timestamp column <cfproperty name="lastModified“ fieldtype="timestamp|version“>  None  Also available at property level. <cfproperty .. optimisticlock=“true”> ® Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 18
  • 19. Fetching Strategy  Lazy fetching  Default strategy, lazy=true  Extra Lazy : lazy = “extra” gets pk of arts and then all art columns from db  Immediate fetching  Fetch target relationship in a separate SQL, immediately <cfproperty name=“artist" fieldtype="one-to-many" cfc=“art" fkcolumn=“ARTISTID“ lazy="false" fetch="select">  Eager fetching  Fetch together in a single SQL, fetch=“join”  Useful for 1:1 frequently used relationships  Batch fetching < cfcomponent persistent="true" batchsize="100“ >  When fetching relationship, get some more that maybe required later  Get Addr1 for emp101, plus address for emp102, 103 etc depending on batch size ® Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 19
  • 20. Caching  Session Level  Ensures a single instance for a given ID  EntityLoad fetches data for the first time  Data is cached for the session  Next request in the same session will use cached data  EntyReload re-fetches ® Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 20
  • 21. Secondary Level Cache  Caches data across sessions  In-memory/disk/clustered  Pluggable cache impls  Default – EHCache … ® Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 21
  • 22. Secondary Level caching ...  Configuration in Application.cfc  ormsettings.secondarycacheenabled  ormsettings.Cacheprovider  JBossCache, OSCache, SwarmCache, Hashtable, DEFAULT - ehcache  ormsettings.cacheconfig  Appropriate config file for cache, e.g. ehcache.xml  What is being cached  How (caching strategy)  3 Things in 4 Ways ® Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 22
  • 23. Secondary Level Cache – 3 Things in 4 Ways  3 Things  4 Ways (cacheuse)  Component  Read-only  cfcomponent  Nonrestrict-read-write  Collection/Association  Read-write  cfproperty  Transactional  Query  EntityLoad/OrmExecuteQuery ® Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 23
  • 24. Caching - examples  Component  <cfcomponent persistent="true“ cachename=“foo_region" cacheuse="read-only">  Relationship/Association/Collection  Primary Key of the associated object is cached  The associated object itself is cached if specified as below <cfproperty name="arts" fieldtype="one-to-many“ cachename="foo_region" cacheuse="read-write">  Query data  ORMExecuteQuery("from Art where issold=0", {}, false, {cacheable=true, cachename=“foo_region"}); ® Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 24
  • 25. Caching – cacheuse  Read-only  Best performance for read only data  Read-write  Use if your data needs to be updated  More overhead  Nonrestrict-read-write  Use when data is updated occasionally  Transactional  Transactional cache  Can only be used if the cache provider is transaction aware ® Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 25
  • 26. Caching - cleanup  ORMEvictEntity ORMEvictEntity("<component_name>", [primarykey])  ORMEvictCollection ORMEvictCollection("<component_name>", "<relation_name>", [primarykey])  ORMEvictQueries ORMEvictQueries([cachename]) ® Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 26
  • 27. Thank You ! - himar@adobe.com Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 27

Editor's Notes

  • #18: CFTransaction tag is fully supported in ColdFusion-ORMSavepoint and rollback are supportedIsolation-levels:Isolation level, which indicates which type of read can occur during the execution of concurrent SQL transactions. The possible read actions include dirty read, in which a second SQL transaction reads a row before the first SQL transaction executes a COMMIT; non-repeatable read, in which a SQL transaction reads a row and then a second SQL transaction modifies or deletes the row and executes a COMMIT; and phantom, in which a SQL transaction reads rows that meet search criteria, a second SQL transaction then generates at least one row that meets the first transaction&apos;s search criteria, and then the first transaction repeats the search, resulting in a different result set.read_uncommitted: Allows dirty read, non-repeatable read, and phantom read_committed: Allows non-repeatable read and phantom. Does not allow dirty read. repeatable_read: Allows phantom. Does not allow dirty read or non-repeatable read. serializable: Does not allow dirty read, non-repeatable read, or phantom.