Package org.syncany.database

Examples of org.syncany.database.VectorClock


    PreparedStatement preparedStatement = getStatement("databaseversion.select.all.getVectorClockByDatabaseVersionId.sql");
    preparedStatement.setInt(1, databaseVersionId);

    ResultSet resultSet = preparedStatement.executeQuery();

    VectorClock vectorClock = new VectorClock();

    while (resultSet.next()) {
      vectorClock.setClock(resultSet.getString("client"), resultSet.getLong("logicaltime"));
    }
   
    resultSet.close();
    preparedStatement.close();
   
View Full Code Here


    xmlOut.writeEmptyElement("client");
    xmlOut.writeAttribute("name", databaseVersion.getClient());
   
    xmlOut.writeStartElement("vectorClock");

    VectorClock vectorClock = databaseVersion.getVectorClock();     
    for (Map.Entry<String, Long> vectorClockEntry : vectorClock.entrySet()) {
      xmlOut.writeEmptyElement("client");
      xmlOut.writeAttribute("name", vectorClockEntry.getKey());
      xmlOut.writeAttribute("value", vectorClockEntry.getValue());
    }
   
View Full Code Here

    else if (elementPath.equalsIgnoreCase("/database/databaseVersions/databaseVersion/header/client")) {
      String clientName = attributes.getValue("name");
      databaseVersion.setClient(clientName);
    }
    else if (elementPath.equalsIgnoreCase("/database/databaseVersions/databaseVersion/header/vectorClock")) {
      vectorClock = new VectorClock();
    }
    else if (elementPath.equalsIgnoreCase("/database/databaseVersions/databaseVersion/header/vectorClock/client")) {
      String clientName = attributes.getValue("name");
      Long clientValue = Long.parseLong(attributes.getValue("value"));
View Full Code Here

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

    return newDatabaseVersionHeader;
  }
 
  public static VectorClock createVectorClock(String vectorClockString) throws Exception {
    String[] vectorClockElements = vectorClockString.split(",");   
    VectorClock vectorClock = new VectorClock();
   
    for (String vectorClockElement : vectorClockElements) {
      if ("".equals(vectorClockElement.trim())) {
        continue;
      }
     
      Matcher vectorClockElementMatcher = vectorClockElementPattern.matcher(vectorClockElement);
     
      if (!vectorClockElementMatcher.matches()) {
        throw new Exception("Invalid vector clock element string: "+vectorClockElement);
      }
     
      String vectorClockMachineName = vectorClockElementMatcher.group(1);
      long vectorClockTime = Long.parseLong(vectorClockElementMatcher.group(2));
     
      vectorClock.setClock(vectorClockMachineName, vectorClockTime);
    }
   
    return vectorClock;
  }
View Full Code Here

  public static DatabaseVersion createDatabaseVersion(DatabaseVersionHeader basedOnDatabaseVersionHeader) {
    return createDatabaseVersion(basedOnDatabaseVersionHeader, new Date());
  }
 
  public static DatabaseVersion createDatabaseVersion(DatabaseVersionHeader basedOnDatabaseVersionHeader, Date date) {
    VectorClock vectorClock = (basedOnDatabaseVersionHeader != null) ? basedOnDatabaseVersionHeader.getVectorClock().clone() : new VectorClock();
    vectorClock.incrementClock("someclient");
   
    DatabaseVersion databaseVersion = new DatabaseVersion();
   
    databaseVersion.setClient("someclient");
    databaseVersion.setTimestamp(date);
View Full Code Here

TOP

Related Classes of org.syncany.database.VectorClock

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.