@Override public List<ProcessChange> removeSubEquipment(final Long subEquipmentId,final ConfigurationElementReport subEquipmentReport){
  log.debug("Removing SubEquipment " + subEquipmentId);
  subEquipmentCache.acquireWriteLockOnKey(subEquipmentId);
  try {
    SubEquipment subEquipment=subEquipmentCache.get(subEquipmentId);
    List<ProcessChange> changes=removeSubEquipmentTags(subEquipment,subEquipmentReport);
    try {
      changes.addAll(subEquipmentConfigTransacted.doRemoveSubEquipment(subEquipment,subEquipmentReport));
      subEquipmentCache.releaseWriteLockOnKey(subEquipmentId);
      changes.addAll(removeEquipmentControlTags(subEquipment,subEquipmentReport));
      subEquipmentFacade.removeAliveTimer(subEquipmentId);
      subEquipmentFacade.removeCommFault(subEquipmentId);
      subEquipmentCache.remove(subEquipmentId);
      subEquipmentFacade.removeSubEquipmentFromEquipment(subEquipment.getParentId(),subEquipmentId);
      return changes;
    }
 catch (    RuntimeException e) {
      subEquipmentReport.setFailure("Exception caught while removing Sub-equipment " + subEquipmentId);
      throw new UnexpectedRollbackException("Exception caught while removing Sub-equipment",e);
    }
  }
 catch (  CacheElementNotFoundException e) {
    log.debug("SubEquipment not found in cache - unable to remove it.",e);
    subEquipmentReport.setWarning("SubEquipment not found in cache so cannot be removed.");
    return new ArrayList<ProcessChange>();
  }
 finally {
    if (subEquipmentCache.isWriteLockedByCurrentThread(subEquipmentId)) {
      subEquipmentCache.releaseWriteLockOnKey(subEquipmentId);
    }
  }
}

@ Override public List < ProcessChange > removeSubEquipment ( final Long subEquipmentId , final ConfigurationElementReport subEquipmentReport ) { log . debug ( "Removing SubEquipment " + subEquipmentId ) ; subEquipmentCache . acquireWriteLockOnKey ( subEquipmentId ) ; try { SubEquipment subEquipment = subEquipmentCache . get ( subEquipmentId ) ; List < ProcessChange > changes = removeSubEquipmentTags ( subEquipment , subEquipmentReport ) ; try { changes . addAll ( subEquipmentConfigTransacted . doRemoveSubEquipment ( subEquipment , subEquipmentReport ) ) ; subEquipmentCache . releaseWriteLockOnKey ( subEquipmentId ) ; changes . addAll ( removeEquipmentControlTags ( subEquipment , subEquipmentReport ) ) ; subEquipmentFacade . removeAliveTimer ( subEquipmentId ) ; subEquipmentFacade . removeCommFault ( subEquipmentId ) ; subEquipmentCache . remove ( subEquipmentId ) ; subEquipmentFacade . removeSubEquipmentFromEquipment ( subEquipment . getParentId ( ) , subEquipmentId ) ; return changes ; } catch ( RuntimeException e ) { subEquipmentReport . setFailure ( "Exception caught while removing Sub-equipment " + subEquipmentId ) ; throw new UnexpectedRollbackException ( "Exception caught while removing Sub-equipment" , e ) ; } } catch ( CacheElementNotFoundException e ) { log . debug ( "SubEquipment not found in cache - unable to remove it." , e ) ; subEquipmentReport . setWarning ( "SubEquipment not found in cache so cannot be removed." ) ; return new ArrayList < ProcessChange > ( ) ; } finally { if ( subEquipmentCache . isWriteLockedByCurrentThread ( subEquipmentId ) ) { subEquipmentCache . releaseWriteLockOnKey ( subEquipmentId ) ; } } }
first removes the subequipment from the db and cache . if successful , removes the associated control tags . < p > if an exception is thrown the subequipment will be restored in db ( transaction rollback ) .
