class DefaultComponentMaintenanceImpl extends FacetSupport implements ComponentMaintenance {

  @Override
  public DeletionProgress deleteComponents(final Iterable<EntityId> components,
                                           final BooleanSupplier cancelledCheck,
                                           final int batchSize)
  {
    checkNotNull(components);
    checkNotNull(cancelledCheck);

    UnitOfWork.beginBatch(getRepository().facet(StorageFacet.class).txSupplier());

    DeletionProgress deletionProgress = new DeletionProgress();

    try {
      Iterable<List<EntityId>> split = partition(components, batchSize);
      for (List<EntityId> entityIds : split) {
        
        if (cancelledCheck.getAsBoolean()) {
          break;
        }

        DeletionProgress batchDeletion = doBatchDelete(entityIds, cancelledCheck);
        deletionProgress.addCount(batchDeletion.getCount());
        if (batchDeletion.isFailed()) {
          deletionProgress.setFailed(true);
          break;
        }
      }
    }
    finally {
      UnitOfWork.end();
    }

    tryAfter();

    return deletionProgress;
  }

}