Search in sources :

Example 16 with DatabaseVersionHeader

use of org.syncany.database.DatabaseVersionHeader in project syncany by syncany.

the class DatabaseVersionSqlDao method createDatabaseVersionFromRow.

protected DatabaseVersion createDatabaseVersionFromRow(ResultSet resultSet, boolean excludeChunkData, int fileHistoryMaxCount) throws SQLException {
    DatabaseVersionHeader databaseVersionHeader = createDatabaseVersionHeaderFromRow(resultSet);
    DatabaseVersion databaseVersion = new DatabaseVersion();
    databaseVersion.setHeader(databaseVersionHeader);
    // Add chunk/multichunk/filecontent data
    if (!excludeChunkData) {
        Map<ChunkChecksum, ChunkEntry> chunks = chunkDao.getChunks(databaseVersionHeader.getVectorClock());
        Map<MultiChunkId, MultiChunkEntry> multiChunks = multiChunkDao.getMultiChunks(databaseVersionHeader.getVectorClock());
        Map<FileChecksum, FileContent> fileContents = fileContentDao.getFileContents(databaseVersionHeader.getVectorClock());
        for (ChunkEntry chunk : chunks.values()) {
            databaseVersion.addChunk(chunk);
        }
        for (MultiChunkEntry multiChunk : multiChunks.values()) {
            databaseVersion.addMultiChunk(multiChunk);
        }
        for (FileContent fileContent : fileContents.values()) {
            databaseVersion.addFileContent(fileContent);
        }
    }
    // Add file histories
    Map<FileHistoryId, PartialFileHistory> fileHistories = fileHistoryDao.getFileHistoriesWithFileVersions(databaseVersionHeader.getVectorClock(), fileHistoryMaxCount);
    for (PartialFileHistory fileHistory : fileHistories.values()) {
        databaseVersion.addFileHistory(fileHistory);
    }
    return databaseVersion;
}
Also used : FileHistoryId(org.syncany.database.PartialFileHistory.FileHistoryId) MultiChunkId(org.syncany.database.MultiChunkEntry.MultiChunkId) ChunkChecksum(org.syncany.database.ChunkEntry.ChunkChecksum) FileChecksum(org.syncany.database.FileContent.FileChecksum) PartialFileHistory(org.syncany.database.PartialFileHistory) FileContent(org.syncany.database.FileContent) ChunkEntry(org.syncany.database.ChunkEntry) MultiChunkEntry(org.syncany.database.MultiChunkEntry) DatabaseVersionHeader(org.syncany.database.DatabaseVersionHeader) MultiChunkEntry(org.syncany.database.MultiChunkEntry) DatabaseVersion(org.syncany.database.DatabaseVersion)

Example 17 with DatabaseVersionHeader

use of org.syncany.database.DatabaseVersionHeader in project syncany by syncany.

the class DatabaseVersionSqlDao method getNonEmptyDatabaseVersionHeaders.

public List<DatabaseVersionHeader> getNonEmptyDatabaseVersionHeaders() {
    List<DatabaseVersionHeader> databaseVersionHeaders = new ArrayList<>();
    try (PreparedStatement preparedStatement = getStatement("databaseversion.select.master.getNonEmptyDatabaseVersionHeaders.sql")) {
        try (ResultSet resultSet = preparedStatement.executeQuery()) {
            while (resultSet.next()) {
                DatabaseVersionHeader databaseVersionHeader = createDatabaseVersionHeaderFromRow(resultSet);
                databaseVersionHeaders.add(databaseVersionHeader);
            }
        }
        return databaseVersionHeaders;
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DatabaseVersionHeader(org.syncany.database.DatabaseVersionHeader)

Example 18 with DatabaseVersionHeader

use of org.syncany.database.DatabaseVersionHeader in project syncany by syncany.

the class TestDatabaseUtil method createBranch.

public static DatabaseBranch createBranch(String[] databaseVersionHeaderStrings) throws Exception {
    DatabaseBranch branch = new DatabaseBranch();
    for (String databaseVersionHeaderString : databaseVersionHeaderStrings) {
        DatabaseVersionHeader databaseVersionHeader = createFromString(databaseVersionHeaderString);
        branch.add(databaseVersionHeader);
    }
    return branch;
}
Also used : DatabaseBranch(org.syncany.operations.down.DatabaseBranch) DatabaseVersionHeader(org.syncany.database.DatabaseVersionHeader)

Example 19 with DatabaseVersionHeader

use of org.syncany.database.DatabaseVersionHeader in project syncany by syncany.

the class TestDatabaseUtil method createFromString.

public static DatabaseVersionHeader createFromString(String databaseVersionHeaderString) throws Exception {
    Matcher databaseVersionHeaderMatcher = databaseVersionHeaderPattern.matcher(databaseVersionHeaderString);
    if (!databaseVersionHeaderMatcher.matches()) {
        throw new Exception("Invalid database version header string: " + databaseVersionHeaderString);
    }
    String client = databaseVersionHeaderMatcher.group(1);
    String vectorClockString = databaseVersionHeaderMatcher.group(2);
    long databaseVersionHeaderTime = Long.parseLong(databaseVersionHeaderMatcher.group(3));
    VectorClock vectorClock = createVectorClock(vectorClockString);
    DatabaseVersionHeader newDatabaseVersionHeader = new DatabaseVersionHeader();
    newDatabaseVersionHeader.setDate(new Date(databaseVersionHeaderTime));
    newDatabaseVersionHeader.setVectorClock(vectorClock);
    newDatabaseVersionHeader.setClient(client);
    return newDatabaseVersionHeader;
}
Also used : Matcher(java.util.regex.Matcher) VectorClock(org.syncany.database.VectorClock) DatabaseVersionHeader(org.syncany.database.DatabaseVersionHeader) IOException(java.io.IOException) Date(java.util.Date)

Example 20 with DatabaseVersionHeader

use of org.syncany.database.DatabaseVersionHeader in project syncany by syncany.

the class DatabaseVersionSqlDao method createDatabaseVersionHeaderFromRow.

private DatabaseVersionHeader createDatabaseVersionHeaderFromRow(ResultSet resultSet) throws SQLException {
    DatabaseVersionHeader databaseVersionHeader = new DatabaseVersionHeader();
    databaseVersionHeader.setClient(resultSet.getString("client"));
    databaseVersionHeader.setDate(new Date(resultSet.getTimestamp("localtime").getTime()));
    databaseVersionHeader.setVectorClock(getVectorClockByDatabaseVersionId(resultSet.getInt("id")));
    return databaseVersionHeader;
}
Also used : DatabaseVersionHeader(org.syncany.database.DatabaseVersionHeader) Date(java.util.Date)

Aggregations

DatabaseVersionHeader (org.syncany.database.DatabaseVersionHeader)33 Test (org.junit.Test)17 DatabaseBranches (org.syncany.operations.down.DatabaseBranches)14 File (java.io.File)4 Date (java.util.Date)4 VectorClock (org.syncany.database.VectorClock)4 PreparedStatement (java.sql.PreparedStatement)3 DatabaseVersion (org.syncany.database.DatabaseVersion)3 MultiChunkEntry (org.syncany.database.MultiChunkEntry)3 DatabaseBranch (org.syncany.operations.down.DatabaseBranch)3 DatabaseRemoteFile (org.syncany.plugins.transfer.files.DatabaseRemoteFile)3 IOException (java.io.IOException)2 Connection (java.sql.Connection)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 Config (org.syncany.config.Config)2 ChunkEntry (org.syncany.database.ChunkEntry)2 FileContent (org.syncany.database.FileContent)2 MemoryDatabase (org.syncany.database.MemoryDatabase)2 MultiChunkId (org.syncany.database.MultiChunkEntry.MultiChunkId)2