Skip to main content

%Library.ArrayOfObjects

serial class %Library.ArrayOfObjects extends %Collection.AbstractArrayOfObj, %Library.SerialObject

For information on this class, see Working with Collections.

The %ArrayOfObjects class represents an array of references to objects, each of which is associated with a unique key value. Keys can have any value, string or numeric. The objects referred to must be registered. They can be either persistent objects or non-id objects.

Internally, an %ArrayOfObjects object contains two arrays: one for holding the OID values for the objects referred to (or their serialized state in the case of an array of non-id objects); and another for holding the OREF values for any objects that have been explicitly referred to, and hence "swizzled" into memory. Swizzling (loading an object into memory and generating an OREF value for it) happens automatically whenever the user refers to an object within the array.

For example, if array is an %ArrayOfObjects object containing an array of Doctor objects (that is an array of OID values for Doctor objects stored in the database) then the following code fragment will automatically load the Doctor object associated with the key "Primary" into memory and generate an OREF value referring to the in-memory version of the Doctor object. This OREF value can then be used to access the properties and methods of the Doctor object:

  Set doc=array.GetAt("Primary")
  Write doc.Name
  

Alternatively, we could use cascading dot syntax:

  Set name=array.GetAt("Primary").Name
  

When the %ArrayOfObjects object is closed (removed from memory), it will close (call %Close on) all of the references it has swizzled into memory. These classes can be used 'standalone' to store a collection.

Property Inventory

Method Inventory

Parameters

parameter CLASSNAMEINOID = 0;
This parameter determines how the collection object stores OID values. If this parameter is set to 0, then partially-formed OID values, containing only an ID number, are used. If this parameter is set to 1, then fully-formed OID values, containing both a class name and an ID number, are used.
parameter ELEMENTTYPE = %RegisteredObject;
The type (class name) of the elements stored in the collection.

Properties

property Data as %String [ MultiDimensional ];
Data is a private property used to hold the contents of the array.
Property methods: DataDisplayToLogical(), DataGet(), DataIsValid(), DataLogicalToDisplay(), DataLogicalToOdbc(), DataNormalize(), DataSet()
property ElementType as %String (MAXLEN = 256) [ InitialExpression = ..#ELEMENTTYPE ];
The type (class name) of the elements stored in the collection.
Property methods: ElementTypeDisplayToLogical(), ElementTypeGet(), ElementTypeIsValid(), ElementTypeLogicalToDisplay(), ElementTypeLogicalToOdbc(), ElementTypeNormalize(), ElementTypeSet()
property Oref as %String [ MultiDimensional ];
Private storage area used to hold OREF values.
Property methods: OrefDisplayToLogical(), OrefGet(), OrefIsValid(), OrefLogicalToDisplay(), OrefLogicalToOdbc(), OrefNormalize(), OrefSet()

Methods

method %AddToSaveSet(force As %Integer = 0, refresh As %Integer = 0) as %Status
Overrides %SerialObject implementation. Scans objects for modifications in the related list (Element) and the terminated relationship list (DeleteOref). Modified/Scheduled to delete objects are added to the save graph.
method %SerializeObject(ByRef serial As %Binary, partial As %Integer = 0) as %Status
Inherited description: This method retrieves all of the serial values for referenced objects and places them into the instance variables, Validates, Normalizes, and serializes the object (with a save of the persistent image if persistent).
This method is not meant to be called directly. It is called by %Save and by %GetSwizzleObject.
method %UnSwizzleAt(key As %String, force As %Integer = 0) as %Status
Unswizzles (removes from memory) the element associated with key in the array.

Returns a %Status value indicating success or failure.

classmethod BuildValueArray(serialized As %Binary, array As %Binary) as %Status
Constructs array(key)=value for each element in the serialval value.

Returns a %Status value indicating success or failure.

method Clear() as %Status
Clears the contents of the array. Both the OID and OREF values are cleared.

Returns a %Status value indicating success or failure.

method Count() as %Integer
Returns the number of elements contained in the array.
deprecated final method Define(key As %String) as %Boolean
This method is deprecated.

Please use IsDefined() instead.

method Find(element As %ObjectIdentity, key As %String) as %String
Starting from, but not including, location key, finds the next element in the array whose OID value equals element.

If key is a null string (""), the search starts at the beginning of the array.

Find returns the key associated with the found element or null string ("") if no element is found.

method FindObjectId(id As %String, key As %Integer) as %String
Starting from, but not including, position key, FindObjectId finds the next element in the list whose ObjectId equals id. If key is a null string, Find starts at the beginning of the list.

Find returns the position of the found element or null string ("") if no element was found.

method GetAt(key As %String) as %RegisteredObject
Finds and returns the OREF value of the element associated with key.

GetAt returns the OREF value of the element associated with key or null string ("") if no element is found.

method GetNext(ByRef key As %String) as %RegisteredObject
Finds and returns the OREF value of the element at the location after key in the array. If key is a null string (""), it returns the OREF value of the first element in the array.

The value of key, which is passed by reference, is updated to the key value of the returned element or null string ("") if key is at the end of the array.

method GetObjectAt(key As %String, force As %Integer = 0) as %ObjectIdentity
Finds and returns the OID value of the element associated with key.

GetObjectAt returns the OID value of the element associated with key or null string ("") if no element is found.

method GetObjectIdAt(key As %String, force As %Integer = 0) as %String
Finds and returns the ID value of the element associated with key.

GetObjectIdAt returns the ID value of the element associated with key or null string ("") if no element is found.

method GetObjectIdNext(ByRef key As %String) as %String
Finds and returns the ID value of the element at the location after key in the array. If key is a null string (""), it returns the ID value of the first element in the array.

The value of key, which is passed by reference, is updated to the key value of the returned element or null string ("") if key is at the end of the array.

method GetObjectIdPrevious(ByRef key As %String) as %String
Finds and returns the ID value of the element at the location before key in the array. If key is a null string (""), it returns the ID value of the last element in the array.

The value of key, which is passed by reference, is updated to the key value of the returned element or null string ("") if key is at the beginning of the array.

method GetObjectNext(ByRef key As %String) as %ObjectIdentity
Finds and returns the OID value of the element at the location after key in the array. If key is a null string (""), it returns the OID value of the first element in the array.

The value of key, which is passed by reference, is updated to the key value of the returned element or null string ("") if key is at the end of the array.

method GetObjectPrevious(ByRef key As %String) as %ObjectIdentity
Finds and returns the OID value of the element at the location before key in the array. If key is a null string (""), it returns the OID value of the last element in the array.

The value of key, which is passed by reference, is updated to the key value of the returned element or null string ("") if key is at the beginning of the array.

method GetPrevious(ByRef key As %String) as %RegisteredObject
Finds and returns the OREF value of the element at the location before key in the array. If key is a null string (""), it returns the OREF value of the last element in the array.

The value of key, which is passed by reference, is updated to the key value of the returned element or null string ("") if key is at the beginning of the array.

final method IsDefined(key As %String) as %Boolean
Returns true (1) if a value is defined at location key, otherwise false (0).
Finds and returns the key value of the element at the location following key in the array. If key is a null string (""), then Next returns the key value for the first element in the array.
Finds and returns the key value of the element at the location preceding key in the array. If key is a null string (""), then Next() returns the key value for the last element in the array.
method RemoveAt(key As %String, Output success As %Boolean) as %ObjectIdentity
Removes the element associated with key in the array.

RemoveAt returns the OID value of the removed element or null string ("") if no element was removed. It also has a success output argument that returns true if the item was removed and false if it was not.

method SetAt(oref As %RegisteredObject, key As %String) as %Status
Sets the OREF value of the element associated with key to element.

Returns a %Status value indicating success or failure.

method SetObjectAt(oid As %ObjectIdentity, key As %String) as %Status
Sets the OID value of the element associated with key to element.

Returns a %Status value indicating success or failure.

method SetObjectIdAt(id As %String, key As %String) as %Status
Sets the ID value of the element associated with key to element.

Returns a %Status value indicating success or failure.

Inherited Members

Inherited Methods

Subclasses

FeedbackOpens in a new tab