Querying Versions
Given an item in a Model Manager database, you can query different subsets of versions associated with the item. You can, for example, query its version history with respect to the latest version on a branch, query all versions of the item ever saved in the database, or query versions of other items that are referenced by one of the item’s versions.
Examples
Query the version history of a file item on the same branch as one of its file versions.
// The fileLocationUri variable is initialized elsewhere.
FileItemVersion version = DatabaseApiUtil
  .api()
  .fileVersionByLocationUri(fileLocationUri);
QueryItemVersionHistoryResultStream resultStream = version
  .branchItem()
  .queryVersionHistory();
Query versions associated with a model by including all versions of the model itself as well as all versions of drafts created from the model.
QueryItemVersionParamGenerator p = DatabaseApiUtil
  .param()
  .forQueryItemVersions()
  .withItemVersionInclusionOptions(
    QueryItemVersionInclusionOption.INCLUDE_ANCILLARY);
 
// The itemKey variable is initialized elsewhere.
QueryItemVersionResultStream resultStream = database
  .modelByKey(itemKey)
  .queryVersions(p);
Search for the versions of all drafts created from a model.
// The itemKey variable for the model is initialized elsewhere.
SearchItemVersionsParamGenerator p = DatabaseApiUtil.param()
  .forSearchItemVersions()
  .withSearchFilters("@itemSaveType:draft")
  .withSearchFilters("@originItemKey:" + itemKey.value());
SearchItemVersionResultStream resultStream = database
  .searchItemVersions(p);
Query all geometry parts referenced by a model version.
QueryItemVersionReferencesParamGenerator p = DatabaseApiUtil
  .param()
  .forQueryItemVersionReferences()
  .withItemVersionReferenceTypes(
    ItemVersionReferenceType.GEOMETRYPART);
 
// The itemVersionKey variable is initialized elsewhere.
QueryItemVersionReferenceResultStream resultStream = database
  .modelVersionByKey(itemVersionKey)
  .queryVersionReferences(p);
Search for the latest versions of models containing reusable geometry parts.
SearchBranchItemResultStream resultStream = branch
  .searchItems("@part:geometry");