/** * Clones the file history, including its file versions. Note that file versions * are not cloned, but copied by reference. * * @return Returns cloned file history */ @Override public PartialFileHistory clone() { PartialFileHistory clone = new PartialFileHistory(fileHistoryId); clone.versions.putAll(versions); return clone; }
private PartialFileHistory createNewFileHistory(PartialFileHistory lastFileHistory) { if (lastFileHistory == null) { FileHistoryId newFileHistoryId = FileHistoryId.secureRandomFileId(); return new PartialFileHistory(newFileHistoryId); } else { return new PartialFileHistory(lastFileHistory.getFileHistoryId()); } }
public List<PartialFileHistory> getFileHistoriesWithLastVersion() { List<PartialFileHistory> fileHistories = new ArrayList<PartialFileHistory>(); try (PreparedStatement preparedStatement = getStatement("filehistory.select.master.getFileHistoriesWithLastVersion.sql")) { try (ResultSet resultSet = preparedStatement.executeQuery()) { while (resultSet.next()) { FileHistoryId fileHistoryId = FileHistoryId.parseFileId(resultSet.getString("filehistory_id")); FileVersion lastFileVersion = fileVersionDao.createFileVersionFromRow(resultSet); PartialFileHistory fileHistory = new PartialFileHistory(fileHistoryId); fileHistory.addFileVersion(lastFileVersion); fileHistories.add(fileHistory); } } return fileHistories; } catch (SQLException e) { throw new RuntimeException(e); } } }
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); } }
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 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; }
String fileHistoryIdStr = attributes.getValue("id"); FileHistoryId fileId = FileHistoryId.parseFileId(fileHistoryIdStr); fileHistory = new PartialFileHistory(fileId);
public PartialFileHistory getFileHistoryWithLastVersion(String relativePath) { try (PreparedStatement preparedStatement = getStatement("filehistory.select.master.getFileHistoryWithLastVersion.sql")) { preparedStatement.setString(1, relativePath); try (ResultSet resultSet = preparedStatement.executeQuery()) { if (resultSet.next()) { FileHistoryId fileHistoryId = FileHistoryId.parseFileId(resultSet.getString("filehistory_id")); FileVersion lastFileVersion = fileVersionDao.createFileVersionFromRow(resultSet); PartialFileHistory fileHistory = new PartialFileHistory(fileHistoryId); fileHistory.addFileVersion(lastFileVersion); return fileHistory; } } return null; } catch (SQLException e) { throw new RuntimeException(e); } } }
public PartialFileHistory getFileHistoryWithFileVersions(String relativePath) { try { PreparedStatement preparedStatement = getStatement("filehistory.select.master.getFileHistoryWithFileVersions.sql"); preparedStatement.setString(1, relativePath); preparedStatement.setString(2, FileStatus.DELETED.toString()); ResultSet resultSet = preparedStatement.executeQuery(); PartialFileHistory fileHistory = null; while (resultSet.next()) { if (fileHistory == null) { FileHistoryId fileHistoryId = FileHistoryId.parseFileId(resultSet.getString("filehistory_id")); fileHistory = new PartialFileHistory(fileHistoryId); } FileVersion fileVersion = fileVersionDao.createFileVersionFromRow(resultSet); fileHistory.addFileVersion(fileVersion); } return fileHistory; } catch (SQLException e) { throw new RuntimeException(e); } }