Skip to main content

Class Members Specific to Persistent Classes

Class Members Specific to Persistent Classes

InterSystems IRIS classes can include several kinds of class members that are meaningful only in persistent classes. These are storage definitions, indexes, foreign keys, and triggers.

Storage Definitions

In most cases (as discussed later), each persistent class has a storage definition. The purpose of the storage definition is to describe the global structure that InterSystems IRIS uses when it saves data for the class or reads saved data for the class. Your Integrated Development Environment (IDE) displays the storage definition at the end of the class definition. The following shows a partial example:

<Storage name="Default">
<Data name="PersonDefaultData">
<Value name="1">
<Value>%%CLASSNAME</Value>
</Value>
<Value name="2">
<Value>Name</Value>
</Value>
<Value name="3">
<Value>SSN</Value>
</Value>
<Value name="4">
<Value>DOB</Value>
</Value>
<Value name="5">
<Value>Home</Value>
</Value>
<Value name="6">
<Value>Office</Value>
</Value>
<Value name="7">
<Value>Spouse</Value>
</Value>
<Value name="8">
<Value>FavoriteColors</Value>
</Value>
</Data>
<DataLocation>^Sample.PersonD</DataLocation>
<DefaultData>PersonDefaultData</DefaultData>
<ExtentSize>200</ExtentSize>
<IdLocation>^Sample.PersonD</IdLocation>
<IndexLocation>^Sample.PersonI</IndexLocation>
<Property name="%%CLASSNAME">
<Selectivity>50.0000%</Selectivity>
</Property>
...

Also in most cases, the compiler generates and updates the storage definition. For more information on the globals used for persistent classes, see Persistent Objects and Globals.

Indices

As with other SQL tables, an InterSystems SQL table can have indexesOpens in a new tab; to define these, you add index definitions to the corresponding class definition.

An index can add a constraint that ensures uniqueness of a given field or combination of fields. For information on such indexes, see Defining Persistent Classes.

Another purpose of an index is to define a specific sorted subset of commonly requested data associated with a class, so that queries can run more quickly. For example, as a general rule, if a query that includes a WHERE clause using a given field, the query runs more rapidly if that field is indexed. In contrast, if there is no index on that field, the engine must perform a full table scan, checking every row to see if it matches the given criteria — an expensive operation if the table is large. See Other Options for Persistent Classes.

Foreign Keys

An InterSystems SQL table can also have foreign keysOpens in a new tab. To define these, you add foreign key definitions to the corresponding class definition.

Foreign keys establish referential integrity constraints between tables that InterSystems IRIS uses when new data is added or when data is changed. If you use relationships, the system automatically treats these as foreign keys. But you can add foreign keys if you do not want to use relationships or if you have other reasons to add them.

For more information on foreign keys, see Other Options for Persistent Classes.

Triggers

An InterSystems SQL table can also have triggersOpens in a new tab. To define these, you add trigger definitions to the corresponding class definition.

Triggers define code to be executed automatically when specific events occur, specifically when a record is inserted, modified, or deleted.

For more information on triggers, see Other Options for Persistent Classes.

FeedbackOpens in a new tab