Growing up I never imagined I would play bass guitar for the Dave Matthews Band. And indeed it never happened. But I have become a passionate and pretty good web developer. I code mostly in ColdFusion and jQuery. Sam is a DZone MVB and is not an employee of DZone and has posted 16 posts at DZone. You can read more from them at their website. View Full User Profile

How to use ORM and onSessionEnd()

06.09.2011
| 5235 views |
  • submit to reddit

At 16applications I use ORM extensively. Recently I wanted to track when users sessions timed out which the onSessionEnd function in Application.cfc is perfect for.

onSessionEnd is interesting in that its not part of a standard ColdFusion request process which ORM is somewhat dependent on. In order to use ORM inside it I had to use ormFlush() to get changes to flush to the database.

function onSessionEnd( SessionScope ) {    if ( structKeyExists( arguments.SessionScope, "loginTrackerId" ) ) {        var lt = entityload("loginTracker", {loginTrackerId=arguments.SessionScope.loginTrackerId}, true );        lt.setOutDT( now() );
        lt.setTimedOut( true );
        ormFlush();
    }
}

 

References
Published at DZone with permission of Sam Farmer, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Mark Mandel replied on Thu, 2011/06/09 - 8:44pm

Wouldn't it have been better to use a transaction block?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.