Class: MutableRecordModel

diffusion.datatypes.RecordV2. MutableRecordModel


new MutableRecordModel()

This is a mutable data model of diffusion.datatypes.RecordV2 data based upon a diffusion.datatypes.RecordV2.Schema.

An initial version of such a model can be created from a schema using the diffusion.datatypes.RecordV2.Schema#createMutableModel() method. A model created in this way will have all mandatory fields set to default values.

The model may then be updated as required and then at any time a diffusion.datatypes.RecordV2 object can be generated from the current state using the asValue method. The diffusion.datatypes.RecordV2 object may then be used to update a topic.

When values for integer or decimal type fields are supplied the values are validated and normalized. All number values will have any insignificant leading zeroes removed. A decimal value will also be rounded to its specified scale.

All mutator methods return the model so that calls can be chained.

Since:
  • 6.0

Methods


add( [recordName] [, recordIndex])

Adds new values to the end of a variable length field list.

This can only be used for a variable multiplicity field which can only be the last field in a record and therefore the field does not need to be named.

If the record name and index are not supplied, this will add values to the last record in the model. If the model's schema does not specify a variable last field or record, an error will be thrown.

Parameters:
Name Type Argument Description
recordName String <optional>

the name of the record

recordIndex Number <optional>

the index identifying the occurrence of the record

values... String

the values to add

Returns:

this model

Type
diffusion.datatypes.RecordV2.MutableRecordModel

addRecord()

Adds a new initialized record occurrence to the end of a variable multiplicity record list.

As the only variable multiplicity record can be the last one there is no need to name the record. This method will add to the list of occurrences of the last defined record. The record will be initialized with default values appropriate to the schema definition and may then have individual field items set separately.

Returns:

this model

Type
diffusion.datatypes.RecordV2.MutableRecordModel

asRecordV2()

Creates an immutable diffusion.datatypes.RecordV2 object generated from the model.

Returns:

a new immutable instance

Type
diffusion.datatypes.RecordV2

fieldCount(recordName, recordIndex, fieldName)

Returns the actual number of occurrences of a named field within a specified record.

For all but variable fields this simply returns the schema defined number of occurrences of the field.

Parameters:
Name Type Description
recordName String

the record name

recordIndex Number

the record index

fieldName String

the field name

Returns:

the actual number of occurrences of the field

Type
Number

get(recordName [, recordIndex], fieldName [, fieldIndex])

Get a field value.

This allows an item to be addressed using a key of the form recordName(recordIndex).fieldName(fieldIndex). Indexes may be omitted in which case 0 is assumed.

Parameters:
Name Type Argument Default Description
recordName String

the name of the record

recordIndex Number <optional>
0

the index of the record

fieldName String

the name of the field

fieldIndex Number <optional>
0

the index of the field

Returns:

the field value

Type
String
Example
// Get field value with record & field names and indices
var value = model.get("record", 0, "field", 0);

recordCount(recordName)

Returns the actual number of occurrences of a named record.

If the record is not variable, this is the same as the defined number of occurrences in the schema

Parameters:
Name Type Description
recordName String

the record name

Returns:

the actual number of occurrences of the record

Type
Number

removeField(recordName, recordIndex, the)

Removes the specified occurrence of a variable multiplicity field.

A variable multiplicity field must be the last or only field within a record and therefore the field name is not required.

Parameters:
Name Type Description
recordName String

the name of the record

recordIndex Number

the record index

the Number

index of the field to remove

Returns:

this model

Type
diffusion.datatypes.RecordV2.MutableRecordModel

removeRecord(index)

Removes the specified occurrence of a variable multiplicity record.

A variable multiplicity record must be the last or only record within a schema and therefore the record name is not required.

Parameters:
Name Type Description
index Number

the index of the record to remove

Returns:

this model

Type
diffusion.datatypes.RecordV2.MutableRecordModel

set(recordName [, recordIndex], fieldName [, fieldIndex], value)

Set a field value.

This allows an item to be addressed using a key of the form recordName(recordIndex).fieldName(fieldIndex). Indexes may be omitted in which case 0 is assumed.

Parameters:
Name Type Argument Default Description
recordName String

the name of the record

recordIndex Number <optional>
0

the index of the record

fieldName String

the name of the field

fieldIndex Number <optional>
0

the index of the field

value String

the value to be set

Returns:

this model

Type
diffusion.datatypes.RecordV2.MutableRecordModel
Example
// Get field value with record & field names and indices
var value = model.get("record", 0, "field", 0);