@Override
 public List<SAProcessInstance> searchArchivedProcessInstances(final QueryOptions queryOptions)
     throws SBonitaSearchException {
   final ReadPersistenceService persistenceService =
       archiveService.getDefinitiveArchiveReadPersistenceService();
   try {
     return persistenceService.searchEntity(SAProcessInstance.class, queryOptions, null);
   } catch (final SBonitaReadException e) {
     throw new SBonitaSearchException(e);
   }
 }
 @Override
 public long getNumberOfArchivedProcessInstances(final QueryOptions queryOptions)
     throws SBonitaSearchException {
   final ReadPersistenceService persistenceService =
       archiveService.getDefinitiveArchiveReadPersistenceService();
   try {
     return persistenceService.getNumberOfEntities(SAProcessInstance.class, queryOptions, null);
   } catch (final SBonitaReadException bre) {
     throw new SBonitaSearchException(bre);
   }
 }
 @Override
 public long getNumberOfArchivedProcessInstancesSupervisedBy(
     final long userId, final QueryOptions countOptions) throws SBonitaSearchException {
   final ReadPersistenceService persistenceService =
       archiveService.getDefinitiveArchiveReadPersistenceService();
   final Map<String, Object> parameters = Collections.singletonMap(USER_ID, (Object) userId);
   try {
     return persistenceService.getNumberOfEntities(
         SAProcessInstance.class, SUPERVISED_BY, countOptions, parameters);
   } catch (final SBonitaReadException bre) {
     throw new SBonitaSearchException(bre);
   }
 }
 @Override
 public List<SAProcessInstance> searchArchivedProcessInstancesInvolvingUser(
     final long userId, final QueryOptions queryOptions) throws SBonitaSearchException {
   final ReadPersistenceService persistenceService =
       archiveService.getDefinitiveArchiveReadPersistenceService();
   try {
     final Map<String, Object> parameters = new HashMap<String, Object>(1);
     parameters.put(USER_ID, userId);
     return persistenceService.searchEntity(
         SAProcessInstance.class, INVOLVING_USER, queryOptions, parameters);
   } catch (final SBonitaReadException e) {
     throw new SBonitaSearchException(e);
   }
 }
 @Override
 public SAProcessInstance getArchivedProcessInstance(final long archivedProcessInstanceId)
     throws SProcessInstanceReadException, SProcessInstanceNotFoundException {
   final ReadPersistenceService persistenceService =
       archiveService.getDefinitiveArchiveReadPersistenceService();
   try {
     final Map<String, Object> parameters =
         Collections.singletonMap("id", (Object) archivedProcessInstanceId);
     final SAProcessInstance saProcessInstance =
         persistenceService.selectOne(
             new SelectOneDescriptor<SAProcessInstance>(
                 "getArchivedProcessInstance", parameters, SAProcessInstance.class));
     if (saProcessInstance == null) {
       throw new SProcessInstanceNotFoundException(archivedProcessInstanceId);
     }
     return saProcessInstance;
   } catch (final SBonitaReadException e) {
     throw new SProcessInstanceReadException(e);
   }
 }
 private void archiveProcessInstance(final SProcessInstance processInstance)
     throws SProcessInstanceModificationException {
   final SAProcessInstance saProcessInstance =
       BuilderFactory.get(SAProcessInstanceBuilderFactory.class)
           .createNewInstance(processInstance)
           .done();
   final ArchiveInsertRecord insertRecord = new ArchiveInsertRecord(saProcessInstance);
   try {
     archiveService.recordInsert(System.currentTimeMillis(), insertRecord);
   } catch (final SRecorderException e) {
     throw new SProcessInstanceModificationException(e);
   } catch (final SDefinitiveArchiveNotFound e) {
     if (logger.isLoggable(this.getClass(), TechnicalLogSeverity.ERROR)) {
       logger.log(
           this.getClass(),
           TechnicalLogSeverity.ERROR,
           "The process instance was not archived. Id:" + processInstance.getId(),
           e);
     }
   }
 }
 @Override
 public List<Long> getSourceProcesInstanceIdsOfArchProcessInstancesFromDefinition(
     final long processDefinitionId,
     final int fromIndex,
     final int maxResults,
     final OrderByType sortingOrder)
     throws SProcessInstanceReadException {
   final ReadPersistenceService persistenceService =
       archiveService.getDefinitiveArchiveReadPersistenceService();
   final String saCommentSourceObjectId =
       BuilderFactory.get(SACommentBuilderFactory.class).getSourceObjectId();
   final QueryOptions queryOptions =
       new QueryOptions(
           fromIndex, maxResults, SAProcessInstance.class, saCommentSourceObjectId, sortingOrder);
   try {
     return persistenceService.selectList(
         SelectDescriptorBuilder.getSourceProcesInstanceIdsOfArchProcessInstancesFromDefinition(
             processDefinitionId, queryOptions));
   } catch (final SBonitaReadException e) {
     throw new SProcessInstanceReadException(e);
   }
 }