Class ChunkSqlDao


  • public class ChunkSqlDao
    extends AbstractSqlDao
    The chunk data access object (DAO) writes and queries the SQL database for information on ChunkEntrys. It translates the relational data in the "chunk" table to Java objects.
    • Constructor Detail

      • ChunkSqlDao

        public ChunkSqlDao​(java.sql.Connection connection)
    • Method Detail

      • writeChunks

        public void writeChunks​(java.sql.Connection connection,
                                long databaseVersionId,
                                java.util.Collection<ChunkEntry> chunks)
                         throws java.sql.SQLException
        Writes a list of ChunkEntrys to the database using INSERTs and the given connection.

        Note: This method executes, but does not commit the query.

        Parameters:
        connection - The connection used to execute the statements
        databaseVersionId -
        chunks - List of ChunkEntrys to be inserted in the database
        Throws:
        java.sql.SQLException - If the SQL statement fails
      • removeUnreferencedChunks

        public void removeUnreferencedChunks()
        Removes unreferenced chunks from the database. Unreferenced chunks are chunks that are not referenced by any file content or multichunk.

        During the cleanup process, when file versions are deleted, unused chunks are left over. This method removes these chunks from the database.

        Note: This method executes, but does not commit the query.

      • getChunk

        public ChunkEntry getChunk​(ChunkEntry.ChunkChecksum chunkChecksum)
        Queries the database of a chunk with the given checksum.

        Note: When first called, this method loads the chunk cache and keeps this cache until it is cleared explicitly with clearCache().

        Also note that this method will return null if the chunk has been added after the cache has been filled.

        Parameters:
        chunkChecksum - Chunk checksum of the chunk to be selected
        Returns:
        Returns the chunk entry, or null if the chunk does not exist.
      • clearCache

        public void clearCache()
        Clears the chunk cache loaded by getChunk() and resets the cache. If getChunk() is called after the cache is cleared, it is re-populated.
      • getChunks

        public java.util.Map<ChunkEntry.ChunkChecksum,​ChunkEntrygetChunks​(VectorClock vectorClock)
        Queries the SQL database for all chunks that originally appeared in the database version identified by the given vector clock.

        Note: This method does not select all the chunks that are referenced in the database version. In particular, it does not return chunks that appeared in previous other database versions.

        Parameters:
        vectorClock - Vector clock that identifies the database version
        Returns:
        Returns all chunks that originally belong to a database version
      • createChunkEntryFromRow

        protected ChunkEntry createChunkEntryFromRow​(java.sql.ResultSet resultSet)
                                              throws java.sql.SQLException
        Throws:
        java.sql.SQLException