How %Populate Works
This section describes how %PopulateOpens in a new tab works internally. The %PopulateOpens in a new tab class contains two method generators: Populate() and PopulateSerial(). Each persistent or serial class inheriting from %PopulateOpens in a new tab has one or the other of these two methods included in it (as appropriate).
We will describe only the Populate method here. The Populate() method is a loop, which is repeated for each of the requested number of objects.
Inside the loop, the code:
-
Creates a new object
-
Sets values for its properties
-
Saves and closes the object
A simple property with no overriding POPSPEC parameter has a value generated using code with the form:
Set obj.Description = ##class(%PopulateUtils).String(50)
While using a library method from %PopulateUtilsOpens in a new tab via a Name:Name() specification would generate:
Set obj.Name = ##class(%PopulateUtils).Name()
An embedded Home property might create code like:
Do obj.HomeSetObject(obj.Home.PopulateSerial())
The generator loops through all the properties of the class, and creates code for some of the properties, as follows:
-
It checks if the property is private, is calculated, is multidimensional, or has an initial expression. If any of these are true, the generator exits.
-
If the property is has a POPSPEC override, the generator uses that and then exits.
-
If the property is a reference, on the first time through the loop, the generator builds a list of random IDs, takes one from the list, and then exits. For the subsequent passes, the generator simply takes an ID from the list and then exits.
-
If the property name is one of the specially handled names, the generator then uses the corresponding library method and then exits.
-
If the generator can generate code based on the property type, it does so and then exits.
-
Otherwise, the generator sets the property to an empty string.
Refer to the %PopulateUtilsOpens in a new tab class for a list of available methods.