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); }
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); }
private List<Record> read(List<RecordId> recordIds, List<FieldType> fields, FieldTypes fieldTypes) throws RepositoryException, InterruptedException { long before = System.currentTimeMillis(); try { ArgumentValidator.notNull(recordIds, "recordIds"); List<Record> records = new ArrayList<Record>(); if (recordIds.isEmpty()) return records; Map<RecordId, Result> results = getRows(recordIds, fields); for (Entry<RecordId, Result> entry : results.entrySet()) { Long version = recdec.getLatestVersion(entry.getValue()); records.add( recdec.decodeRecord(entry.getKey(), version, null, entry.getValue(), fieldTypes)); } return records; } finally { if (metrics != null) metrics.report(Action.READ, System.currentTimeMillis() - before); } }
protected Record read( RecordId recordId, Long requestedVersion, List<FieldType> fields, FieldTypes fieldTypes) throws RepositoryException, InterruptedException { long before = System.currentTimeMillis(); try { ArgumentValidator.notNull(recordId, "recordId"); Result result = getRow(recordId, requestedVersion, 1, fields); Long latestVersion = recdec.getLatestVersion(result); if (requestedVersion == null) { // Latest version can still be null if there are only non-versioned fields in the record requestedVersion = latestVersion; } else { if (latestVersion == null || latestVersion < requestedVersion) { // The requested version is higher than the highest existing version throw new VersionNotFoundException(recordId, requestedVersion); } } return recdec.decodeRecord(recordId, requestedVersion, null, result, fieldTypes); } finally { if (metrics != null) metrics.report(Action.READ, System.currentTimeMillis() - before); } }