use of org.syncany.database.PartialFileHistory.FileHistoryId in project syncany by syncany.
the class FileHistorySqlDao method getLastVersionByFileHistoryId.
private PartialFileHistory getLastVersionByFileHistoryId(String fileHistoryId) {
try (PreparedStatement preparedStatement = getStatement("filehistory.select.master.getLastVersionByFileHistoryId.sql")) {
preparedStatement.setString(1, fileHistoryId);
preparedStatement.setString(2, fileHistoryId);
try (ResultSet resultSet = preparedStatement.executeQuery()) {
if (resultSet.next()) {
FileVersion lastFileVersion = fileVersionDao.createFileVersionFromRow(resultSet);
FileHistoryId fileHistoryIdData = FileHistoryId.parseFileId(resultSet.getString("filehistory_id"));
PartialFileHistory fileHistory = new PartialFileHistory(fileHistoryIdData);
fileHistory.addFileVersion(lastFileVersion);
return fileHistory;
} else {
return null;
}
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
use of org.syncany.database.PartialFileHistory.FileHistoryId in project syncany by syncany.
the class FileVersionSqlDao method removeSpecificFileVersions.
public void removeSpecificFileVersions(Map<FileHistoryId, List<FileVersion>> purgeFileVersions) throws SQLException {
if (purgeFileVersions.size() > 0) {
try (PreparedStatement preparedStatement = getStatement(connection, "fileversion.delete.all.removeSpecificFileVersionsByIds.sql")) {
for (FileHistoryId purgeFileHistoryId : purgeFileVersions.keySet()) {
for (FileVersion purgeFileVersion : purgeFileVersions.get(purgeFileHistoryId)) {
preparedStatement.setString(1, purgeFileHistoryId.toString());
preparedStatement.setLong(2, purgeFileVersion.getVersion());
preparedStatement.addBatch();
}
}
preparedStatement.executeBatch();
}
}
}
use of org.syncany.database.PartialFileHistory.FileHistoryId in project syncany by syncany.
the class GetFileHistoryFolderRequestHandler method handleRequest.
@Override
public Response handleRequest(FolderRequest request) {
GetFileHistoryFolderRequest concreteRequest = (GetFileHistoryFolderRequest) request;
FileHistoryId fileHistoryId = FileHistoryId.parseFileId(concreteRequest.getFileHistoryId());
List<FileVersion> fileHistory = localDatabase.getFileHistory(fileHistoryId);
return new GetFileHistoryFolderResponse(concreteRequest.getId(), concreteRequest.getRoot(), fileHistory);
}
use of org.syncany.database.PartialFileHistory.FileHistoryId in project syncany by syncany.
the class MemoryDatabaseCacheTest method testRemoveDatabaseVersion.
@Test
public void testRemoveDatabaseVersion() {
MemoryDatabase database = new MemoryDatabase();
// Round 1: Add file history & version
DatabaseVersion databaseVersion1 = TestDatabaseUtil.createDatabaseVersion();
// - history 1, version 1
FileVersion fileVersion1 = TestDatabaseUtil.createFileVersion("file.jpg");
FileHistoryId idFile1 = FileHistoryId.parseFileId("1111111111111111");
PartialFileHistory fileHistory1 = new PartialFileHistory(idFile1);
fileHistory1.addFileVersion(fileVersion1);
databaseVersion1.addFileHistory(fileHistory1);
database.addDatabaseVersion(databaseVersion1);
// - history 1, version 2
DatabaseVersion databaseVersion2 = TestDatabaseUtil.createDatabaseVersion(databaseVersion1);
FileVersion fileVersion2 = TestDatabaseUtil.createFileVersion("file.jpg", fileVersion1);
FileHistoryId idFile1b = FileHistoryId.parseFileId("1111111111111111");
PartialFileHistory fileHistory1b = new PartialFileHistory(idFile1b);
fileHistory1b.addFileVersion(fileVersion2);
databaseVersion2.addFileHistory(fileHistory1b);
database.addDatabaseVersion(databaseVersion2);
// Tests: Database should have 2 versions of file
assertEquals(2, database.getFileHistory(idFile1).getFileVersions().size());
assertEquals(2, database.getFileHistory(idFile1b).getFileVersions().size());
// Round 2: Remove second database version
database.removeDatabaseVersion(databaseVersion2);
// Tests: Second version removed, 1 version left
assertEquals(1, database.getFileHistory(idFile1).getFileVersions().size());
assertEquals(1, database.getFileHistory(idFile1b).getFileVersions().size());
assertEquals(fileVersion1, database.getFileHistory(idFile1).getLastVersion());
// Round 3: Add database version again
database.addDatabaseVersion(databaseVersion2);
// Tests: Second version added, 2 versions of file
assertEquals(2, database.getFileHistory(idFile1).getFileVersions().size());
assertEquals(2, database.getFileHistory(idFile1b).getFileVersions().size());
// Round 4: Remove FIRST database version
database.removeDatabaseVersion(databaseVersion1);
// Tests: First version removed, 1 version left
assertEquals(1, database.getFileHistory(idFile1).getFileVersions().size());
assertEquals(1, database.getFileHistory(idFile1b).getFileVersions().size());
assertEquals(fileVersion2, database.getFileHistory(idFile1).getLastVersion());
// Round 5: Remove second database version
database.removeDatabaseVersion(databaseVersion2);
// Tests: Second version removed, none left
assertNull(database.getFileHistory(idFile1));
}
use of org.syncany.database.PartialFileHistory.FileHistoryId in project syncany by syncany.
the class RestoreOperation method execute.
@Override
public RestoreOperationResult execute() throws Exception {
logger.log(Level.INFO, "");
logger.log(Level.INFO, "Running 'Restore' at client " + config.getMachineName() + " ...");
logger.log(Level.INFO, "--------------------------------------------");
// Find file history
FileHistoryId restoreFileHistoryId = findFileHistoryId();
if (restoreFileHistoryId == null) {
return new RestoreOperationResult(RestoreResultCode.NACK_NO_FILE);
}
// Find file version
FileVersion restoreFileVersion = findRestoreFileVersion(restoreFileHistoryId);
if (restoreFileVersion == null) {
return new RestoreOperationResult(RestoreResultCode.NACK_NO_FILE);
} else if (restoreFileVersion.getType() == FileType.FOLDER) {
return new RestoreOperationResult(RestoreResultCode.NACK_INVALID_FILE);
}
logger.log(Level.INFO, "Restore file identified: " + restoreFileVersion);
// Download multichunks
downloadMultiChunks(restoreFileVersion);
// Restore file
logger.log(Level.INFO, "- Restoring: " + restoreFileVersion);
RestoreFileSystemAction restoreAction = new RestoreFileSystemAction(config, assembler, restoreFileVersion, options.getRelativeTargetPath());
RestoreFileSystemActionResult restoreResult = restoreAction.execute();
return new RestoreOperationResult(RestoreResultCode.ACK, restoreResult.getTargetFile());
}
Aggregations