use of org.syncany.database.FileVersion in project syncany by syncany.
the class FileVersionSqlDao method getFileHistory.
public List<FileVersion> getFileHistory(FileHistoryId fileHistoryId) {
try (PreparedStatement preparedStatement = getStatement("fileversion.select.master.getFileHistoryById.sql")) {
preparedStatement.setString(1, fileHistoryId.toString());
List<FileVersion> fileTree = new ArrayList<FileVersion>();
try (ResultSet resultSet = preparedStatement.executeQuery()) {
while (resultSet.next()) {
FileVersion fileVersion = createFileVersionFromRow(resultSet);
fileTree.add(fileVersion);
}
return fileTree;
} catch (SQLException e) {
throw new RuntimeException(e);
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
use of org.syncany.database.FileVersion in project syncany by syncany.
the class FileVersionSqlDao method getCurrentFileTree.
/**
* Queries the database for the currently active {@link FileVersion}s and returns it
* as a map. If the current file tree (on the disk) has not changed, the result will
* match the files on the disk.
*
* <p>Keys in the returned map correspond to the file version's relative file path,
* and values to the actual {@link FileVersion} object.
*
* @return Returns the current file tree as a map of relative paths to {@link FileVersion} objects
*/
public Map<String, FileVersion> getCurrentFileTree() {
try (PreparedStatement preparedStatement = getStatement("fileversion.select.master.getCurrentFileTree.sql")) {
Map<String, FileVersion> fileTree = new TreeMap<>();
List<FileVersion> fileList = getFileTree(preparedStatement);
for (FileVersion fileVersion : fileList) {
fileTree.put(fileVersion.getPath(), fileVersion);
}
return fileTree;
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
use of org.syncany.database.FileVersion in project syncany by syncany.
the class FileVersionSqlDao method writeFileVersions.
/**
* Writes a list of {@link FileVersion} to the database table <i>fileversion</i> using <tt>INSERT</tt>s
* and the given connection.
*
* <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 fileHistoryId References the {@link PartialFileHistory} to which the list of file versions belongs
* @param databaseVersionId References the {@link PartialFileHistory} to which the list of file versions belongs
* @param fileVersions List of {@link FileVersion}s to be written to the database
* @throws SQLException If the SQL statement fails
*/
public void writeFileVersions(Connection connection, FileHistoryId fileHistoryId, long databaseVersionId, Collection<FileVersion> fileVersions) throws SQLException {
PreparedStatement preparedStatement = getStatement(connection, "fileversion.insert.writeFileVersions.sql");
for (FileVersion fileVersion : fileVersions) {
String fileContentChecksumStr = (fileVersion.getChecksum() != null) ? fileVersion.getChecksum().toString() : null;
preparedStatement.setString(1, fileHistoryId.toString());
preparedStatement.setInt(2, Integer.parseInt("" + fileVersion.getVersion()));
preparedStatement.setLong(3, databaseVersionId);
preparedStatement.setString(4, fileVersion.getPath());
preparedStatement.setString(5, fileVersion.getType().toString());
preparedStatement.setString(6, fileVersion.getStatus().toString());
preparedStatement.setLong(7, fileVersion.getSize());
preparedStatement.setTimestamp(8, new Timestamp(fileVersion.getLastModified().getTime()));
preparedStatement.setString(9, fileVersion.getLinkTarget());
preparedStatement.setString(10, fileContentChecksumStr);
preparedStatement.setTimestamp(11, new Timestamp(fileVersion.getUpdated().getTime()));
preparedStatement.setString(12, fileVersion.getPosixPermissions());
preparedStatement.setString(13, fileVersion.getDosAttributes());
preparedStatement.addBatch();
}
preparedStatement.executeBatch();
preparedStatement.close();
}
use of org.syncany.database.FileVersion in project syncany by syncany.
the class FileVersionSqlDao method getSingleVersionInHistory.
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;
}
}
use of org.syncany.database.FileVersion in project syncany by syncany.
the class FileVersionSqlDao method getFileTree.
private List<FileVersion> getFileTree(PreparedStatement preparedStatement) {
List<FileVersion> fileTree = new ArrayList<>();
try (ResultSet resultSet = preparedStatement.executeQuery()) {
while (resultSet.next()) {
FileVersion fileVersion = createFileVersionFromRow(resultSet);
fileTree.add(fileVersion);
}
return fileTree;
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
Aggregations