Skip to main content

%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.

%OnDeleteModel

ClassMethod %OnDeleteModel(pID As %String) As %Status

This callback method is invoked when the DataModel is deleted. This is implemented by the subclasses of this class.

%OnDeleteSource

ClassMethod %OnDeleteSource(pID As %String) As %Status

This callback method is called when the DataModel is deleted. If implemented, it is responsible for making the appropriate deletes against the data source.

%CopyDataToModel

Method %CopyDataToModel(ByRef pData, pSeries As %Integer = "") As %Status [ CodeMode = objectgenerator, Final, GenerateAfter = (%GetPropertyInfo, %OnCopyDataToModel), Internal ]

Internal method.
Called by the dataController to move data into this model. Copies the values in the array pData (subscripted by series and property name) into this data model.

%CopyDataFromModel

Method %CopyDataFromModel(Output pData, Output pTypes, pSeries As %Integer = "") As %Status [ CodeMode = objectgenerator, Final, GenerateAfter = (%GetPropertyInfo, %OnCopyDataFromModel), Internal ]

Internal method.
Called by the dataController to get data from this model. Copies the values in the data demo to the array pData (subscripted by series number and property name).

%OnCopyDataToModel

Method %OnCopyDataToModel(ByRef pData) As %Status [ Abstract ]

If defined, this callback method is invoked just before the dataController copies its values into the properties of this DataModel object.
pData is an array containing the values provided by the controller, subscripted by property name.

%OnCopyDataFromModel

Method %OnCopyDataFromModel(ByRef pData) As %Status [ Abstract ]

If defined, this callback method is invoked just as this DataModel object is about to copy its values into a dataController.
pData is an array containing the values that will be provided to the controller, subscripted by property name.

%GetPropertyInfo

ClassMethod %GetPropertyInfo(Output pInfo As %String, pExtended As %Boolean = 0, pModelId As %String = "", pContainer As %String = "") As %Status [ CodeMode = objectgenerator, Final, GenerateAfter = %OnGetPropertyInfo ]

Return an array, subscripted by property name, describing the properties within this DataModel.
These are returned as an array of the form:
pInfo(name) = seqno
If pExtended is true (1), then the array will include additional nodes for each property. This information is used to create dynamic forms for this model.
Applications should not change this method. To modify the information returned by this method, override the %OnGetPropertyInfo callback method.

%OnGetPropertyInfo

ClassMethod %OnGetPropertyInfo(pIndex As %Integer, ByRef pInfo As %String, pExtended As %Boolean = 0, pModelId As %String = "", pContainer As %String = "") As %Status [ Abstract ]

This callback method, if present, is called by the %GetPropertyInfo method. This gives subclasses the opportunity to add additional property descriptions to the DataModel.
pIndex is the index number that should be used to add the next property to the list.
pInfo is a multidimensional array containing information about the properties of this data model.
If pExtended is true, then complete information about the properties should be returned; if false, then only property names need be returned (applications can simply ignore this).
pModelId is the id value of the current Data Model instance. This is provided for cases where the contents of a dynamic form may vary by instance of the Data Model object.

%GetPropertyList

ClassMethod %GetPropertyList(pModelId As %String = "", pContainer As %String = "") As %String [ CodeMode = objectgenerator, Final, GenerateAfter = %GetPropertyInfo, Internal ]

Return a comma-delimited list of properties within this DataModel, including any virtual properties provided by the %OnGetPropertyInfo pContainer is the containing property in the case of an embedded object. This method is simply an optimization for cases where there is no user-defined %OnGetPropertyInfo method.

%BuildPropertyList

ClassMethod %BuildPropertyList(pModelId As %String = "", pContainer As %String = "") As %String [ Internal, Private ]

Internal method.
Build a comma-delimited list of of properties within this DataModel using the list returned by %GetPropertyInfo.

%GetJSValidationCode

ClassMethod %GetJSValidationCode() As %String [ CodeMode = objectgenerator ]

Internal method.
This generated method contructs client-side JS validation code for the properties within this provider. The client-side code is returned as a string that is converted to JS function at run-time.

%GetLookupSQL

ClassMethod %GetLookupSQL(pProperty As %String, Output pSQL As %String, Output pSQLLookup As %String) As %Status [ CodeMode = objectgenerator, Internal ]

Internal method. This is called in order to get the SQL statements (specified by the ZENSQL and ZENSQLLOOKUP parameters) that will provide a set of lookup values for a property.

%DispatchGetProperty

Method %DispatchGetProperty(pProperty As %String) [ CodeMode = objectgenerator, Internal ]

Provide a property dispatch method to catch references to virtual properties.
This should not be called directly.
This method is only generated if the DYNAMICPROPERTIES parameter is true.

%DispatchSetProperty

Method %DispatchSetProperty(pProperty As %String, pValue As %String) [ CodeMode = objectgenerator, Internal ]

Provide a property dispatch method to catch references to virtual properties.
This should not be called directly.
This method is only generated if the DYNAMICPROPERTIES parameter is true.

%SubmitHandler

ClassMethod %SubmitHandler(pSubmit As %ZEN.Submit) As %Status

Internal method.
If a form connected to this DataModel is submitted, this method handles the server-side processing of the submit.

%OnSubmit

Method %OnSubmit(pSubmit As %ZEN.Submit) As %Status

If defined, this callback is called when a form connected to this DataModel is submitted.
The contents of this DataModel will be filled in from the submitted values before this callback is invoked.
The default implementation is to store the submitted values back to the model.