Using Caché Objects - InterSystems Documentation
Using Caché Objects - InterSystems Documentation
Using Caché Objects - InterSystems Documentation
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Unless otherwise configured, <strong>Caché</strong> uses random data to populate the class. In cases with<br />
defined constraints, such as a minimum or maximum length, some of the generated data may<br />
not pass validation, so that individual objects will not be saved. In these situations, Populate<br />
may create fewer than the specified number of objects. To allow you to check this, Populate<br />
returns the number of objects actually populated:<br />
Set objs = ##class(Person).Populate(100)<br />
// objs is set to the number of objects created.<br />
// objs will be less than or equal to 100<br />
The populate utility is aware of the MAXVAL and MINVAL parameters and automatically<br />
creates data that obeys these conditions for properties of type %Integer.<br />
19.1.2.1 Object-valued Properties<br />
The populate utility can automatically generate values for object-valued properties —<br />
embedded objects as well as references to other persistent objects. This allows you to test or<br />
demonstrate more complex objects and classes.<br />
To enable population for these properties:<br />
1. Include %Populate among the superclasses of the referenced class.<br />
2. Create one or more instances of the referenced class.<br />
The POPSPEC Parameter<br />
This ensures that there are valid objects for the object-valued properties to point to.<br />
19.2 The POPSPEC Parameter<br />
The populate utility can provide data for properties containing embedded objects, lists, arrays,<br />
and combinations of these with object-valued properties; it also allows you to customize the<br />
data of certain data type properties.<br />
To perform this kind of data population, provide a value for a property's POPSPEC parameter<br />
by having it reference a method for generating data. If POPSPEC has a value, then the<br />
Populate method invokes the referenced method to generate a value for the property. This<br />
method can be user-provided or one of the methods of the %PopulateUtils class (provided<br />
within the <strong>Caché</strong> library). Methods of %PopulateUtils provide data such as the names of<br />
people, states, countries, or street address in the United States. Refer to the class' documentation<br />
for a complete list of available methods.<br />
To use POPSPEC, set its value as part of a property definition, as follows:<br />
<strong>Using</strong> <strong>Caché</strong> <strong>Objects</strong> 163