ormsettings.eventHandler

141 views
Skip to first unread message

Bernhard Döbler

unread,
Jun 28, 2011, 4:09:28 PM6/28/11
to cf-or...@googlegroups.com
Hi,

I'd like to have a CFC handling ORM events setting updated-timestamps
on update and the like.

I keep getting the error:
ormcfcs.ormeventhandler is not a valid ORM event handler.
It must implement interface cfide.orm.IEventHandler

in my Application.cfc I defined
<cfset this.ormsettings.eventHandling = true>
<cfset this.ormsettings.eventHandler="ormcfcs.ormeventhandler">
<cfset this.ormsettings.cfclocation = "/ormcfcs/">

and put the following ormeventhandler.cfc in the ormcfcs folder

<cfcomponent implements="CFIDE.orm.IEventHandler">

<cffunction name="preInsert" access="public" returntype="void"
output="false" hint="I run before this entity is inserted.">
<cfargument name="entity" type="any" />

<!---
Set the date/time properties. This way, we can
keep track of the time at which this object was
created / inserted.
--->
<cfset this.setangelegt_datum( Now() ) />
<cfset this.setgeaendert_datum( Now() ) />

<!--- Return out. --->
<cfreturn />
</cffunction>

<cffunction name="postLoad" access="public" returntype="void"
output="false" hint="I run after this entity is loaded.">
<cfargument name="entity" type="any" />

<!--- Return out. --->
<cfreturn />
</cffunction>

<cffunction name="postDelete" access="public" returntype="void"
output="false" hint="I run after this entity is deleted.">
<cfargument name="entity" type="any" />

<!--- Return out. --->
<cfreturn />
</cffunction>

<cffunction name="preLoad" access="public" returntype="void"
output="false" hint="I run before this entity is loaded.">
<cfargument name="entity" type="any" />

<!--- Return out. --->
<cfreturn />
</cffunction>

<cffunction name="preDelete" access="public" returntype="void"
output="false" hint="I run before this entity is deleted.">
<cfargument name="entity" type="any" />

<!--- Return out. --->
<cfreturn />
</cffunction>

<cffunction name="preUpdate" access="public" returntype="void"
output="false" hint="I run before this entity is updated.">
<cfargument name="entity" type="any" />
<!--- Define the arguments. --->
<cfargument name="oldData" type="struct" required="true" hint="I am
the collection of data held over from the load time." />

<!---
Set the date/time properties. This way, we can
keep track of the most recent time at which this
object was updated.
--->
<cfset this.setgeaendert_datum( Now() ) />

<!---
Return out. NOTE: If this method return TRUE, then
the update is cancelled.
--->
<cfreturn />
</cffunction>

<cffunction name="postUpdate" access="public" returntype="void"
output="false" hint="I run after this entity is updated.">
<cfargument name="entity" type="any" />

<!--- Return out. --->
<cfreturn />
</cffunction>

<cffunction name="postInsert" access="public" returntype="void"
output="false" hint="I run before this entity is inserted.">
<cfargument name="entity" type="any" />

<!--- Return out. --->
<cfreturn />
</cffunction>

</cfcomponent>

It works, when I use the following cfc in script-notation.

component implements="CFIDE.orm.IEventHandler" {

public void function preInsert(any entity){
arguments.entity.setangelegt_datum(now());
arguments.entity.setgeaendert_datum(now());
}

public void function postLoad( any entity){
arguments.entity.setgeaendert_datum(now());
}

public void function postDelete(any entity){

}

public void function preLoad( any entity){

}

public void function preDelete( any entity) {

}

public void function preUpdate( any entity, Struct oldData){

}

public void function postUpdate( any entity){

}

public void function postInsert( any entity){

}

}

Are you using ORM events to modify data preUpdate? Have you used
mappedSuperClass to define event handlers?


Best,
Bernhard

Brian Kotek

unread,
Jun 28, 2011, 6:24:18 PM6/28/11
to cf-or...@googlegroups.com
I'm not sure why the script version works and the tag-based one doesn't, and it would probably be good to find out. But as a pragmatist, I'd say just use the script version since it is vastly superior to the tag version in terms of layout, space, and ease of scanning.

Also, mapped superclass only applies to ORM CFCs. While the event handler CFCs are used as part of the ORM framework, they are not entities. So you'd just use normal inheritance here.

Brian


--
You received this message because you are subscribed to the Google Groups "cf-orm-dev" group.
To post to this group, send email to cf-or...@googlegroups.com.
To unsubscribe from this group, send email to cf-orm-dev+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cf-orm-dev?hl=en.


Tony Nelson

unread,
Jun 28, 2011, 8:19:49 PM6/28/11
to cf-orm-dev
I think I ran into this one as well. Try removing required="true" from
the tag-based version of preUpdate().

On Jun 28, 5:24 pm, Brian Kotek <brian...@gmail.com> wrote:
> I'm not sure why the script version works and the tag-based one doesn't, and
> it would probably be good to find out. But as a pragmatist, I'd say just use
> the script version since it is vastly superior to the tag version in terms
> of layout, space, and ease of scanning.
>
> Also, mapped superclass only applies to ORM CFCs. While the event handler
> CFCs are used as part of the ORM framework, they are not entities. So you'd
> just use normal inheritance here.
>
> Brian
>

zabimaru

unread,
Dec 21, 2012, 11:42:14 PM12/21/12
to cf-or...@googlegroups.com
Hi guys

The following works for me

<cfcomponent implements="CFIDE.orm.IEventHandler" displayname="ormeventhandler" accessors="true" output="false">

<cffunction name="preLoad" returntype="void" access="public">
<cfargument name="entity" type="any"  hint="The entity that will be loaded.">
</cffunction>

<cffunction name="postLoad" returntype="void" access="public">
<cfargument name="entity" type="any"  hint="The entity that was be loaded.">
</cffunction>

<cffunction name="preInsert" returntype="void" access="public">
<cfargument name="entity" type="any" hint="The entity that is going to be inserted.">
</cffunction>

<cffunction name="postInsert" returntype="void" access="public">
<cfargument name="entity" type="any"  hint="The entity that was inserted.">
</cffunction>

<cffunction name="preUpdate" returntype="void" access="public">
<cfargument name="entity" type="any" hint="The entity that is going to be updated.">
<cfargument name="oldData" type="struct" hint="A struct of old data.">
</cffunction>

<cffunction name="postUpdate" returntype="void" access="public">
<cfargument name="entity" type="any"  hint="The entity that was updated.">
</cffunction>

<cffunction name="preDelete" returntype="void" access="public">
<cfargument name="entity" type="any"  hint="The entity that is going to be deleted.">
</cffunction>

<cffunction name="postDelete" returntype="void" access="public">
<cfargument name="entity" type="any"  hint="The entity that was deleted.">
</cffunction>
    
</cfcomponent>

Thanks!
Reply all
Reply to author
Forward
0 new messages