You can read data values for multiple database objects using query methods in the Model Manager API. You have already seen examples of this for database configurations and repositories earlier in the section. As the number of objects in a database can potentially be large, these query methods return so-called
result streams from which individual elements can be retrieved
on demand. You may, for example, build an application in the Application Builder that shows the latest couple of versions of a model in a suitable form object. In that case, it would typically be wasteful to first fetch data for all versions from the database in the app and then immediately discard all but a few to show in the form object.
All result streams in the Model Manager API extend DatabaseApiResultStream. You can read the first element from the result stream, read a fixed number of elements from the result stream as a list or an array, or you can traverse the elements in the result stream using loop constructs.
When you expect that a query should only return a single element — anything else to be considered an error — you can use the single method on the result stream. Find the latest version of a model with a specific filename, with the filename expected to be unique for models on the branch.
When you need to traverse a large number of database objects from a result stream, it is better to use a for-each loop statement. Save the latest versions of all models from one
source database to another
target database.
You can also use the iterator method on
DatabaseApiResultStream to take explicit control of the element traversal. With an iterator, you can, for example, fetch the next 100 versions when building an application user interface that shows a version history with
show more functionality.