// PERF: Avoid events if no listeners.
if (this.descriptor.getEventManager().hasAnyEventListeners()) {
// Need to run post build or refresh selector, currently check with the query for this,
// I'm not sure which should be called it case of refresh building a new object, currently refresh is used...
DescriptorEvent event = new DescriptorEvent(clone);
event.setQuery(query);
event.setSession(unitOfWork);
event.setDescriptor(this.descriptor);
event.setRecord(databaseRow);
if (forRefresh) {
event.setEventCode(DescriptorEventManager.PostRefreshEvent);
} else {
event.setEventCode(DescriptorEventManager.PostBuildEvent);
//fire a postBuildEvent then the postCloneEvent
unitOfWork.deferEvent(event);
event = new DescriptorEvent(clone);
event.setQuery(query);
event.setSession(unitOfWork);
event.setDescriptor(this.descriptor);
event.setRecord(databaseRow);
//bug 259404: ensure postClone is called for objects built directly into the UnitOfWork
//in this case, the original is the clone
event.setOriginalObject(clone);
event.setEventCode(DescriptorEventManager.PostCloneEvent);
}
unitOfWork.deferEvent(event);
}