Using Caché Objects - InterSystems Documentation
Using Caché Objects - InterSystems Documentation
Using Caché Objects - InterSystems Documentation
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
The <strong>Caché</strong> Data Population Utility<br />
19.1.1 Changes to the Class Definition<br />
To use the populate utility, simply add %Populate to the end of a class' list of superclasses,<br />
so that it inherits the interface methods. For example, if a class inherits directly from<br />
%Persistent, its new superclass list would be:<br />
Class MyApp.MyClass Extends (%Persistent,%Populate) ...<br />
Do not use %Populate as a primary superclass; that is do not list it as the first class in the<br />
superclass list.<br />
When using the New Class Wizard within the <strong>Caché</strong> Studio, you can specify that a new class<br />
supports “automatic data population” . This is equivalent to adding the %Populate class to<br />
the superclass list.<br />
Once you have changed the class definition, re-compile the class so that you can populate<br />
instances with data.<br />
19.1.2 Populating <strong>Objects</strong><br />
To create new instances of a class and populate them with dummy data, simply run the<br />
Populate class method inherited from the %Populate class at the command line in the <strong>Caché</strong><br />
terminal:<br />
Do ##class(Person).Populate()<br />
By default, Populate creates 10 new objects, populates their literal properties with random<br />
data, and saves them in the database. It also populates reference properties if the referenced<br />
class contains any objects, collections of data types, collections of persistent objects, and<br />
indexes defined for the class.<br />
If you prefer, you can specify the number of objects to create:<br />
Do ##class(Person).Populate(num)<br />
where num is the number of objects that you want.<br />
Note:<br />
After using the populate utility to create sample data, you must manually delete the<br />
class extent (set of all object instances) in order to have an empty set of objects. You<br />
can do this using either the %DeleteExtent() method (safe) or the %KillExtent()<br />
method (fast) of the persistent interface. For more information, see the section<br />
Deleting <strong>Objects</strong> in the chapter “Object Persistence.”<br />
162 <strong>Using</strong> <strong>Caché</strong> <strong>Objects</strong>