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.