public void create() throws HyracksDataException {
    synchronized (lcManager) {
      long resourceID = getResourceID();
      index = lcManager.getIndex(resourceID);
      if (index != null) {
        lcManager.unregister(resourceID);
      } else {
        index = createIndexInstance();
      }

      // The previous resource ID needs to be removed since calling IIndex.create() may possibly
      // destroy
      // any physical artifact that the LocalResourceRepository is managing (e.g. a file containing
      // the resource ID).
      // Once the index has been created, a new resource ID can be generated.
      if (resourceID != -1) {
        localResourceRepository.deleteResourceByName(file.getFile().getPath());
      }
      index.create();
      try {
        // TODO Create LocalResource through LocalResourceFactory interface
        resourceID = resourceIdFactory.createId();
        ILocalResourceFactory localResourceFactory =
            opDesc.getLocalResourceFactoryProvider().getLocalResourceFactory();
        localResourceRepository.insert(
            localResourceFactory.createLocalResource(
                resourceID, file.getFile().getPath(), partition));
      } catch (IOException e) {
        throw new HyracksDataException(e);
      }
      lcManager.register(resourceID, index);
    }
  }
 public long getResourceID() throws HyracksDataException {
   LocalResource localResource =
       localResourceRepository.getResourceByName(file.getFile().getPath());
   if (localResource == null) {
     return -1;
   } else {
     return localResource.getResourceId();
   }
 }
  public void destroy() throws HyracksDataException {
    synchronized (lcManager) {
      long resourceID = getResourceID();
      index = lcManager.getIndex(resourceID);
      if (index != null) {
        lcManager.unregister(resourceID);
      } else {
        index = createIndexInstance();
      }

      if (resourceID != -1) {
        localResourceRepository.deleteResourceByName(file.getFile().getPath());
      }
      index.destroy();
    }
  }