private void completeInPlaceRestore(FileDTO file, VersionDTO version)
 	throws DBException, IOException
 {
  Manager db = getDb();
  Logger log = log();
  ReplicaDTO replica = getCurrentReplica();
  FileDAO fileDAO = db.findDAO(FileDAO.class);
  LastSyncDAO lsDAO = db.findDAO(LastSyncDAO.class);
  VersionDAO versionDAO = db.findDAO(VersionDAO.class);
  Number nameId = version.getNameId();
  if (null == nameId)
   nameId = file.getNameId();
  // use a transaction for undelete, rename (if needed) and sync record update
  Transaction txn = db.beginTransaction();
  try
  {
   // if the restored file needs renaming 
   if (file.getNameId() != nameId.longValue())
   {
    File originalPath = db.findDAO(NodeNameDAO.class).toLocalFile(file.getNameId(), replica.getPath());
    VersionDTO current = versionDAO.findCurrentVersion(file);
    if (!current.isDeletionMark() && originalPath.isFile() && !originalPath.delete())
     log.warning("Cleanup failed for local file '" + originalPath + "'");
    versionDAO.beforeFileNameChange(file);
    lsDAO.beforeFileNameChange(file);
    file.setNameId(nameId.longValue());
    fileDAO.update(file);
   }
   // update the sync record when a file is being restored in-place
   lsDAO.recordSync(replica, version);
   txn.commit();
   txn = null;
  }
  finally
  {
   if (null != txn)
    try { txn.abort(); }
    catch (DBException fail)
    {
     log.log(Level.WARNING, "Rollback failed after unsuccessful renaming of " + file, fail);
    }
  }
 }