private PrivateInstanceLocal getPrivateInstance(
     InstanceLocal instance, int type, PrivateSeriesLocal privSeries)
     throws FinderException, CreateException {
   Collection col = privInstHome.findBySopIuid(type, instance.getSopIuid());
   PrivateInstanceLocal privInstance;
   if (col.isEmpty()) {
     if (privSeries == null) {
       privSeries = getPrivateSeries(instance.getSeries(), type, null, false);
     }
     privInstance = privInstHome.create(type, instance.getAttributes(true), privSeries);
   } else {
     privInstance = (PrivateInstanceLocal) col.iterator().next();
   }
   Object[] files = instance.getFiles().toArray();
   FileLocal file;
   for (int i = 0; i < files.length; i++) {
     file = (FileLocal) files[i];
     privFileHome.create(
         file.getFilePath(),
         file.getFileTsuid(),
         file.getFileSize(),
         file.getFileMd5(),
         file.getFileStatus(),
         privInstance,
         file.getFileSystem());
     try {
       file.remove();
     } catch (Exception x) {
       log.warn("Can not remove File record:" + file, x);
     }
   }
   return privInstance;
 }
 /**
  * @throws FinderException
  * @throws FinderException
  * @ejb.interface-method
  */
 public void deletePrivateInstance(long instance_pk) throws RemoteException, FinderException {
   try {
     PrivateInstanceLocal instance = privInstHome.findByPrimaryKey(new Long(instance_pk));
     PrivateSeriesLocal series = instance.getSeries();
     instance.remove();
     if (series.getInstances().isEmpty()) {
       PrivateStudyLocal study = series.getStudy();
       series.remove();
       if (study.getSeries().isEmpty()) {
         PrivatePatientLocal pat = study.getPatient();
         study.remove();
         if (pat.getStudies().isEmpty()) {
           pat.remove();
         }
       }
     }
   } catch (EJBException e) {
     throw new RemoteException(e.getMessage());
   } catch (RemoveException e) {
     throw new RemoteException(e.getMessage());
   }
 }