private Map<FileHistoryId, FileVersion> fillFileHistoryIdCache(Collection<PartialFileHistory> fileHistoriesWithLastVersion) { Map<FileHistoryId, FileVersion> fileHistoryIdCache = new HashMap<FileHistoryId, FileVersion>(); for (PartialFileHistory fileHistory : fileHistoriesWithLastVersion) { fileHistoryIdCache.put(fileHistory.getFileHistoryId(), fileHistory.getLastVersion()); } return fileHistoryIdCache; } }
private void updateContentChecksumCache() { contentChecksumFileHistoriesCache.clear(); for (PartialFileHistory fullFileHistory : fullDatabaseVersionCache.getFileHistories()) { FileChecksum lastVersionChecksum = fullFileHistory.getLastVersion().getChecksum(); if (lastVersionChecksum != null) { List<PartialFileHistory> historiesWithVersionsWithSameChecksum = contentChecksumFileHistoriesCache.get(lastVersionChecksum); // Create if it does not exist if (historiesWithVersionsWithSameChecksum == null) { historiesWithVersionsWithSameChecksum = new ArrayList<PartialFileHistory>(); } // Add to cache historiesWithVersionsWithSameChecksum.add(fullFileHistory); contentChecksumFileHistoriesCache.put(lastVersionChecksum, historiesWithVersionsWithSameChecksum); } } }
private void updateFilenameHistoryCache() { // TODO [medium] Performance: This throws away the unchanged entries. It should only update new database version filenameHistoryCache.clear(); for (PartialFileHistory cacheFileHistory : fullDatabaseVersionCache.getFileHistories()) { FileVersion lastVersion = cacheFileHistory.getLastVersion(); String fileName = lastVersion.getPath(); if (lastVersion.getStatus() != FileStatus.DELETED) { filenameHistoryCache.put(fileName, cacheFileHistory); } } }
private PartialFileHistory getFileHistoryByPathFromDatabaseVersion(DatabaseVersion databaseVersion, String path) { // TODO [medium] Extremely performance intensive, because this is called inside a loop above. Implement better caching for database version!!! for (PartialFileHistory fileHistory : databaseVersion.getFileHistories()) { FileVersion lastVersion = fileHistory.getLastVersion(); if (lastVersion.getStatus() != FileStatus.DELETED && lastVersion.getPath().equals(path)) { return fileHistory; } } return null; }
PartialFileHistory fileHistory = getLastVersionByFileHistoryId(fileHistoryId); boolean resultIsLatestVersion = fileHistory.getLastVersion().getVersion() == resultSet.getLong("version"); boolean resultIsNotDelete = fileHistory.getLastVersion().getStatus() != FileVersion.FileStatus.DELETED;
FileVersion lastVersion = fileHistoryWithSameChecksum.getLastVersion(); String currentPreviousPath = lastFileHistory.getLastVersion().getPath(); String candidatePreviousPath = fileHistoryWithSameChecksum.getLastVersion().getPath();
if (fileHistory.getLastVersion().getVersion() == latestFileVersion) { return fileHistory;
private void removeDeletedFiles(DatabaseVersion newDatabaseVersion, List<File> deletedFiles) { logger.log(Level.FINER, "- Looking for deleted files ..."); for (File deletedFile : deletedFiles) { String path = FileUtil.getRelativeDatabasePath(config.getLocalDir(), deletedFile); PartialFileHistory fileHistory = localDatabase.getFileHistoriesWithLastVersionByPath(path); // Ignore this file history if it has been updated in this database version before (file probably renamed!) if (newDatabaseVersion.getFileHistory(fileHistory.getFileHistoryId()) != null) { continue; } // Check if file exists, remove if it doesn't FileVersion lastLocalVersion = fileHistory.getLastVersion(); File lastLocalVersionOnDisk = new File(config.getLocalDir() + File.separator + lastLocalVersion.getPath()); // Ignore this file history if the last version is marked "DELETED" if (lastLocalVersion.getStatus() == FileStatus.DELETED) { continue; } // Add this file history if a new file with this name has been added (file type change) PartialFileHistory newFileWithSameName = getFileHistoryByPathFromDatabaseVersion(newDatabaseVersion, fileHistory.getLastVersion() .getPath()); // If file has VANISHED, mark as DELETED if (!FileUtil.exists(lastLocalVersionOnDisk) || newFileWithSameName != null) { PartialFileHistory fileHistoryForDeletion = createFileHistoryForDeletion(fileHistory, lastLocalVersion); newDatabaseVersion.addFileHistory(fileHistoryForDeletion); logger.log(Level.FINER, " + Deleted: Adding DELETED version: {0}", fileHistoryForDeletion.getLastVersion()); logger.log(Level.FINER, " based on: {0}", lastLocalVersion); } } }
private PartialFileHistory createFileHistoryForDeletion(PartialFileHistory fileHistory, FileVersion lastLocalVersion) { PartialFileHistory deletedFileHistory = new PartialFileHistory(fileHistory.getFileHistoryId()); FileVersion deletedVersion = lastLocalVersion.clone(); deletedVersion.setStatus(FileStatus.DELETED); deletedVersion.setVersion(fileHistory.getLastVersion().getVersion() + 1); deletedVersion.setUpdated(new Date()); deletedFileHistory.addFileVersion(deletedVersion); return deletedFileHistory; }
/** * This method fills a {@link ChangeSet} with the files and changes that are uploaded, to include in * the {@link UpOperationResult}. * * @param newDatabaseVersion {@link DatabaseVersion} that contains the changes. * @param resultChanges {@ChangeSet} to which these changes are to be added. */ private void addNewDatabaseChangesToResultChanges(DatabaseVersion newDatabaseVersion, ChangeSet resultChanges) { for (PartialFileHistory partialFileHistory : newDatabaseVersion.getFileHistories()) { FileVersion lastFileVersion = partialFileHistory.getLastVersion(); switch (lastFileVersion.getStatus()) { case NEW: resultChanges.getNewFiles().add(lastFileVersion.getPath()); break; case CHANGED: case RENAMED: resultChanges.getChangedFiles().add(lastFileVersion.getPath()); break; case DELETED: resultChanges.getDeletedFiles().add(lastFileVersion.getPath()); break; } } }
FileVersion winningLastVersion = winningFileHistory.getLastVersion(); File winningLastFile = new File(config.getLocalDir(), winningLastVersion.getPath()); FileVersion localLastVersion = localFileHistoryWithLastVersion.getLastVersion(); File localLastFile = (localLastVersion != null) ? new File(config.getLocalDir(), localLastVersion.getPath()) : null;
FileVersion fileVersion = fileHistory.getLastVersion();
FileVersion lastFileVersion = (lastFileHistory != null) ? lastFileHistory.getLastVersion() : null;