예제 #1
0
  public List<Record> readVersions(RecordId recordId, List<Long> versions, QName... fieldNames)
      throws RepositoryException, InterruptedException {
    ArgumentValidator.notNull(recordId, "recordId");
    ArgumentValidator.notNull(versions, "versions");

    if (versions.isEmpty()) return new ArrayList<Record>();

    Collections.sort(versions);

    FieldTypes fieldTypes = typeManager.getFieldTypesSnapshot();
    List<FieldType> fields = getFieldTypesFromNames(fieldTypes, fieldNames);

    Long lowestRequestedVersion = versions.get(0);
    Long highestRequestedVersion = versions.get(versions.size() - 1);
    int numberOfVersionsToRetrieve = (int) (highestRequestedVersion - lowestRequestedVersion + 1);
    Result result = getRow(recordId, highestRequestedVersion, numberOfVersionsToRetrieve, fields);
    Long latestVersion = recdec.getLatestVersion(result);

    // Drop the versions that are higher than the latestVersion
    List<Long> validVersions = new ArrayList<Long>();
    for (Long version : versions) {
      if (version > latestVersion) break;
      validVersions.add(version);
    }
    return recdec.decodeRecords(recordId, validVersions, result, fieldTypes);
  }
예제 #2
0
  public List<Record> readVersions(
      RecordId recordId, Long fromVersion, Long toVersion, QName... fieldNames)
      throws RepositoryException, InterruptedException {
    ArgumentValidator.notNull(recordId, "recordId");
    ArgumentValidator.notNull(fromVersion, "fromVersion");
    ArgumentValidator.notNull(toVersion, "toVersion");
    if (fromVersion > toVersion) {
      throw new IllegalArgumentException(
          "fromVersion '"
              + fromVersion
              + "' must be smaller or equal to toVersion '"
              + toVersion
              + "'");
    }

    FieldTypes fieldTypes = typeManager.getFieldTypesSnapshot();
    List<FieldType> fields = getFieldTypesFromNames(fieldTypes, fieldNames);

    int numberOfVersionsToRetrieve = (int) (toVersion - fromVersion + 1);
    Result result = getRow(recordId, toVersion, numberOfVersionsToRetrieve, fields);
    if (fromVersion < 1L) fromVersion = 1L; // Put the fromVersion to a sensible value
    Long latestVersion = recdec.getLatestVersion(result);
    if (latestVersion < toVersion)
      toVersion = latestVersion; // Limit the toVersion to the highest possible version
    List<Long> versionsToRead = new ArrayList<Long>();
    for (long version = fromVersion; version <= toVersion; version++) {
      versionsToRead.add(version);
    }
    return recdec.decodeRecords(recordId, versionsToRead, result, fieldTypes);
  }