}
EntityEcaRuleRunner<?> ecaRunner = this.getEcaRuleRunner(primaryKey.getEntityName());
ecaRunner.evalRules(EntityEcaHandler.EV_VALIDATE, EntityEcaHandler.OP_REMOVE, primaryKey, false);
GenericHelper helper = getEntityHelper(primaryKey.getEntityName());
if (doCacheClear) {
// always clear cache before the operation
ecaRunner.evalRules(EntityEcaHandler.EV_CACHE_CLEAR, EntityEcaHandler.OP_REMOVE, primaryKey, false);
this.clearCacheLine(primaryKey);
}
ecaRunner.evalRules(EntityEcaHandler.EV_RUN, EntityEcaHandler.OP_REMOVE, primaryKey, false);
// if audit log on for any fields, save old value before removing so it's still there
if (primaryKey != null && primaryKey.getModelEntity().getHasFieldWithAuditLog()) {
createEntityAuditLogAll(this.findOne(primaryKey.getEntityName(), primaryKey, false), true, true);
}
GenericValue removedEntity = null;
if (testMode) {
removedEntity = this.findOne(primaryKey.entityName, primaryKey, false);
}
int num = helper.removeByPrimaryKey(primaryKey);
this.saveEntitySyncRemoveInfo(primaryKey);
if (testMode) {
if (removedEntity != null) {
storeForTestRollback(new TestOperation(OperationType.DELETE, removedEntity));