use of org.syncany.database.MultiChunkEntry in project syncany by syncany.
the class MultiChunkSqlDao method createMultiChunkEntriesWithoutChunks.
private Map<MultiChunkId, MultiChunkEntry> createMultiChunkEntriesWithoutChunks(ResultSet resultSet) throws SQLException {
Map<MultiChunkId, MultiChunkEntry> unusedMultiChunkIds = new HashMap<MultiChunkId, MultiChunkEntry>();
while (resultSet.next()) {
MultiChunkId multiChunkId = MultiChunkId.parseMultiChunkId(resultSet.getString("id"));
long multiChunkSize = resultSet.getLong("size");
unusedMultiChunkIds.put(multiChunkId, new MultiChunkEntry(multiChunkId, multiChunkSize));
}
return unusedMultiChunkIds;
}
use of org.syncany.database.MultiChunkEntry in project syncany by syncany.
the class MultiChunkSqlDao method writeMultiChunks.
public void writeMultiChunks(Connection connection, long databaseVersionId, Collection<MultiChunkEntry> multiChunks) throws SQLException {
for (MultiChunkEntry multiChunk : multiChunks) {
PreparedStatement preparedStatement = getStatement(connection, "multichunk.insert.all.writeMultiChunks.sql");
preparedStatement.setString(1, multiChunk.getId().toString());
preparedStatement.setLong(2, databaseVersionId);
preparedStatement.setLong(3, multiChunk.getSize());
preparedStatement.executeUpdate();
preparedStatement.close();
writeMultiChunkRefs(connection, multiChunk);
}
}
use of org.syncany.database.MultiChunkEntry in project syncany by syncany.
the class MultiChunkSqlDao method writeMuddyMultiChunks.
public void writeMuddyMultiChunks(Map<DatabaseVersionHeader, Collection<MultiChunkEntry>> muddyMultiChunksPerDatabaseVersion) throws SQLException {
PreparedStatement preparedStatement = getStatement("multichunk_muddy.insert.muddy.writeMuddyMultiChunks.sql");
for (DatabaseVersionHeader muddyDatabaseVersionHeader : muddyMultiChunksPerDatabaseVersion.keySet()) {
Collection<MultiChunkEntry> muddyMultiChunks = muddyMultiChunksPerDatabaseVersion.get(muddyDatabaseVersionHeader);
for (MultiChunkEntry muddyMultiChunk : muddyMultiChunks) {
String multiChunkIdStr = muddyMultiChunk.getId().toString();
String clientName = muddyDatabaseVersionHeader.getClient();
Long clientVersion = muddyDatabaseVersionHeader.getVectorClock().getClock(clientName);
preparedStatement.setString(1, multiChunkIdStr);
preparedStatement.setString(2, clientName);
preparedStatement.setLong(3, clientVersion);
preparedStatement.addBatch();
}
}
preparedStatement.executeBatch();
preparedStatement.close();
}
use of org.syncany.database.MultiChunkEntry in project syncany by syncany.
the class DatabaseVersionDaoTest method testRemoveDirtyDatabaseVersions.
@Test
public void testRemoveDirtyDatabaseVersions() throws Exception {
// Setup
Config testConfig = TestConfigUtil.createTestLocalConfig();
Connection databaseConnection = testConfig.createDatabaseConnection();
// Run
TestSqlUtil.runSqlFromResource(databaseConnection, "test.insert.set1.sql");
ChunkSqlDao chunkDao = new ChunkSqlDao(databaseConnection);
MultiChunkSqlDao multiChunkDao = new MultiChunkSqlDao(databaseConnection);
FileVersionSqlDao fileVersionDao = new FileVersionSqlDao(databaseConnection);
FileHistorySqlDao fileHistoryDao = new FileHistorySqlDao(databaseConnection, fileVersionDao);
FileContentSqlDao fileContentDao = new FileContentSqlDao(databaseConnection);
DatabaseVersionSqlDao databaseVersionDao = new DatabaseVersionSqlDao(databaseConnection, chunkDao, fileContentDao, fileVersionDao, fileHistoryDao, multiChunkDao);
// a. Test before
List<DatabaseVersion> dirtyDatabaseVersionsBefore = TestCollectionUtil.toList(databaseVersionDao.getDirtyDatabaseVersions());
assertNotNull(dirtyDatabaseVersionsBefore);
assertNotNull(chunkDao.getChunk(ChunkChecksum.parseChunkChecksum("beefbeefbeefbeefbeefbeefbeefbeefbeefbeef")));
assertNotNull(multiChunkDao.getDirtyMultiChunkIds());
assertEquals(1, multiChunkDao.getDirtyMultiChunkIds().size());
// b. Add new database version with DIRTY multichunk; remove DIRTY version
DatabaseVersion newDatabaseVersion = new DatabaseVersion();
newDatabaseVersion.setVectorClock(TestDatabaseUtil.createVectorClock("A5,B2"));
long newDatabaseVersionId = databaseVersionDao.writeDatabaseVersion(newDatabaseVersion);
databaseVersionDao.removeDirtyDatabaseVersions(newDatabaseVersionId);
// c. Test after
// Database version
List<DatabaseVersion> dirtyDatabaseVersionsAfter = TestCollectionUtil.toList(databaseVersionDao.getDirtyDatabaseVersions());
assertNotNull(dirtyDatabaseVersionsAfter);
assertEquals(0, dirtyDatabaseVersionsAfter.size());
// Multichunk from dirty version "moved" to new version
Map<MultiChunkId, MultiChunkEntry> multiChunksA5B2 = multiChunkDao.getMultiChunks(TestDatabaseUtil.createVectorClock("A5,B2"));
assertNotNull(multiChunksA5B2);
assertEquals(1, multiChunksA5B2.size());
assertNotNull(multiChunksA5B2.get(MultiChunkId.parseMultiChunkId("1234567890987654321123456789098765433222")));
// File version/history/content ARE removed
assertNull(fileContentDao.getFileContent(FileChecksum.parseFileChecksum("beefbeefbeefbeefbeefbeefbeefbeefbeefbeef"), true));
// TODO [low] Test file version and file history removal
// Chunks and multichunks are NOT removed!
assertNotNull(chunkDao.getChunk(ChunkChecksum.parseChunkChecksum("beefbeefbeefbeefbeefbeefbeefbeefbeefbeef")));
assertNotNull(multiChunkDao.getMultiChunks(TestDatabaseUtil.createVectorClock("B1")));
assertEquals(0, multiChunkDao.getMultiChunks(TestDatabaseUtil.createVectorClock("B1")).size());
assertNotNull(multiChunkDao.getDirtyMultiChunkIds());
assertEquals(0, multiChunkDao.getDirtyMultiChunkIds().size());
// Tear down
databaseConnection.close();
TestConfigUtil.deleteTestLocalConfigAndData(testConfig);
}
use of org.syncany.database.MultiChunkEntry in project syncany by syncany.
the class MultiChunkDaoTest method testGetMultiChunksByDatabaseVersion1.
@Test
public void testGetMultiChunksByDatabaseVersion1() throws Exception {
// Setup
Config testConfig = TestConfigUtil.createTestLocalConfig();
Connection databaseConnection = testConfig.createDatabaseConnection();
// Run
TestSqlUtil.runSqlFromResource(databaseConnection, "test.insert.set3.sql");
MultiChunkSqlDao multiChunkDao = new MultiChunkSqlDao(databaseConnection);
Map<MultiChunkId, MultiChunkEntry> multiChunksA6 = multiChunkDao.getMultiChunks(TestDatabaseUtil.createVectorClock("A6"));
Map<MultiChunkId, MultiChunkEntry> multiChunksA7B2 = multiChunkDao.getMultiChunks(TestDatabaseUtil.createVectorClock("A7,B2"));
// Test
// - Database version "A6"
assertNotNull(multiChunksA6);
assertEquals(1, multiChunksA6.size());
MultiChunkEntry multiChunkInA6 = multiChunksA6.get(MultiChunkId.parseMultiChunkId("9302d8b104023627f655fa7745927fdeb3df674b"));
assertNotNull(multiChunkInA6);
assertEquals("9302d8b104023627f655fa7745927fdeb3df674b", multiChunkInA6.getId().toString());
assertTrue(CollectionUtil.containsExactly(multiChunkInA6.getChunks(), ChunkChecksum.parseChunkChecksum("24a39e00d6156804e27f7c0987d00903da8e6682")));
// - Database version "A8,B3"
assertNotNull(multiChunksA7B2);
assertEquals(1, multiChunksA7B2.size());
MultiChunkEntry multiChunkInA7B2 = multiChunksA7B2.get(MultiChunkId.parseMultiChunkId("51aaca5c1280b1cf95cff8a3266a6bb44b482ad4"));
assertEquals("51aaca5c1280b1cf95cff8a3266a6bb44b482ad4", multiChunkInA7B2.getId().toString());
assertTrue(CollectionUtil.containsExactly(multiChunkInA7B2.getChunks(), ChunkChecksum.parseChunkChecksum("0fecbac8ac8a5f8b7aa12b2741a4ef5db88c5dea"), ChunkChecksum.parseChunkChecksum("38a18897e94a901b833e750e8604d9616a02ca84"), ChunkChecksum.parseChunkChecksum("47dded182d31799267f12eb9864cdc11127b3352"), ChunkChecksum.parseChunkChecksum("5abe80d7dd96369a3e53993cd69279400ec740bd"), ChunkChecksum.parseChunkChecksum("5f0b34374821423f69bf2231210245ccf0302df0"), ChunkChecksum.parseChunkChecksum("615fba8c2281d5bee891eb092a252d235c237457"), ChunkChecksum.parseChunkChecksum("8ed8d50a6e9da3197bd665bc3a1f229ebcde9b42"), ChunkChecksum.parseChunkChecksum("9974b55a79994b4bfe007983539ca21b2679ba35"), ChunkChecksum.parseChunkChecksum("a301a81d5a4f427d04791b89bfd7798eda6bd013"), ChunkChecksum.parseChunkChecksum("a7405a0bada0035ed52a1a44a4d381b78dc59d19"), ChunkChecksum.parseChunkChecksum("ab85720d3f31bd08ca1cd25dcd8a490e5f00783b"), ChunkChecksum.parseChunkChecksum("b0223d9770a5c0d7e22ac3d2706c4c9858cf42a9"), ChunkChecksum.parseChunkChecksum("b310c0eedcd03238888c6abb3e3398633139ecc5"), ChunkChecksum.parseChunkChecksum("f15eace568ea3c324ecd3d01b67e692bbf8a2f1b")));
// Tear down
databaseConnection.close();
TestConfigUtil.deleteTestLocalConfigAndData(testConfig);
}
Aggregations