Esempio n. 1
0
  /**
   * Empty repository directory, record count and specific Data Source temporary files and
   * directories.
   *
   * @throws Exception
   */
  public void cleanUp() throws IOException {
    // Delete records indexes
    for (AccessPoint accessPoint : getAccessPoints().values()) {
      try {
        RepoxContextUtil.getRepoxManager().getAccessPointsManager().emptyIndex(this, accessPoint);
        log.info("Emptied AccessPoint with id " + accessPoint.getId());
      } catch (Exception e) {
        log.error("Unable to empty Table from Database: " + accessPoint.getId(), e);
      }
    }

    File dataSourceDir = getDataSourceDir();

    boolean deletedDir = true;
    if (dataSourceDir.exists()) {
      deletedDir = FileUtil.deleteDir(dataSourceDir);
      dataSourceDir.mkdir();
    }

    if (!deletedDir) {
      log.error("Unable to delete Data Source dir from Data Source with id " + id);
    } else {
      log.info("Deleted Data Source dir with success from Data Source with id " + id);
    }

    RepoxContextUtil.getRepoxManager().getRecordCountManager().removeDataSourceCounts(id);
  }
Esempio n. 2
0
 public void renameDataSourceDir(String oldDataSourceId, String newDataSourceId)
     throws FileNotFoundException, IOException {
   File dataSourceDir = getDataSourceDir(oldDataSourceId);
   if (dataSourceDir.exists()) {
     dataSourceDir.renameTo(getDataSourceDir(newDataSourceId));
   }
 }
Esempio n. 3
0
 public String getSynchronizationDateString() throws FileNotFoundException, IOException {
   File syncDateFile = getSyncDateFile();
   if (!syncDateFile.exists()) {
     return null;
   }
   String syncDate = FileUtil.readFileToString(syncDateFile);
   return syncDate;
 }
Esempio n. 4
0
  protected int getLastTaskId() throws IOException {
    int lastId = 0;

    File lastTaskFile = new File(getTasksDir(), LAST_TASK_FILENAME);
    if (lastTaskFile.exists()) {
      BufferedReader reader =
          new BufferedReader(new InputStreamReader(new FileInputStream(lastTaskFile)));
      String currentLine;
      if ((currentLine = reader.readLine()) != null) {
        try {
          lastId = Integer.parseInt(currentLine);
        } catch (NumberFormatException e) {
          log.error("Trying to parse as int: " + currentLine, e);
        }
      }
    }

    return lastId;
  }
Esempio n. 5
0
  protected void setLastTaskId(int taskId) throws IOException {
    File lastTaskFile = new File(getTasksDir(), LAST_TASK_FILENAME);
    if (lastTaskFile.exists()) {
      File backupFile = new File(lastTaskFile.getParent(), lastTaskFile.getName() + ".bkp");
      FileUtil.copyFile(lastTaskFile, backupFile);
    }

    BufferedWriter writer = null;
    try {
      writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(lastTaskFile)));
      writer.write(new Integer(taskId).toString());
      writer.newLine();
    } catch (IOException e) {
      log.error("Error writing last task file", e);
    } finally {
      if (writer != null) {
        writer.close();
      }
    }
  }