CF Summit - ORM Games, Steve Rittler

October 29, 2013

ORM GAMES -- Steve Rittler

diagnosing and debugging--
don't change this stuff in Prod!
the log files that are generated by this, tend to balloon very quickly. also a resource drain

files to modify
application.cfc
and
/cf10/{server}/lib/log4j.properties

this.ormsettings =
{
logSQL = true
}

log4j.properties
log levels - trace is the "noisiest" level for logging
hibernate.sql = true...makes our binding info visible in the debugging

in the hibernatesql.log file
now that we've told it to be "noisy" via "trace"
we can actually see the SQL statements being executed in here (though they don't appear in the console output)

set the appender to "RollingFileAppender"!
by default it's set to FileAppend which isn't as useful
and can cause the log file to eat up ALL your drive space

event handling --
ormsettings - event handling = true;

global handler
this is a per APP setting
ormsettings
-- event handler = points to a CFC that is an Interface and has methods for all 8 event handlers
(preInsert, postInsert, etc)

can use this to set ALL the dtCreated, dtModified, IPUpdated, ipModified columns for every table in my app so they all, always get set correctly.

caching
2 levels
first level cache (on by default)
in the hibernate session

second level cache (optional)
ormsetings secondaryCacheEnabled=true
can use this on a per entity or per query basis
in your entity CFC
cacheUse="transactional" (type of cache you want to use:
transactional -- safest but slowest -- but not noticeable to you or end user. reasonably fast. evicts on update
read-write: not allays guaranteed to be updated
nonrestricted read-write
read-only -- only if your data is never updated. will get thrown an error if you try to do EntitySave() on a read-only entity in a secondary cache

stick to transactional everywhere possible
will prevent the fewest surprises

1 gotcha
EntityLoad always obeys the cache settings
ORM Execute Query / cfquery do NOT obey cache. they leave it to you to specify if you want this query cached or not
-- do this by passing in a struct w/ the cache properties
{cacheable=true, cachename='name', timeout=60}...

how do i know if an entity is/isn't cached
ormgetsessionfactory()
--- can use that to see what's going on inside
ex: getStatistics() -- see what matrices are avail to you
getSecondLevelCAcheHItCount()
getSecondLevelCAcheMissCount()

inheritance
immensely helpful

coldfusionormbook.com -- John Wish's book
rupeshk.org/blog/ -- "Advanced ColdFusion ORM"
--- one of his presos from Max 2009 is super helpful