Package org.syncany.database

Examples of org.syncany.database.DatabaseVersionHeader


      TreeMap<String, DatabaseVersionHeader> winningFirstConflictingDatabaseVersionHeaders, DatabaseBranches allDatabaseVersionHeaders) {
   
    Map<String, Integer> machineBranchPositionIterator = new HashMap<String, Integer>();

    for (String machineName : winningFirstConflictingDatabaseVersionHeaders.keySet()) {
      DatabaseVersionHeader machineFirstConflictingDatabaseVersionHeader = winningFirstConflictingDatabaseVersionHeaders.get(machineName);
      DatabaseBranch machineBranch = allDatabaseVersionHeaders.getBranch(machineName);

      for (int i = 0; i < machineBranch.size(); i++) {
        DatabaseVersionHeader machineDatabaseVersionHeader = machineBranch.get(i);

        if (machineFirstConflictingDatabaseVersionHeader.equals(machineDatabaseVersionHeader)) {
          machineBranchPositionIterator.put(machineName, i);
          break;
        }
View Full Code Here


    List<DatabaseRemoteFile> unknownRemoteDatabases = new ArrayList<DatabaseRemoteFile>();

    // List all remote database files
    Map<String, DatabaseRemoteFile> remoteDatabaseFiles = transferManager.list(DatabaseRemoteFile.class);

    DatabaseVersionHeader lastLocalDatabaseVersionHeader = localDatabase.getLastDatabaseVersionHeader();

    // No local database yet
    if (lastLocalDatabaseVersionHeader == null) {
      logger.log(Level.INFO, "- No local database versions yet. Assuming all {0} remote database files are unknown. ",
          remoteDatabaseFiles.size());
     
      return new ArrayList<DatabaseRemoteFile>(remoteDatabaseFiles.values());
    }

    // At least one local database version exists
    else {
      VectorClock knownDatabaseVersions = lastLocalDatabaseVersionHeader.getVectorClock();

      for (DatabaseRemoteFile remoteDatabaseFile : remoteDatabaseFiles.values()) {
        String clientName = remoteDatabaseFile.getClientName();
        Long knownClientVersion = knownDatabaseVersions.getClock(clientName);
View Full Code Here

    remoteTransaction.upload(localDatabaseFile, remoteDatabaseFile);
  }

  private DatabaseVersion index(List<File> localFiles) throws FileNotFoundException, IOException {
    // Get last vector clock
    DatabaseVersionHeader lastDatabaseVersionHeader = localDatabase.getLastDatabaseVersionHeader();
    VectorClock lastVectorClock = (lastDatabaseVersionHeader != null) ? lastDatabaseVersionHeader.getVectorClock() : new VectorClock();

    // New vector clock
    VectorClock newVectorClock = findNewVectorClock(lastVectorClock);

    // Index
View Full Code Here

      // Populate branches
      DatabaseBranch remoteClientBranch = unknownRemoteBranches.getBranch(remoteDatabaseFile.getClientName(), true);

      for (DatabaseVersion remoteDatabaseVersion : remoteDatabaseVersions) {
        DatabaseVersionHeader header = remoteDatabaseVersion.getHeader();
        remoteClientBranch.add(header);
      }
    }

    return unknownRemoteBranches;
View Full Code Here

    String rangeClientName = null;
    VectorClock rangeVersionFrom = null;
    VectorClock rangeVersionTo = null;

    for (int i=0; i<winnersApplyBranchList.size(); i++) {
      DatabaseVersionHeader currentDatabaseVersionHeader = winnersApplyBranchList.get(i);
      DatabaseVersionHeader nextDatabaseVersionHeader = (i+1 < winnersApplyBranchList.size()) ? winnersApplyBranchList.get(i+1) : null;
     
      // First of range for this client
      if (rangeClientName == null) {
        rangeClientName = currentDatabaseVersionHeader.getClient();
        rangeVersionFrom = currentDatabaseVersionHeader.getVectorClock();
        rangeVersionTo = currentDatabaseVersionHeader.getVectorClock();
      }
     
      // Still in range for this client
      else {
        rangeVersionTo = currentDatabaseVersionHeader.getVectorClock();
      }
     
      // Now load this stuff from the database file (or not)
      //   - If the database file exists, load the range and reset it
      //   - If not, only force a load if this is the range end
     
      File databaseVersionFile = databaseFileList.getExactDatabaseVersionFile(currentDatabaseVersionHeader);
           
      if (databaseVersionFile != null) {
        databaseSerializer.load(winnerBranchDatabase, databaseVersionFile, rangeVersionFrom, rangeVersionTo, DatabaseReadType.FULL, filterType, ignoredMostRecentPurgeVersions);       
        rangeClientName = null;
      }
      else {
        boolean lastDatabaseVersionHeader = nextDatabaseVersionHeader == null;
        boolean nextClientIsDifferent = !lastDatabaseVersionHeader && !currentDatabaseVersionHeader.getClient().equals(nextDatabaseVersionHeader.getClient());
        boolean rangeEnds = lastDatabaseVersionHeader || nextClientIsDifferent;

        if (rangeEnds) {
          databaseVersionFile = databaseFileList.getNextDatabaseVersionFile(currentDatabaseVersionHeader);
         
View Full Code Here

    logger.log(Level.INFO, "- Uploading PURGE database file " + newPurgeRemoteFile + " ...");
    remoteTransaction.upload(tempPurgeFile, newPurgeRemoteFile);
  }

  private DatabaseVersion createPurgeDatabaseVersion(Map<FileHistoryId, FileVersion> mostRecentPurgeFileVersions) {
    DatabaseVersionHeader lastDatabaseVersionHeader = localDatabase.getLastDatabaseVersionHeader();
    VectorClock lastVectorClock = lastDatabaseVersionHeader.getVectorClock();

    VectorClock purgeVectorClock = lastVectorClock.clone();
    purgeVectorClock.incrementClock(config.getMachineName());

    DatabaseVersionHeader purgeDatabaseVersionHeader = new DatabaseVersionHeader();
    purgeDatabaseVersionHeader.setType(DatabaseVersionType.PURGE);
    purgeDatabaseVersionHeader.setDate(new Date());
    purgeDatabaseVersionHeader.setClient(config.getMachineName());
    purgeDatabaseVersionHeader.setVectorClock(purgeVectorClock);

    DatabaseVersion purgeDatabaseVersion = new DatabaseVersion();
    purgeDatabaseVersion.setHeader(purgeDatabaseVersionHeader);

    for (Entry<FileHistoryId, FileVersion> fileHistoryEntry : mostRecentPurgeFileVersions.entrySet()) {
View Full Code Here

    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;
View Full Code Here

    }

  }

  protected DatabaseVersion createDatabaseVersionFromRow(ResultSet resultSet) throws SQLException {
    DatabaseVersionHeader databaseVersionHeader = createDatabaseVersionHeaderFromRow(resultSet);
   
    if (databaseVersionHeader.getType() == DatabaseVersionType.DEFAULT) {
      return createDatabaseVersionFromRowDefault(databaseVersionHeader, resultSet);
    }
    else if (databaseVersionHeader.getType() == DatabaseVersionType.PURGE) {
      return createDatabaseVersionFromRowPurge(databaseVersionHeader, resultSet);
    }
    else {
      throw new RuntimeException("Unexpected database version type: " + databaseVersionHeader.getType());
    }     
  }
View Full Code Here

    try (PreparedStatement preparedStatement = getStatement("databaseversion.select.master.getLastDatabaseVersionHeader.sql")) {
      preparedStatement.setMaxRows(1);

      try (ResultSet resultSet = preparedStatement.executeQuery()) {
        if (resultSet.next()) {
          DatabaseVersionHeader databaseVersionHeader = createDatabaseVersionHeaderFromRow(resultSet);
          return databaseVersionHeader;
        }
      }

      return null;
View Full Code Here

      throw new RuntimeException(e);
    }
  }

  private DatabaseVersionHeader createDatabaseVersionHeaderFromRow(ResultSet resultSet) throws SQLException {
    DatabaseVersionHeader databaseVersionHeader = new DatabaseVersionHeader();

    databaseVersionHeader.setType(DatabaseVersionType.valueOf(resultSet.getString("type")));
    databaseVersionHeader.setClient(resultSet.getString("client"));
    databaseVersionHeader.setDate(new Date(resultSet.getTimestamp("localtime").getTime()));
    databaseVersionHeader.setVectorClock(getVectorClockByDatabaseVersionId(resultSet.getInt("id")));

    return databaseVersionHeader;
  }
View Full Code Here

TOP

Related Classes of org.syncany.database.DatabaseVersionHeader

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.