Package org.syncany.database

Examples of org.syncany.database.ChunkEntry$ChunkChecksum


    newFileVersion.setType(FileType.FILE);

    newFileHistory.addFileVersion(newFileVersion);
    newDatabaseVersion.addFileHistory(newFileHistory);

    ChunkEntry newChunkEntry = new ChunkEntry(ChunkChecksum.parseChunkChecksum("aaaaaaaaaaaaaaaaaaaaab2b263ffa4cc48e282f"), 1);
    newDatabaseVersion.addChunk(newChunkEntry);
   
    MultiChunkEntry newMultiChunkEntry = new MultiChunkEntry(MultiChunkId.parseMultiChunkId("1234567890987654321234567876543456555555"), 10);
    newMultiChunkEntry.addChunk(newChunkEntry.getChecksum());
    newDatabaseVersion.addMultiChunk(newMultiChunkEntry);
   
    FileContent newFileContent = new FileContent();
    newFileContent.setChecksum(FileChecksum.parseFileChecksum("aaaaaaaaaaaaaaaaaaaaab2b263ffa4cc48e282f"));
    newFileContent.setSize(1L);   
    newFileContent.addChunk(newChunkEntry.getChecksum());
    newDatabaseVersion.addFileContent(newFileContent);   
   
    // c. Persist database version
    databaseVersionDao.persistDatabaseVersion(newDatabaseVersion);
   
View Full Code Here


    MemoryDatabase database = new MemoryDatabase();

    // Round 1: Add chunk to new database version, then add database version
    DatabaseVersion databaseVersion1 = TestDatabaseUtil.createDatabaseVersion();

    ChunkEntry chunkA1 = new ChunkEntry(new ChunkChecksum(new byte[] { 1, 2, 3, 4, 5, 7, 8, 9, 0 }), 12);
    databaseVersion1.addChunk(chunkA1);

    database.addDatabaseVersion(databaseVersion1);
    assertEquals(chunkA1, database.getChunk(new ChunkChecksum(new byte[] { 1, 2, 3, 4, 5, 7, 8, 9, 0 })));

    // Round 2: Add chunk to new database version, then add database version
    DatabaseVersion databaseVersion2 = TestDatabaseUtil.createDatabaseVersion(databaseVersion1);

    ChunkEntry chunkA2 = new ChunkEntry(new ChunkChecksum(new byte[] { 9, 8, 7, 6, 5, 4, 3, 2, 1 }), 112);
    databaseVersion2.addChunk(chunkA2);

    database.addDatabaseVersion(databaseVersion2);
    assertEquals(chunkA1, database.getChunk(new ChunkChecksum(new byte[] { 1, 2, 3, 4, 5, 7, 8, 9, 0 })));
    assertEquals(chunkA2, database.getChunk(new ChunkChecksum(new byte[] { 9, 8, 7, 6, 5, 4, 3, 2, 1 })));

    // Round 3: Add chunk to new database version, then add database version
    DatabaseVersion databaseVersion3 = TestDatabaseUtil.createDatabaseVersion(databaseVersion2);

    ChunkEntry chunkA3 = new ChunkEntry(new ChunkChecksum(new byte[] { 1, 1, 1, 1, 1, 1, 1, 1, 1 }), 192);
    databaseVersion3.addChunk(chunkA3);

    database.addDatabaseVersion(databaseVersion3);
    assertEquals(chunkA1, database.getChunk(new ChunkChecksum(new byte[] { 1, 2, 3, 4, 5, 7, 8, 9, 0 })));
    assertEquals(chunkA2, database.getChunk(new ChunkChecksum(new byte[] { 9, 8, 7, 6, 5, 4, 3, 2, 1 })));
View Full Code Here

    // Round 1: Add chunk to multichunk
    DatabaseVersion databaseVersion1 = TestDatabaseUtil.createDatabaseVersion();

    MultiChunkEntry multiChunkP1 = new MultiChunkEntry(new MultiChunkId(new byte[] { 8, 8, 8, 8, 8, 8, 8, 8 }), 10);
    ChunkEntry chunkA1 = new ChunkEntry(new ChunkChecksum(new byte[] { 1, 2, 3, 4, 5, 7, 8, 9, 0 }), 12);

    multiChunkP1.addChunk(chunkA1.getChecksum());
    databaseVersion1.addChunk(chunkA1);
    databaseVersion1.addMultiChunk(multiChunkP1);

    database.addDatabaseVersion(databaseVersion1);

    assertEquals(chunkA1, database.getChunk(new ChunkChecksum(new byte[] { 1, 2, 3, 4, 5, 7, 8, 9, 0 })));
    assertEquals(multiChunkP1, database.getMultiChunk(new MultiChunkId(new byte[] { 8, 8, 8, 8, 8, 8, 8, 8 })));

    // Round 2: Add chunk to multichunk
    DatabaseVersion databaseVersion2 = TestDatabaseUtil.createDatabaseVersion(databaseVersion1);

    MultiChunkEntry multiChunkP2 = new MultiChunkEntry(new MultiChunkId(new byte[] { 7, 7, 7, 7, 7, 7, 7, 7, 7 }), 11);
    MultiChunkEntry multiChunkP3 = new MultiChunkEntry(new MultiChunkId(new byte[] { 5, 5, 5, 5, 5, 5, 5, 5, 5 }), 12);

    ChunkEntry chunkA2 = new ChunkEntry(new ChunkChecksum(new byte[] { 9, 2, 3, 4, 5, 7, 8, 9, 0 }), 912);
    ChunkEntry chunkA3 = new ChunkEntry(new ChunkChecksum(new byte[] { 8, 2, 3, 4, 5, 7, 8, 9, 0 }), 812);
    ChunkEntry chunkA4 = new ChunkEntry(new ChunkChecksum(new byte[] { 7, 2, 3, 4, 5, 7, 8, 9, 0 }), 712);

    multiChunkP2.addChunk(chunkA2.getChecksum());
    multiChunkP2.addChunk(chunkA3.getChecksum());
    multiChunkP3.addChunk(chunkA4.getChecksum());

    databaseVersion2.addChunk(chunkA2);
    databaseVersion2.addChunk(chunkA3);
    databaseVersion2.addChunk(chunkA4);
View Full Code Here

    // Run
    TestSqlUtil.runSqlFromResource(databaseConnection, "test.insert.set3.sql");
   
    ChunkSqlDao chunkDao = new ChunkSqlDao(databaseConnection);
   
    ChunkEntry chunk1 = chunkDao.getChunk(ChunkChecksum.parseChunkChecksum("615fba8c2281d5bee891eb092a252d235c237457"));
    ChunkEntry chunk2 = chunkDao.getChunk(ChunkChecksum.parseChunkChecksum("ab85720d3f31bd08ca1cd25dcd8a490e5f00783b"));
    ChunkEntry chunkNonExistent = chunkDao.getChunk(ChunkChecksum.parseChunkChecksum("beefbeefbeefbeefbeefbeefbeefbeefbeefbeef"));
   
    // Test
    assertNotNull(chunk1);
    assertEquals("615fba8c2281d5bee891eb092a252d235c237457", chunk1.getChecksum().toString());
    assertEquals(8387, chunk1.getSize());
View Full Code Here

        chunkEntry = newDatabaseVersion.getChunk(chunkChecksum);

        if (chunkEntry == null) {
          logger.log(Level.FINER, "- Chunk new: {0}", chunkChecksum.toString());

          chunkEntry = new ChunkEntry(chunkChecksum, chunk.getSize());
          newDatabaseVersion.addChunk(chunkEntry);

          return true;
        }
      }
View Full Code Here

  protected Map<ChunkChecksum, ChunkEntry> createChunkEntries(ResultSet resultSet) throws SQLException {
    Map<ChunkChecksum, ChunkEntry> chunks = new HashMap<ChunkChecksum, ChunkEntry>();

    while (resultSet.next()) {
      ChunkEntry chunkEntry = createChunkEntryFromRow(resultSet);
      chunks.put(chunkEntry.getChecksum(), chunkEntry);
    }

    return chunks;
  }
View Full Code Here

    return chunks;
  }

  protected ChunkEntry createChunkEntryFromRow(ResultSet resultSet) throws SQLException {
    ChunkChecksum chunkChecksum = ChunkChecksum.parseChunkChecksum(resultSet.getString("checksum"));
    return new ChunkEntry(chunkChecksum, resultSet.getInt("size"));
  }
View Full Code Here

      if (elementPath.equalsIgnoreCase("/database/databaseVersions/databaseVersion/chunks/chunk")) {
        String chunkChecksumStr = attributes.getValue("checksum");
        ChunkChecksum chunkChecksum = ChunkChecksum.parseChunkChecksum(chunkChecksumStr);
        int chunkSize = Integer.parseInt(attributes.getValue("size"));

        ChunkEntry chunkEntry = new ChunkEntry(chunkChecksum, chunkSize);
        databaseVersion.addChunk(chunkEntry);
      }
      else if (elementPath.equalsIgnoreCase("/database/databaseVersions/databaseVersion/fileContents/fileContent")) {
        String checksumStr = attributes.getValue("checksum");
        long size = Long.parseLong(attributes.getValue("size"));
View Full Code Here

TOP

Related Classes of org.syncany.database.ChunkEntry$ChunkChecksum

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.