use of org.syncany.database.FileVersion 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.FileVersion in project syncany by syncany.
the class FileVersionSqlDao method createFileVersionFromRow.
// TODO [low] This should be private; but it has to be public for a test
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;
}
use of org.syncany.database.FileVersion 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.FileVersion in project syncany by syncany.
the class DatabaseXmlWriter method writeFileHistories.
private void writeFileHistories(IndentXmlStreamWriter xmlOut, Collection<PartialFileHistory> fileHistories) throws XMLStreamException, IOException {
xmlOut.writeStartElement("fileHistories");
for (PartialFileHistory fileHistory : fileHistories) {
xmlOut.writeStartElement("fileHistory");
xmlOut.writeAttribute("id", fileHistory.getFileHistoryId().toString());
xmlOut.writeStartElement("fileVersions");
Collection<FileVersion> fileVersions = fileHistory.getFileVersions().values();
for (FileVersion fileVersion : fileVersions) {
if (fileVersion.getVersion() == null || fileVersion.getType() == null || fileVersion.getPath() == null || fileVersion.getStatus() == null || fileVersion.getSize() == null || fileVersion.getLastModified() == null) {
throw new IOException("Unable to write file version, because one or many mandatory fields are null (version, type, path, name, status, size, last modified): " + fileVersion);
}
if (fileVersion.getType() == FileType.SYMLINK && fileVersion.getLinkTarget() == null) {
throw new IOException("Unable to write file version: All symlinks must have a target.");
}
xmlOut.writeEmptyElement("fileVersion");
xmlOut.writeAttribute("version", fileVersion.getVersion());
xmlOut.writeAttribute("type", fileVersion.getType().toString());
xmlOut.writeAttribute("status", fileVersion.getStatus().toString());
if (containsXmlRestrictedChars(fileVersion.getPath())) {
xmlOut.writeAttribute("pathEncoded", encodeXmlRestrictedChars(fileVersion.getPath()));
} else {
xmlOut.writeAttribute("path", fileVersion.getPath());
}
xmlOut.writeAttribute("size", fileVersion.getSize());
xmlOut.writeAttribute("lastModified", fileVersion.getLastModified().getTime());
if (fileVersion.getLinkTarget() != null) {
xmlOut.writeAttribute("linkTarget", fileVersion.getLinkTarget());
}
if (fileVersion.getUpdated() != null) {
xmlOut.writeAttribute("updated", fileVersion.getUpdated().getTime());
}
if (fileVersion.getChecksum() != null) {
xmlOut.writeAttribute("checksum", fileVersion.getChecksum().toString());
}
if (fileVersion.getDosAttributes() != null) {
xmlOut.writeAttribute("dosattrs", fileVersion.getDosAttributes());
}
if (fileVersion.getPosixPermissions() != null) {
xmlOut.writeAttribute("posixperms", fileVersion.getPosixPermissions());
}
}
// </fileVersions>
xmlOut.writeEndElement();
// </fileHistory>
xmlOut.writeEndElement();
}
// </fileHistories>
xmlOut.writeEndElement();
}
use of org.syncany.database.FileVersion in project syncany by syncany.
the class FileSystemActionComparatorTest method createDeleteFileSystemAction.
private DeleteFileSystemAction createDeleteFileSystemAction(String path, FileType type) throws Exception {
FileVersion firstFileVersion = createFileVersion(path, type);
FileVersion secondFileVersion = createFileVersion(path, type, firstFileVersion);
return new DeleteFileSystemAction(createDummyConfig(), firstFileVersion, secondFileVersion, null);
}
Aggregations