public void addFileHistory(PartialFileHistory history) { fileHistories.put(history.getFileHistoryId(), history); }
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; } }
/** * Writes a list of {@link PartialFileHistory}s to the database table <i>filehistory</i> using <tt>INSERT</tt>s * and the given connection. In addition, this method also writes the corresponding {@link FileVersion}s of * each file history to the database using * {@link FileVersionSqlDao#writeFileVersions(Connection, FileHistoryId, long, Collection) FileVersionSqlDao#writeFileVersions}. * * <p><b>Note:</b> This method executes, but <b>does not commit</b> the queries. * * @param connection The connection used to execute the statements * @param databaseVersionId References the {@link PartialFileHistory} to which the list of file versions belongs * @param fileHistories List of {@link PartialFileHistory}s to be written to the database * @throws SQLException If the SQL statement fails */ public void writeFileHistories(Connection connection, long databaseVersionId, Collection<PartialFileHistory> fileHistories) throws SQLException { for (PartialFileHistory fileHistory : fileHistories) { PreparedStatement preparedStatement = getStatement(connection, "filehistory.insert.all.writeFileHistories.sql"); preparedStatement.setString(1, fileHistory.getFileHistoryId().toString()); preparedStatement.setLong(2, databaseVersionId); int affectedRows = preparedStatement.executeUpdate(); if (affectedRows == 0) { throw new SQLException("Cannot add database version header. Affected rows is zero."); } preparedStatement.close(); fileVersionDao.writeFileVersions(connection, fileHistory.getFileHistoryId(), databaseVersionId, fileHistory.getFileVersions().values()); } }
protected Map<FileHistoryId, PartialFileHistory> createFileHistoriesFromResult(ResultSet resultSet) throws SQLException { Map<FileHistoryId, PartialFileHistory> fileHistories = new HashMap<FileHistoryId, PartialFileHistory>(); PartialFileHistory fileHistory = null; while (resultSet.next()) { FileVersion lastFileVersion = fileVersionDao.createFileVersionFromRow(resultSet); FileHistoryId fileHistoryId = FileHistoryId.parseFileId(resultSet.getString("filehistory_id")); // Old history (= same filehistory identifier) if (fileHistory != null && fileHistory.getFileHistoryId().equals(fileHistoryId)) { // Same history! fileHistory.addFileVersion(lastFileVersion); } // New history! else { // Add the old history if (fileHistory != null) { fileHistories.put(fileHistory.getFileHistoryId(), fileHistory); } // Create a new one fileHistory = new PartialFileHistory(fileHistoryId); fileHistory.addFileVersion(lastFileVersion); } } // Add the last history if (fileHistory != null) { fileHistories.put(fileHistory.getFileHistoryId(), fileHistory); } return fileHistories; }
private PartialFileHistory createNewFileHistory(PartialFileHistory lastFileHistory) { if (lastFileHistory == null) { FileHistoryId newFileHistoryId = FileHistoryId.secureRandomFileId(); return new PartialFileHistory(newFileHistoryId); } else { return new PartialFileHistory(lastFileHistory.getFileHistoryId()); } }
private PartialFileHistory guessLastFileHistoryForFolderOrSymlink(FileProperties fileProperties) { PartialFileHistory lastFileHistory = localDatabase.getFileHistoriesWithLastVersionByPath(fileProperties.getRelativePath()); if (lastFileHistory == null) { logger.log(Level.FINER, " * No old file history found, starting new history (path: " + fileProperties.getRelativePath() + ", " + fileProperties.getType() + ")"); return null; } else { logger.log(Level.FINER, " * Found old file history " + lastFileHistory.getFileHistoryId() + " (by path: " + fileProperties.getRelativePath() + "), " + fileProperties.getType() + ", appending new version."); return lastFileHistory; } }
private void printGroupedHistories(LsOperationResult operationResult, int longestSize, int longestVersion) { Iterator<FileVersion> fileVersionIterator = operationResult.getFileList().iterator(); while (fileVersionIterator.hasNext()) { FileVersion fileVersion = fileVersionIterator.next(); PartialFileHistory fileHistory = operationResult.getFileVersions().get(fileVersion.getFileHistoryId()); out.printf("File %s, %s\n", formatObjectId(fileHistory.getFileHistoryId()), fileVersion.getPath()); for (FileVersion fileVersionInHistory : fileHistory.getFileVersions().values()) { if (fileVersionInHistory.equals(fileVersion)) { out.print(" * "); } else { out.print(" "); } printOneVersion(fileVersionInHistory, longestVersion, longestSize); } if (fileVersionIterator.hasNext()) { out.println(); } } }
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; }
" * Found old file history " + lastFileHistory.getFileHistoryId() + " (by checksum: " + fileProperties.getChecksum() + "), appending new version."); return lastFileHistory; " * Found old file history " + lastFileHistory.getFileHistoryId() + " (by path: " + fileProperties.getRelativePath() + "), appending new version."); return lastFileHistory;
FileVersion localLastVersion = localFileHistoryIdCache.get(winningFileHistory.getFileHistoryId()); File localLastFile = (localLastVersion != null) ? new File(config.getLocalDir(), localLastVersion.getPath()) : null; boolean localFileHistoryInWinnersDatabase = winnerFileHistoryIdCache.get(localFileHistoryWithLastVersion.getFileHistoryId()) != null;
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); } } }
xmlOut.writeAttribute("id", fileHistory.getFileHistoryId().toString());
PartialFileHistory targetFileHistory = fullDatabaseVersionCache.getFileHistory(sourceFileHistory.getFileHistoryId());