Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 593

Developing applications
Hide thumbs Also See for 38043740 - ColdFusion Standard - Mac:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
ColdFusion ORM
With this strategy, on loading the artists object, its art object is loaded immediately using a separate SQL query. As a
result, this strategy is extremely vulnerable to 'N+1 Select problem'.
Lazy fetching
In this strategy, the associated object or collection is fetched only when required. Although you need to send a new
request to the database each time you need data, this strategy controls how much of data is loaded and when is it
loaded. This helps in reducing the database load.
When you load an entity, by default, ColdFusion ORM loads the entity's data but relations and any mapped collections
and are not loaded. They are loaded only when you want to load them by calling the getter method. Therefore, the
relations and collection mappings are lazily loaded. For example, when the
not loaded and they are loaded only when
ColdFusion ORM provides three types of lazy loading for relationships:
• lazy: This is the default lazy loading that applies to collection mapping, one-to-many and many-to-many
relationship. In this case, when you call the accessor for the collection/relation, the collection is fully loaded. So,
when you call
EntityLoad()
artist.getarts(), all the art object belonging to the artist will get loaded. This is achieved by setting
the relationship property definition in the CFC.
Example:
In artist.cfc
<cfproperty name="art" fieldtype="one-to-many" cfc="ART" fkcolumn="artistId" lazy="true">
• Extra lazy: This applies to one-to-many and many-to-many relationships. This type of lazy loading goes one step
ahead of lazy and does not load all the associated objects when the accessor for that relation is called. It just loads
the primary keys for those objects and keeps a proxy object for them. When you call any method on the wrapper
object, that object's data is loaded from the database.
For example, when you call
related artwork objects and creates a proxy artwork object. So, you do not load the data for all the artwork objects
in memory. When you access a particular artwork object and invoke any method on it, then it fires another query
to the database to load that particular artwork object. This is achieved by setting
property definition in the CFC.
Example:
In artist.cfc
<cfproperty name="art" fieldtype="one-to-many" cfc="art" fkcolumn="artistId" lazy="extra" >
• proxy: This applies to one-to-one and many-to-one relationships. When the owner object is loaded, the related
object is not loaded from the database. ColdFusion only creates a proxy object for the related object and when any
method is invoked on the related object, the data for the proxy object is loaded from the database and populated in
the proxy object.
For example, if the art-artist table relation is lazy, when the art object is loaded, the artists object is not loaded and
when you call
art.getartist()
object, query gets executed on the database to load artist object's data. This is achieved by setting
the relationship property definition in the CFC
Example:
In ART.cfc
is called.
getarts()
for a particular artist, its artworks are not loaded at that time. When you call
, it executes a query on the database to fetch the primary key of the
artist.getarts()
, you would only get a proxy object. When you call any method on the proxy
Last updated 1/20/2012
object is loaded, all its artworks are
artist
lazy="true"
on the relationship
lazy="extra"
lazy="true"
588
on
on

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents