private Map<FileHistoryId, FileVersion> getSingleVersionInHistory(PreparedStatement preparedStatement) throws SQLException { try (ResultSet resultSet = preparedStatement.executeQuery()) { Map<FileHistoryId, FileVersion> mostRecentPurgeFileVersions = new HashMap<FileHistoryId, FileVersion>(); while (resultSet.next()) { FileHistoryId fileHistoryId = FileHistoryId.parseFileId(resultSet.getString("filehistory_id")); FileVersion fileVersion = createFileVersionFromRow(resultSet); mostRecentPurgeFileVersions.put(fileHistoryId, fileVersion); } return mostRecentPurgeFileVersions; } }
private Map<FileHistoryId, List<FileVersion>> getAllVersionsInQuery(PreparedStatement preparedStatement) throws SQLException { try (ResultSet resultSet = preparedStatement.executeQuery()) { Map<FileHistoryId, List<FileVersion>> fileHistoryPurgeFileVersions = new HashMap<FileHistoryId, List<FileVersion>>(); while (resultSet.next()) { FileHistoryId fileHistoryId = FileHistoryId.parseFileId(resultSet.getString("filehistory_id")); FileVersion fileVersion = createFileVersionFromRow(resultSet); List<FileVersion> purgeFileVersions = fileHistoryPurgeFileVersions.get(fileHistoryId); if (purgeFileVersions == null) { purgeFileVersions = new ArrayList<FileVersion>(); fileHistoryPurgeFileVersions.put(fileHistoryId, purgeFileVersions); } purgeFileVersions.add(fileVersion); } return fileHistoryPurgeFileVersions; } }
public FileHistoryId expandFileHistoryId(FileHistoryId fileHistoryIdPrefix) { String fileHistoryIdPrefixLikeQuery = fileHistoryIdPrefix.toString() + "%"; try (PreparedStatement preparedStatement = getStatement("filehistory.select.master.expandFileHistoryId.sql")) { preparedStatement.setString(1, fileHistoryIdPrefixLikeQuery); try (ResultSet resultSet = preparedStatement.executeQuery()) { if (resultSet.next()) { FileHistoryId fullFileHistoryId = FileHistoryId.parseFileId(resultSet.getString("filehistory_id")); boolean nonUniqueResult = resultSet.next(); if (nonUniqueResult) { return null; } else { return fullFileHistoryId; } } else { return null; } } } catch (SQLException e) { throw new RuntimeException(e); } }
FileHistoryId fileId = FileHistoryId.parseFileId(fileHistoryIdStr); fileHistory = new PartialFileHistory(fileId);
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; }
public FileVersion createFileVersionFromRow(ResultSet resultSet) throws SQLException { FileVersion fileVersion = new FileVersion(); fileVersion.setFileHistoryId(FileHistoryId.parseFileId(resultSet.getString("filehistory_id"))); fileVersion.setVersion(resultSet.getLong("version")); fileVersion.setPath(resultSet.getString("path")); fileVersion.setType(FileType.valueOf(resultSet.getString("type"))); fileVersion.setStatus(FileStatus.valueOf(resultSet.getString("status"))); fileVersion.setSize(resultSet.getLong("size")); fileVersion.setLastModified(new Date(resultSet.getTimestamp("lastmodified").getTime())); if (resultSet.getString("linktarget") != null) { fileVersion.setLinkTarget(resultSet.getString("linktarget")); } if (resultSet.getString("filecontent_checksum") != null) { FileChecksum fileChecksum = FileChecksum.parseFileChecksum(resultSet.getString("filecontent_checksum")); fileVersion.setChecksum(fileChecksum); } if (resultSet.getString("updated") != null) { fileVersion.setUpdated(new Date(resultSet.getTimestamp("updated").getTime())); } if (resultSet.getString("posixperms") != null) { fileVersion.setPosixPermissions(resultSet.getString("posixperms")); } if (resultSet.getString("dosattrs") != null) { fileVersion.setDosAttributes(resultSet.getString("dosattrs")); } return fileVersion; }
FileHistoryId restoreFileHistory = FileHistoryId.parseFileId(nonOptionArgs.get(0).toString()); operationOptions.setFileHistoryId(restoreFileHistory);
FileHistoryId fileHistoryId = FileHistoryId.parseFileId(concreteRequest.getFileHistoryId()); long version = concreteRequest.getVersion();
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); } } }
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); } }
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); } } }
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); } }
@Override public PartialFileHistory.FileHistoryId read(InputNode node) throws Exception { return PartialFileHistory.FileHistoryId.parseFileId(node.getValue()); }
@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); } }