%ZEN.DataModel.ObjectDataModel
Class %ZEN.DataModel.ObjectDataModel Extends %ZEN.DataModel.DataModel [ Abstract, DependsOn = (%ZEN.Generator, %ZEN.DataModelUtils), Deprecated, PropertyClass = %ZEN.DataModel.objectModelParameters, System = 3 ]
This class is used to implement the Model portion of the Zen Model-View-Controller mechanism.
An ObjectDataModel is specific type of DataModel that contains a set of named values (properties).
The properties of an ObjectDataModel can either be formally defined within the ObjectDataModel class, or they can be "virtual" properties - properties defined at run-time.
When an ObjectDataModel is displayed using a %ZEN.Component.dynaForm, the properties will be displayed in the following default ways:
- Private properties - Not displayed.
- Reference properties - Using a %ZEN.Component.dataCombo.
- Strings - Using a %ZEN.Component.text.
- Strings with MAXLEN over 250 - Using a %ZEN.Component.textarea.
- Numerics - Using a %ZEN.Component.text.
- Dates - Using a %ZEN.Component.dateText.
- Enumerated value (using VALUELIST) - Using a %ZEN.Component.radioSet or %ZEN.Component.comboBox.
Parameters
DOMAIN;
Parameter DOMAIN;
Localization domain. DataModel classes that wish to support localization must provide a value for this within subclasses.
DYNAMICPROPERTIES
Parameter DYNAMICPROPERTIES As BOOL = 1;
If true (the default), then this dataModel class supports dynamic properties: that is, you can reference arbitrary property names within the data model object. Any such properties that are not formally defined will refer to a location within the private property, %data using the dynamic dispatch mechanism. Set this to false to disable this feature.
Properties
%data
Property %data As %ZEN.Datatype.string(POPORDER = -1, XMLPROJECTION = "NONE") [ InitialExpression = {$H}, Internal, MultiDimensional, Transient ];
This property is used to hold any virtual properties used by this model.
A virtual property is a property referenced by the data model but not defined as a formal property within the data model class. This is only used when the DYNAMICPROPERTIES parameter is true.
%source
Property %source As %RegisteredObject(POPORDER = -1, XMLPROJECTION = "NONE") [ Transient ];
If needed, this transient property is used to hold a copy of the source object used by this model.
Methods
%CreateModelInstance
ClassMethod %CreateModelInstance(pID As %String, pConcurrency As %Integer = -1, Output pSC As %Status = {$$$OK}) As %RegisteredObject [ CodeMode = expression ]
Create an instance of this DataModel object.
Subclasses may override this for special behavior.
The default implementation returns the DataModel itself as the source object (this allows for simple DataModel classes that have no actual source object).
%OpenModel
ClassMethod %OpenModel(pID As %String, pConcurrency As %Integer = -1, Output pSC As %Status = {$$$OK}) As %RegisteredObject [ Final ]
Open and return an instance of this DataModel object (given an id value pID and fill in its property values.
The actual loading of the properties is carried out by the %OnLoadModel method. The property values can come from an independent data source object or may be local to this data model object.
If pID is "", then a new instance of data model object should be created.
pConcurrency is an optional concurrency flag that can be used in cases where the data source is a persistent object.
On return, pSC contains a status code indicating success of failure.
%SaveModel
Method %SaveModel() As %Status [ Final ]
Save the values currently within this DataModel object back to a data source. Before saving, the values of the properties will be validated (as specified by the property definitions).
The actual save operation works as follows:
The %OnStoreModel callback is invoked. This copies the properties of this model back to the data source object (if there is an independent data source).
The %OnSaveSource callback is invoked. This causes the independent data source object to be saved.
Returns a status code indicating success or failure.
%DeleteModel
ClassMethod %DeleteModel(pID As %String) As %Status
Delete a given DataModel instance.
This is implemented by the subclasses of this class by providing implementations of the %OnDeleteModel and %OnDeleteSource methods.
%OnOpenSource
Method %OnOpenSource(pID As %String, pConcurrency As %Integer = -1, Output pSC As %Status = {$$$OK}) As %RegisteredObject
This callback method is invoked when a DataModel is loaded into memory. If implemented, it loads an instance of the data source object used by the DataModel.
The default implementation returns the DataModel itself as the source object (this allows for simple DataModel classes that have no actual source object).
%OnNewSource
Method %OnNewSource(Output pSC As %Status = {$$$OK}) As %RegisteredObject
This callback method is invoked when a new instance of DataModel is required. If implemented, it returns a new instance of the data source object used by the DataModel.
The default implementation returns the DataModel itself as the source object (this allows for simple DataModel classes that have no actual source object).
%OnLoadModel
Method %OnLoadModel(pSource As %RegisteredObject) As %Status
This callback method does the actual work of loading values from the source object.
%OnStoreModel
Method %OnStoreModel(pSource As %RegisteredObject) As %Status [ CodeMode = expression ]
This callback method does the actual work of copying values from the DataModel to the data source.
The default implementation is an expression method.
%OnSaveSource
Method %OnSaveSource(pSource As %RegisteredObject) As %Status
This callback method is called when the DataModel is saved. If implemented, it is responsible for saving changes to the data source.