示例#1
1
  private FileContent getFileContentWithChunkChecksums(FileChecksum fileChecksum) {
    try (PreparedStatement preparedStatement =
        getStatement("filecontent.select.all.getFileContentByChecksumWithChunkChecksums.sql")) {
      preparedStatement.setString(1, fileChecksum.toString());

      try (ResultSet resultSet = preparedStatement.executeQuery()) {
        FileContent fileContent = null;

        while (resultSet.next()) {
          if (fileContent == null) {
            fileContent = new FileContent();

            fileContent.setChecksum(
                FileChecksum.parseFileChecksum(resultSet.getString("checksum")));
            fileContent.setSize(resultSet.getLong("size"));
          }

          // Add chunk references
          ChunkChecksum chunkChecksum =
              ChunkChecksum.parseChunkChecksum(resultSet.getString("chunk_checksum"));
          fileContent.addChunk(chunkChecksum);
        }

        return fileContent;
      }
    } catch (SQLException e) {
      throw new RuntimeException(e);
    }
  }
示例#2
0
  private Map<FileChecksum, FileContent> createFileContents(ResultSet resultSet)
      throws SQLException {
    Map<FileChecksum, FileContent> fileContents = new HashMap<FileChecksum, FileContent>();
    FileChecksum currentFileChecksum = null;

    while (resultSet.next()) {
      FileChecksum fileChecksum = FileChecksum.parseFileChecksum(resultSet.getString("checksum"));
      FileContent fileContent = null;

      if (currentFileChecksum != null && currentFileChecksum.equals(fileChecksum)) {
        fileContent = fileContents.get(fileChecksum);
      } else {
        fileContent = new FileContent();

        fileContent.setChecksum(fileChecksum);
        fileContent.setSize(resultSet.getLong("size"));
      }

      ChunkChecksum chunkChecksum =
          ChunkChecksum.parseChunkChecksum(resultSet.getString("chunk_checksum"));
      fileContent.addChunk(chunkChecksum);

      fileContents.put(fileChecksum, fileContent);
      currentFileChecksum = fileChecksum;
    }

    return fileContents;
  }
示例#3
0
    private void addFileVersion(FileProperties fileProperties) {
      if (fileProperties.getChecksum() != null) {
        logger.log(
            Level.FINER,
            "- /File: {0} (checksum {1})",
            new Object[] {fileProperties.getRelativePath(), fileProperties.getChecksum()});
      } else {
        logger.log(
            Level.FINER,
            "- /File: {0} (directory/symlink/0-byte-file)",
            fileProperties.getRelativePath());
      }

      // 1. Determine if file already exists in database
      PartialFileHistory lastFileHistory = guessLastFileHistory(fileProperties);
      FileVersion lastFileVersion =
          (lastFileHistory != null) ? lastFileHistory.getLastVersion() : null;

      // 2. Create new file history/version
      PartialFileHistory fileHistory = createNewFileHistory(lastFileHistory);
      FileVersion fileVersion = createNewFileVersion(lastFileVersion, fileProperties);

      // 3. Compare new and last version
      FileProperties lastFileVersionProperties =
          fileVersionComparator.captureFileProperties(lastFileVersion);
      FileVersionComparison lastToNewFileVersionComparison =
          fileVersionComparator.compare(fileProperties, lastFileVersionProperties, true);

      boolean newVersionDiffersFromToLastVersion = !lastToNewFileVersionComparison.equals();

      if (newVersionDiffersFromToLastVersion) {
        fileHistory.addFileVersion(fileVersion);
        newDatabaseVersion.addFileHistory(fileHistory);

        logger.log(Level.INFO, "   * Added file version:    " + fileVersion);
        logger.log(Level.INFO, "     based on file version: " + lastFileVersion);
      } else {
        logger.log(Level.INFO, "   * NOT ADDING file version: " + fileVersion);
        logger.log(Level.INFO, "         b/c IDENTICAL prev.: " + lastFileVersion);
      }

      // 4. Add file content (if not a directory)
      if (fileProperties.getChecksum() != null && fileContent != null) {
        fileContent.setSize(fileProperties.getSize());
        fileContent.setChecksum(fileProperties.getChecksum());

        // Check if content already exists, throw gathered content away if it does!
        FileContent existingContent =
            localDatabase.getFileContent(fileProperties.getChecksum(), false);

        if (existingContent == null) {
          newDatabaseVersion.addFileContent(fileContent);
        } else {
          // Uses existing content (already in database); ref. by checksum
        }
      }
    }
示例#4
0
  private FileContent getFileContentWithoutChunkChecksums(FileChecksum fileChecksum) {
    try (PreparedStatement preparedStatement =
        getStatement("filecontent.select.all.getFileContentByChecksumWithoutChunkChecksums.sql")) {
      preparedStatement.setString(1, fileChecksum.toString());

      try (ResultSet resultSet = preparedStatement.executeQuery()) {
        if (resultSet.next()) {
          FileContent fileContent = new FileContent();

          fileContent.setChecksum(FileChecksum.parseFileChecksum(resultSet.getString("checksum")));
          fileContent.setSize(resultSet.getLong("size"));

          return fileContent;
        }
      }

      return null;
    } catch (SQLException e) {
      throw new RuntimeException(e);
    }
  }