Package org.syncany.database.dao
Class ChunkSqlDao
- java.lang.Object
-
- org.syncany.database.dao.AbstractSqlDao
-
- org.syncany.database.dao.ChunkSqlDao
-
public class ChunkSqlDao extends AbstractSqlDao
The chunk data access object (DAO) writes and queries the SQL database for information onChunkEntry
s. It translates the relational data in the "chunk" table to Java objects.
-
-
Field Summary
-
Fields inherited from class org.syncany.database.dao.AbstractSqlDao
connection
-
-
Constructor Summary
Constructors Constructor Description ChunkSqlDao(java.sql.Connection connection)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clearCache()
Clears the chunk cache loaded bygetChunk()
and resets the cache.protected java.util.Map<ChunkEntry.ChunkChecksum,ChunkEntry>
createChunkEntries(java.sql.ResultSet resultSet)
protected ChunkEntry
createChunkEntryFromRow(java.sql.ResultSet resultSet)
ChunkEntry
getChunk(ChunkEntry.ChunkChecksum chunkChecksum)
Queries the database of a chunk with the given checksum.java.util.Map<ChunkEntry.ChunkChecksum,ChunkEntry>
getChunks(VectorClock vectorClock)
Queries the SQL database for all chunks that originally appeared in the database version identified by the given vector clock.protected void
loadChunkCache()
void
removeUnreferencedChunks()
Removes unreferenced chunks from the database.void
updateDirtyChunksNewDatabaseId(long newDatabaseVersionId)
no commitvoid
writeChunks(java.sql.Connection connection, long databaseVersionId, java.util.Collection<ChunkEntry> chunks)
Writes a list ofChunkEntry
s to the database usingINSERT
s and the given connection.-
Methods inherited from class org.syncany.database.dao.AbstractSqlDao
getConnection, getStatement, getStatement, runScript
-
-
-
-
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 ofChunkEntry
s to the database usingINSERT
s and the given connection.Note: This method executes, but does not commit the query.
- Parameters:
connection
- The connection used to execute the statementsdatabaseVersionId
-chunks
- List ofChunkEntry
s 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 bygetChunk()
and resets the cache. IfgetChunk()
is called after the cache is cleared, it is re-populated.
-
getChunks
public java.util.Map<ChunkEntry.ChunkChecksum,ChunkEntry> getChunks(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
-
createChunkEntries
protected java.util.Map<ChunkEntry.ChunkChecksum,ChunkEntry> createChunkEntries(java.sql.ResultSet resultSet) throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
createChunkEntryFromRow
protected ChunkEntry createChunkEntryFromRow(java.sql.ResultSet resultSet) throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
loadChunkCache
protected void loadChunkCache()
-
updateDirtyChunksNewDatabaseId
public void updateDirtyChunksNewDatabaseId(long newDatabaseVersionId)
no commit
-
-