Skip to main content

Special Options for Persistent Classes

Special Options for Persistent Classes

In InterSystems IRIS, all persistent classes extend %Library.PersistentOpens in a new tab (also referred to as %PersistentOpens in a new tab). This class provides much of the framework for the object-SQL correspondence in InterSystems IRIS. Within persistent classes, you have options like the following:

  • Ability to use methods to open, save, and delete objects.

    When you open a persistent object, you specify the degree of concurrency locking, because a persistent object could potentially be used by multiple users or multiple processes.

    When you open an object instance and you refer to an object-valued property, the system automatically opens that object as well. This process is referred to as swizzling. Then you can work with that object as well. In the example below, when the Sample.Person object is opened, the corresponding Sample.Address object is swizzled:

     Set person=##class(Sample.Person).%OpenId(10)
     Set person.Name="Andrew Park"
     Set person.Address.City="Birmingham" 
     Do person.%Save()
    import iris
    person=iris.cls("Sample.Person")._OpenId(10)
    person.Name="Andrew Park"
    person.Address.City="Birmingham"
    person._Save()
    

    Similarly, when you save an object, the system automatically saves all its object-valued properties as well; this is known as a deep save. There is an option to perform a shallow save instead.

  • Ability to use a default query (the Extent query) that is an SQL result set that contains the data for the objects of this class. By default, the Extent query returns the existing IDs in the extent. It can be modified to return more columns.

    In this class (or in other classes), you can define additional queries.

  • Ability to define relationships between classes that are projected to SQL as foreign keys.

    A relationship is a special type of object-valued property that defines how two or more object instances are associated with each other. Every relationship is two-sided: for every relationship definition, there is a corresponding inverse relationship that defines the other side. InterSystems IRIS automatically enforces referential integrity of the data, and any operation on one side is immediately visible on the other side. Relationships automatically manage their in-memory and on-disk behavior. They also provide superior scaling and concurrency over object collections (see Collection Classes).

  • Ability to define foreign keys. In practice, you add foreign keys to add referential integrity constraints to an existing application. For a new application, it is simpler to define relationships instead.

  • Ability to define indexes in these classes.

    Indexes provide a mechanism for optimizing searches across the instances of a persistent class; they define a specific sorted subset of commonly requested data associated with a class. They are very helpful in reducing overhead for performance-critical searches.

    Indexes can be sorted on one or more properties belonging to their class. This allows you a great deal of specific control of the order in which results are returned.

    In addition, indexes can store additional data that is frequently requested by queries based on the sorted properties. By including additional data as part of an index, you can greatly enhance the performance of the query that uses the index; when the query uses the index to generate its result set, it can do so without accessing the main data storage facility.

  • Ability to define triggers in these classes to control what occurs when rows are inserted, modified, or deleted.

  • Ability to project methods and class queries as SQL stored procedures.

  • Ability to fine-tune the projection to SQL (for example, specifying the table and column names as seen in SQL queries).

  • Ability to fine-tune the structure of the globals that store the data for the objects.

Note:

You cannot define relationships, foreign keys, or indexes in Python.

FeedbackOpens in a new tab