wirebox orm event handler

Question…

I’m using the Wirebox Event Handler and I added one of my entities to the injectorExclude however ColdBox is still announcing all of the interceptors for the excluded entity. Not sure if this is by design since code can easily be added to your interceptor to also exclude the injectorExclude entity but wanted to find out if this was by design or defect.

To phrase it differently

In my wirebox event handler I created, I have injectorExclude=‘audit’ and the ORMPreInsert custom interception point is still being fired. I believe this should only happen when it passes the injectorExclude or injectorInclude test.

Not a big deal and I might not be thinking thru the entire life cycle of the eventHandler however I wanted to verify first.

Jeremy R. DeYoung
615.261.8201jeremy.deyoung@lunarfly.comLunarFly.com

Jeremy,

Is this stand alone or part of a ColdBox application? Where did you extend from for your event handler?

Curt

Curt,

Here is my Application.cfc code snippet (truncated)

component extends=“coldbox.system.Coldbox” output=“false” {

this.ormSettings = {

cfclocation = [“model”],
eventHandler = “model.EventHandler”

};

}

Here is my model.EventHandler.cfc code

component output=“false” extends=“coldbox.system.orm.hibernate.WBEventHandler” {

injectorExclude = “audit”;

}

Here is my mode.audit.cfc code entity

component name=“audit” persistent=“true” entityname=“audit” table=“audit” batchsize=“25” cachename=“audit” cacheuse=“read-write” datasource=“vencommerce” {

property name=“auditID” fieldtype=“id” generator=“native” setter=“false”;

property name=“audit” ormtype=“text” notnull=“true”;
property name=“typeID” notnull=“true” default=“0” dbdefault=“0”;
property name=“isSuccess” notnull=“true” default=“0” dbdefault=“0”;
property name=“createdAt” notnull=“true” ormtype=“timestamp” update=“false” default="#now()#";
property name=“createdBy” notnull=“true” ormtype=“boolean” default=“false” dbdefault=“0”;

}

And lastly here is my interceptor.mainInterceptor.cfc code (truncated)

component output=false {

property name=“auditService” inject=“model:audit.auditService”;

public void function preReinit(required event,required interceptData) output=false {
ormReload();

}

public void function ORMPostInsert(required any event, required any interceptData) async {

if(getMetaData(interceptData[‘entity’])[‘entityName’] != ‘audit’){
databaseAuditLogging(entity=interceptData[‘entity’],isSuccess=1,typeID=1);
}
}
public void function ORMPostUpdate(required any event, required any interceptData) async {
if(getMetaData(interceptData[‘entity’])[‘entityName’] != ‘audit’){
databaseAuditLogging(entity=interceptData[‘entity’],isSuccess=1,typeID=2);
}
}
public void function ORMPostDelete(required any event, required any interceptData) async {
if(getMetaData(interceptData[‘entity’])[‘entityName’] != ‘audit’){
databaseAuditLogging(entity=interceptData[‘entity’],isSuccess=1,typeID=3);
}
}

private void function databaseAuditLogging(required any entity, required numeric isSuccess=0, required numeric typeID=0){

var audit = auditService.new();
audit.setCreatedBy(arguments[‘entity’].getModifiedBy());
audit.setCreatedAt(now());
audit.setAudit(serializeJSON(arguments[‘entity’]));
audit.setTypeID(arguments[‘typeID’]);
audit.setIsSuccess(arguments[‘isSuccess’]);
auditService.save(audit);
}

}

I’ve added the extra “if statement” to the ORMPostInsert, ORMPostUpdate, ORMPostDelete custom interception points provided by wirebox to check to see if the entity being added is ‘audit’ and if not, it logs the data. It works just fine but to me the coldbox.system.orm.hibernate.WBEventHandler should not announceInterception if the processEntityInjection returns true. Yet again, maybe I am over-thinking this and it works as designed. And I am handling the checking correctly within my interceptor to exclude the entities as desired.

OK,

So you are within a Coldbox app.

Then you should extend “coldbox.system.orm.hibernate.EventHandler” in your “model.EventHandler.cfc” and use the ColdBox settings to control the include/exclude

orm = {
injection = {
// enable entity injection
enabled = true,
// a list of entity names to include in the injections
include = “audit”,
// a list of entity names to exclude from injection
exclude = “”
}
};

This should then only fire the interception points on the audit entity.