Previous Topic: OBJECT StatementNext Topic: FACTORY Optional Statement


ATTRIBUTES Optional Statement

The optional statement on the OBJECT statement that defines the properties of the object.

Syntax

ATTRIBUTES [table_name]{
   att_name [field_name] value_type [access_type[status_type][DISPLAY_NAME string]]{
       [ON_NEW DEFAULT|SET value|NOW ;]
       [ON_CI DEFAULT|SET value|NOW ;]
	[ON_DB_INIT DEFAULT|SET value|NOW ;];]};]

Arguments

table_name

The name of the table in the database that stores the values associated with the attributes in the object. If the table name is not specified, the obj_name in the OBJECT statement is used.

att_name

The name of the attribute. Each attribute usually maps to a field (column) in the database table.

field_name

The name of the field in the database table or LOCAL if the attribute does not map to a field or DERIVED (derived-expr) if the attribute is derived from other attributes. If neither LOCAL, DERIVED nor a field name is specified, the name of the field is assumed to be the same as the name of the attribute.

A variable declared as DERIVED is constructed only when its value is retrieved. The operand of DERIVED contains a list of attribute names and string constants separated by spaces. All attributes in a derived value must be simple values (that is, they cannot be xRELs), and should be declared prior to the derived variable. The derived attribute's value is the concatenation of the values of its constituent values.

String constants within a derived expression may contain references to environment variables in the one of the forms:

${var}

${var#pattern}

${var#pattern#replacement}

Such specifications are replaced with the value of the environment variable at domsrvr startup time. The #pattern operand is optional. If provided, it is treated as a regular expression, and replaced wherever it appears in the environment variable's value. The #replacement operand defaults to null if not specified. Because # is a fixed delimeter, the pattern cannot contain a # symbol. There are no restrictions on the use of derived attributes in other messages. They behave in same way as standard attributes. A hotlink for a derived attribute fires whenever any of the attributes from which it is built changes.

value_type

Identifies the data type of the attribute’s value as:

If STRING is specified, the size can be specified in an integer following STRING. If no size is specified, the value in the database is used.

UUID is 16 bytes of binary data that is used as a unique identifier for certain database records.

SREL refers the attribute to another object. If SREL is specified, obj2_name must be specified to identify the object that the attribute refers to.

srel_name specifies a "named" SREL. Like a "simple" SREL, a "named" is a type of MAJIC OBJECT attribute that represents a single relation, which uniquely identifies a row in another table (ob2_name). A "simple" SREL attribute normally maps to the "id" field in another table, however a "named" SREL maps two or more attributes ( name, name2, … ) to two or more attributes in the referenced table that uniquely identify a row in the referenced table.

access_type

Defines access to the attribute. Valid values are:

Value

Description

CONST

Cannot be changed

PRIVATE

Read-only

PUBLIC

Read/write access (the default)

WRITE_NEW

Can be written only when the object is created, before the object is saved

status_type

Indicates the status of the attribute as:

DISPLAY_NAME string

Specifies a string to be used in place of the attribute name in messages concerning this attribute, such as"required attribute missing"

ON Statements

Use one of these only when value_type is INTEGER, STRING, DATE, or SREL.

ON_NEW DEFAULT|SET value|NOW

Indicates to set the value of an attribute when the object is being created for the first time:

Value

Description

DEFAULT

Changes a null current value to value or NOW.

SET

Changes any current value to value or NOW.

value

Specifies a numeric value or a string value, depending on the data type of the attribute.

NOW

Specify this if the attribute is of type DATE; it sets the attribute to the current date and time.

In the following example, 90 is the value set as a default when the object is created:

ON_NEW DEFAULT 90 ;
ON_CI DEFAULT|SET value|NOW

Indicates to set the value of an attribute when the attribute is being checked into the database. See the description of each parameter for ON_NEW.

ON_DB_INIT DEFAULT|SET value|NOW

Indicates to set the value of an attribute when the attribute is being instantiated from the database. See the description of each parameter for ON_NEW.

Example

This example defines attributes with names like start_date whose values are stored in fields like nlh_start in the Notify_Log_Header table in the database. The field names are followed by each attribute’s data type. Optional parameters define access to some of the attributes, indicate that the attribute is required, and tell when to set the value of some of the attributes to the current date and time.

For example, an attribute named last_mod is defined; its value is set to the current date and time when the attribute is checked into the database. An attribute named contact is also defined; its value is a single relation stored in database field nlh_c_addressee. The object referred to is cnt:

ATTRIBUTES Notify_Log_Header {
   start_date         nlh_start          DATE WRITE_NEW {ON_NEW DEFAULT NOW;} ;
   last_mod                              DATE {ON_CI SET NOW ;} ;
   msg_hdr            nlh_hdr            STRING 20 WRITE_NEW ;
   msg_text           nlh_msg            STRING WRITE_NEW ;
   msg_ack            nlh_user_ack       STRING ;
   contact            nlh_c_addressee    SREL cnt WRITE_NEW ;
   notify_method      nlh_cm_method      INTEGER WRITE_NEW ;
   activity_notify    nlh_transition     INTEGER WRITE_NEW ;
   pri_event          nlh_pri            INTEGER WRITE_NEW ;
   notify_type        nlh_type           INTEGER WRITE_NEW ; 
   ack_time           nlh_ack_time       DURATION ; 
   status             nlh_status         INTEGER REQUIRED ;
   end_date           nlh_end            DATE {ON_NEW DEFAULT NOW ;} ;

};