@Override
 public void deleteProcessInstance(final SProcessInstance sProcessInstance)
     throws SProcessInstanceModificationException {
   final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
   try {
     final long processDefinitionId = sProcessInstance.getProcessDefinitionId();
     final ClassLoader localClassLoader =
         classLoaderService.getLocalClassLoader("process", processDefinitionId);
     Thread.currentThread().setContextClassLoader(localClassLoader);
     deleteProcessInstanceElements(sProcessInstance);
     final DeleteRecord deleteRecord = new DeleteRecord(sProcessInstance);
     SDeleteEvent deleteEvent = null;
     if (eventService.hasHandlers(PROCESSINSTANCE, EventActionType.DELETED)) {
       deleteEvent =
           (SDeleteEvent)
               BuilderFactory.get(SEventBuilderFactory.class)
                   .createDeleteEvent(PROCESSINSTANCE)
                   .setObject(sProcessInstance)
                   .done();
     }
     recorder.recordDelete(deleteRecord, deleteEvent);
   } catch (final SBonitaException e) {
     throw new SProcessInstanceModificationException(e);
   } finally {
     Thread.currentThread().setContextClassLoader(contextClassLoader);
   }
 }
 @Override
 public void createDataInstance(final SDataInstance dataInstance) throws SDataInstanceException {
   try {
     final InsertRecord insertRecord = new InsertRecord(dataInstance);
     final SInsertEvent insertEvent = getInsertEvent(dataInstance);
     recorder.recordInsert(insertRecord, insertEvent);
   } catch (final SRecorderException e) {
     throw new SCreateDataInstanceException("Imposible to create data intance.", e);
   }
 }
 @Override
 public void deleteDataInstance(final SDataInstance dataInstance) throws SDataInstanceException {
   NullCheckingUtil.checkArgsNotNull(dataInstance);
   final DeleteRecord deleteRecord = new DeleteRecord(dataInstance);
   final SDeleteEvent deleteEvent = getDeleteEvent(dataInstance);
   try {
     recorder.recordDelete(deleteRecord, deleteEvent);
   } catch (final SRecorderException e) {
     throw new SDeleteDataInstanceException("Impossible to delete data instance", e);
   }
 }
 @Override
 public void updateDataInstance(
     final SDataInstance dataInstance, final EntityUpdateDescriptor descriptor)
     throws SDataInstanceException {
   NullCheckingUtil.checkArgsNotNull(dataInstance);
   final UpdateRecord updateRecord = UpdateRecord.buildSetFields(dataInstance, descriptor);
   final SUpdateEvent updateEvent = getUpdateEvent(dataInstance);
   try {
     recorder.recordUpdate(updateRecord, updateEvent);
   } catch (final SRecorderException e) {
     throw new SUpdateDataInstanceException(
         "Impossible to update data instance '" + dataInstance.getName() + "': " + e.getMessage(),
         e);
   }
 }
 @Override
 public void deleteArchivedProcessInstance(final SAProcessInstance archivedProcessInstance)
     throws SProcessInstanceModificationException {
   final DeleteRecord deleteRecord = new DeleteRecord(archivedProcessInstance);
   SDeleteEvent deleteEvent = null;
   if (eventService.hasHandlers(PROCESSINSTANCE, EventActionType.DELETED)) {
     deleteEvent =
         (SDeleteEvent)
             BuilderFactory.get(SEventBuilderFactory.class)
                 .createDeleteEvent(PROCESSINSTANCE)
                 .setObject(archivedProcessInstance)
                 .done();
   }
   try {
     recorder.recordDelete(deleteRecord, deleteEvent);
   } catch (final SRecorderException e) {
     throw new SProcessInstanceModificationException(e);
   }
 }
 @Override
 public void updateProcess(
     final SProcessInstance processInstance, final EntityUpdateDescriptor descriptor)
     throws SProcessInstanceModificationException {
   try {
     final UpdateRecord updateRecord = UpdateRecord.buildSetFields(processInstance, descriptor);
     SUpdateEvent updateEvent = null;
     if (eventService.hasHandlers(PROCESSINSTANCE, EventActionType.UPDATED)) {
       updateEvent =
           (SUpdateEvent)
               BuilderFactory.get(SEventBuilderFactory.class)
                   .createUpdateEvent(PROCESSINSTANCE)
                   .setObject(processInstance)
                   .done();
     }
     recorder.recordUpdate(updateRecord, updateEvent);
   } catch (final SRecorderException e) {
     throw new SProcessInstanceModificationException(e);
   }
 }
 private void updateProcessInstance(
     final SProcessInstance processInstance,
     final String message,
     final EntityUpdateDescriptor descriptor,
     final String eventType)
     throws SProcessInstanceModificationException {
   final UpdateRecord updateRecord = UpdateRecord.buildSetFields(processInstance, descriptor);
   SUpdateEvent updateEvent = null;
   if (eventService.hasHandlers(eventType, EventActionType.UPDATED)) {
     updateEvent =
         (SUpdateEvent)
             BuilderFactory.get(SEventBuilderFactory.class)
                 .createUpdateEvent(eventType)
                 .setObject(processInstance)
                 .done();
   }
   try {
     recorder.recordUpdate(updateRecord, updateEvent);
   } catch (final SRecorderException e) {
     throw new SProcessInstanceModificationException(e);
   }
 }
 @Override
 public void createProcessInstance(final SProcessInstance processInstance)
     throws SProcessInstanceCreationException {
   final InsertRecord insertRecord = new InsertRecord(processInstance);
   SInsertEvent insertEvent = null;
   if (eventService.hasHandlers(PROCESSINSTANCE, EventActionType.CREATED)) {
     insertEvent =
         (SInsertEvent)
             BuilderFactory.get(SEventBuilderFactory.class)
                 .createInsertEvent(PROCESSINSTANCE)
                 .setObject(processInstance)
                 .done();
   }
   try {
     recorder.recordInsert(insertRecord, insertEvent);
     setProcessState(processInstance, ProcessInstanceState.INITIALIZING);
   } catch (final SRecorderException sre) {
     throw new SProcessInstanceCreationException(sre);
   } catch (final SProcessInstanceModificationException spicme) {
     throw new SProcessInstanceCreationException(spicme);
   }
 }