Пример #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 writeFileContentChunkRefs(Connection connection, FileContent fileContent)
      throws SQLException {
    PreparedStatement preparedStatement =
        getStatement(connection, "filecontent.insert.all.writeFileContentChunkRefs.sql");
    int order = 0;

    for (ChunkChecksum chunkChecksum : fileContent.getChunks()) {

      preparedStatement.setString(1, fileContent.getChecksum().toString());
      preparedStatement.setString(2, chunkChecksum.toString());
      preparedStatement.setInt(3, order);

      preparedStatement.addBatch();

      order++;
    }

    preparedStatement.executeBatch();
    preparedStatement.close();
  }
Пример #4
0
    /**
     * Checks if chunk already exists in all database versions Afterwards checks if chunk exists in
     * new introduced database version.
     */
    @Override
    public boolean onChunk(Chunk chunk) {
      ChunkChecksum chunkChecksum = new ChunkChecksum(chunk.getChecksum());
      chunkEntry = localDatabase.getChunk(chunkChecksum);

      if (chunkEntry == null) {
        chunkEntry = newDatabaseVersion.getChunk(chunkChecksum);

        if (chunkEntry == null) {
          logger.log(Level.FINER, "- Chunk new: {0}", chunkChecksum.toString());

          chunkEntry = new ChunkEntry(chunkChecksum, chunk.getSize());
          newDatabaseVersion.addChunk(chunkEntry);

          return true;
        }
      }

      logger.log(Level.FINER, "- Chunk exists: {0}", StringUtil.toHex(chunk.getChecksum()));
      return false;
    }