Exemplo n.º 1
0
  /**
   * Writes a list of {@link FileContent}s to the database using <tt>INSERT</tt>s and the given
   * connection. It fills two tables, the <i>filecontent</i> table ({@link FileContent}) and the
   * <i>filecontent_chunk</i> table ({@link ChunkChecksum}).
   *
   * <p>To do the latter (write chunk references), this method calls {@link
   * #writeFileContentChunkRefs(Connection, FileContent) writeFileContentChunkRefs()} for every
   * {@link FileContent}.
   *
   * <p><b>Note:</b> This method executes, but does not commit the queries.
   *
   * @param connection The connection used to execute the statements
   * @param databaseVersionId
   * @param fileContents List of {@link FileContent}s to be inserted in the database
   * @throws SQLException If the SQL statement fails
   */
  public void writeFileContents(
      Connection connection, long databaseVersionId, Collection<FileContent> fileContents)
      throws SQLException {
    for (FileContent fileContent : fileContents) {
      PreparedStatement preparedStatement =
          getStatement(connection, "filecontent.insert.all.writeFileContents.sql");

      preparedStatement.setString(1, fileContent.getChecksum().toString());
      preparedStatement.setLong(2, databaseVersionId);
      preparedStatement.setLong(3, fileContent.getSize());

      preparedStatement.executeUpdate();
      preparedStatement.close();

      // Write chunk references
      writeFileContentChunkRefs(connection, fileContent);
    }
  }
Exemplo n.º 2
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();
  }