Package org.syncany.database.dao
Class FileContentSqlDao
- java.lang.Object
-
- org.syncany.database.dao.AbstractSqlDao
-
- org.syncany.database.dao.FileContentSqlDao
-
public class FileContentSqlDao extends AbstractSqlDao
The file content data access object (DAO) writes and queries the SQL database for information onFileContent
s. It translates the relational data in the filecontent table to Java objects.
-
-
Field Summary
-
Fields inherited from class org.syncany.database.dao.AbstractSqlDao
connection
-
-
Constructor Summary
Constructors Constructor Description FileContentSqlDao(java.sql.Connection connection)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description FileContent
getFileContent(FileContent.FileChecksum fileChecksum, boolean includeChunkChecksums)
Queries the database for a particularFileContent
, either with or without the corresponding chunk references (list ofChunkEntry.ChunkChecksum
).java.util.Map<FileContent.FileChecksum,FileContent>
getFileContents(VectorClock vectorClock)
Queries the SQL database for allFileContent
s that originally appeared in the database version identified by the given vector clock.void
removeUnreferencedFileContents()
Removes unreferencedFileContent
s from the database table filecontent, as well as the corresponding chunk references (list ofChunkEntry.ChunkChecksum
s) from the table filecontent_chunk.void
updateDirtyFileContentsNewDatabaseId(long newDatabaseVersionId)
no commitvoid
writeFileContents(java.sql.Connection connection, long databaseVersionId, java.util.Collection<FileContent> fileContents)
Writes a list ofFileContent
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
-
FileContentSqlDao
public FileContentSqlDao(java.sql.Connection connection)
-
-
Method Detail
-
writeFileContents
public void writeFileContents(java.sql.Connection connection, long databaseVersionId, java.util.Collection<FileContent> fileContents) throws java.sql.SQLException
Writes a list ofFileContent
s to the database usingINSERT
s and the given connection. It fills two tables, the filecontent table (FileContent
) and the filecontent_chunk table (ChunkEntry.ChunkChecksum
).To do the latter (write chunk references), this method calls
writeFileContentChunkRefs()
for everyFileContent
.Note: This method executes, but does not commit the queries.
- Parameters:
connection
- The connection used to execute the statementsdatabaseVersionId
-fileContents
- List ofFileContent
s to be inserted in the database- Throws:
java.sql.SQLException
- If the SQL statement fails
-
removeUnreferencedFileContents
public void removeUnreferencedFileContents() throws java.sql.SQLException
Removes unreferencedFileContent
s from the database table filecontent, as well as the corresponding chunk references (list ofChunkEntry.ChunkChecksum
s) from the table filecontent_chunk.Note: This method executes, but does not commit the query.
- Throws:
java.sql.SQLException
- If the SQL statement fails
-
getFileContent
public FileContent getFileContent(FileContent.FileChecksum fileChecksum, boolean includeChunkChecksums)
Queries the database for a particularFileContent
, either with or without the corresponding chunk references (list ofChunkEntry.ChunkChecksum
).- Parameters:
fileChecksum
-FileContent
-identifying file checksumincludeChunkChecksums
- Iftrue
, the resultingFileContent
will contain its chunk references- Returns:
- Returns a
FileContent
either with or without chunk references, ornull
if it does not exist.
-
getFileContents
public java.util.Map<FileContent.FileChecksum,FileContent> getFileContents(VectorClock vectorClock)
Queries the SQL database for allFileContent
s that originally appeared in the database version identified by the given vector clock.Note: This method does not select all the file contents that are referenced in the database version. In particular, it does not return file contents that appeared in previous other database versions.
- Parameters:
vectorClock
- Vector clock that identifies the database version- Returns:
- Returns all
FileContent
s that originally belong to a database version
-
updateDirtyFileContentsNewDatabaseId
public void updateDirtyFileContentsNewDatabaseId(long newDatabaseVersionId)
no commit
-
-