8.2 Object Type Components

Table of Contents Previous Next


8 Object Types and Objects : 8.2 Object Type Components

The object type specification - This is the public interface specifying the attributes and method signatures of the object type.
The object type body - This contains the implementation of the methods specified in the object type specification.
( { attribute { datatype | objtype | collecttype } }
[ method_spec ] [, ...]
[ constructor ] [, ...]
where method_spec is the following:
subprogram_spec
where subprogram_spec is the following:
{ PROCEDURE proc_name
[, parm1 [ IN | IN OUT | OUT ] datatype1
[ DEFAULT value1 ] ]
[, parm2 [ IN | IN OUT | OUT ] datatype2
[ DEFAULT value2 ]
FUNCTION func_name
[, parm1 [ IN | IN OUT | OUT ] datatype1
[ DEFAULT value1 ] ]
[, parm2 [ IN | IN OUT | OUT ] datatype2
[ DEFAULT value2 ]
RETURN return_type
where constructor is the following:
CONSTRUCTOR func_name
[, parm1 [ IN | IN OUT | OUT ] datatype1
[ DEFAULT value1 ] ]
[, parm2 [ IN | IN OUT | OUT ] datatype2
[ DEFAULT value2 ]
Note: The OR REPLACE option cannot be currently used to add, delete, or modify the attributes of an existing object type. Use the DROP TYPE command to first delete the existing object type. The OR REPLACE option can be used to add, delete, or modify the methods in an existing object type.
Note: The PostgreSQL form of the ALTER TYPE ALTER ATTRIBUTE command can be used to change the data type of an attribute in an existing object type. However, the ALTER TYPE command cannot add or delete attributes in the object type.
name is an identifier (optionally schema-qualified) assigned to the object type.
If the AUTHID clause is omitted or DEFINER is specified, the rights of the object type owner are used to determine access privileges to database objects. If CURRENT_USER is specified, the rights of the current user executing a method in the object are used to determine access privileges.
attribute is an identifier assigned to an attribute of the object type.
datatype is a base data type.
objtype is a previously defined object type.
collecttype is a previously defined collection type.
Following the closing parenthesis of the CREATE TYPE definition, [ NOT ] FINAL specifies whether or not a subtype can be derived from this object type. FINAL, which is the default, means that no subtypes can be derived from this object type. Specify NOT FINAL if you want to allow subtypes to be defined under this object type.
Note: Even though the specification of NOT FINAL is accepted in the CREATE TYPE command, SPL does not currently support the creation of subtypes.
Following the closing parenthesis of the CREATE TYPE definition, [ NOT ] INSTANTIABLE specifies whether or not an object instance can be created of this object type. INSTANTIABLE, which is the default, means that an instance of this object type can be created. Specify NOT INSTANTIABLE if this object type is to be used only as a parent “template” from which other specialized subtypes are to be defined. If NOT INSTANTIABLE is specified, then NOT FINAL must be specified as well. If any method in the object type contains the NOT INSTANTIABLE qualifier, then the object type, itself, must be defined with NOT INSTANTIABLE and NOT FINAL.
Note: Even though the specification of NOT INSTANTIABLE is accepted in the CREATE TYPE command, SPL does not currently support the creation of subtypes.
method_spec denotes the specification of a member method or static method.
Prior to the definition of a method, [ NOT ] FINAL specifies whether or not the method can be overridden in a subtype. NOT FINAL is the default meaning the method can be overridden in a subtype.
Prior to the definition of a method specify OVERRIDING if the method overrides an identically named method in a supertype. The overriding method must have the same number of identically named method parameters with the same data types and parameter modes, in the same order, and the same return type (if the method is a function) as defined in the supertype.
Prior to the definition of a method, [ NOT ] INSTANTIABLE specifies whether or not the object type definition provides an implementation for the method. If INSTANTIABLE is specified, then the CREATE TYPE BODY command for the object type must specify the implementation of the method. If NOT INSTANTIABLE is specified, then the CREATE TYPE BODY command for the object type must not contain the implementation of the method. In this latter case, it is assumed a subtype contains the implementation of the method, overriding the method in this object type. If there are any NOT INSTANTIABLE methods in the object type, then the object type definition itself, must specify NOT INSTANTIABLE and NOT FINAL following the closing parenthesis of the object type specification. The default is INSTANTIABLE.
subprogram_spec denotes the specification of a procedure or function and begins with the specification of either MEMBER or STATIC. A member subprogram must be invoked with respect to a particular object instance while a static subprogram is not invoked with respect to any object instance.
proc_name is an identifier of a procedure. If the SELF parameter is specified, name is the object type name given in the CREATE TYPE command. If specified, parm1, parm2, … are the formal parameters of the procedure. datatype1, datatype2, … are the data types of parm1, parm2, … respectively. IN, IN OUT, and OUT are the possible parameter modes for each formal parameter. If none are specified, the default is IN. value1, value2, … are default values that may be specified for IN parameters.
Include the CONSTRUCTOR keyword and function definition to define a constructor function.
func_name is an identifier of a function. If the SELF parameter is specified, name is the object type name given in the CREATE TYPE command. If specified, parm1, parm2, … are the formal parameters of the function. datatype1, datatype2, … are the data types of parm1, parm2, … respectively. IN, IN OUT, and OUT are the possible parameter modes for each formal parameter. If none are specified, the default is IN. value1, value2, … are default values that may be specified for IN parameters. return_type is the data type of the value the function returns.
For each member method there is an implicit, built-in parameter named SELF, whose data type is that of the object type being defined.
SELF refers to the object instance that is currently invoking the method. SELF can be explicitly declared as an IN or IN OUT parameter in the parameter list (for example as MEMBER FUNCTION (SELF IN OUT object_type ...)).
If SELF is explicitly declared, SELF must be the first parameter in the parameter list. If SELF is not explicitly declared, its parameter mode defaults to IN OUT for member procedures and IN for member functions.
A static method cannot be overridden (OVERRIDING and STATIC cannot be specified together in method_spec).
A static method must be instantiable (NOT INSTANTIABLE and STATIC cannot be specified together in method_spec).
method_spec [...]
[constructor] [...]
where method_spec is the following:
subprogram_spec
and subprogram_spec is the following:
{ PROCEDURE proc_name
[, parm1 [ IN | IN OUT | OUT ] datatype1
[ DEFAULT value1 ] ]
[, parm2 [ IN | IN OUT | OUT ] datatype2
[ DEFAULT value2 ]
[ variable_declaration; ] ...
statement; ...
statement; ...]
FUNCTION func_name
[, parm1 [ IN | IN OUT | OUT ] datatype1
[ DEFAULT value1 ] ]
[, parm2 [ IN | IN OUT | OUT ] datatype2
[ DEFAULT value2 ]
RETURN return_type
[ variable_declaration; ] ...
statement; ...
statement; ...]
where constructor is:
CONSTRUCTOR func_name
[, parm1 [ IN | IN OUT | OUT ] datatype1
[ DEFAULT value1 ] ]
[, parm2 [ IN | IN OUT | OUT ] datatype2
[ DEFAULT value2 ]
[ variable_declaration; ] ...
statement; ...
statement; ...]
name is an identifier (optionally schema-qualified) assigned to the object type.
method_spec denotes the implementation of an instantiable method that was specified in the CREATE TYPE command.
If INSTANTIABLE was specified or omitted in method_spec of the CREATE TYPE command, then there must be a method_spec for this method in the CREATE TYPE BODY command.
If NOT INSTANTIABLE was specified in method_spec of the CREATE TYPE command, then there must be no method_spec for this method in the CREATE TYPE BODY command.
subprogram_spec denotes the specification of a procedure or function and begins with the specification of either MEMBER or STATIC. The same qualifier must be used as was specified in subprogram_spec of the CREATE TYPE command.
proc_name is an identifier of a procedure specified in the CREATE TYPE command. The parameter declarations have the same meaning as described for the CREATE TYPE command, and must be specified in the CREATE TYPE BODY command in the same manner as specified in the CREATE TYPE command.
Include the CONSTRUCTOR keyword and function definition to define a constructor function.
func_name is an identifier of a function specified in the CREATE TYPE command. The parameter declarations have the same meaning as described for the CREATE TYPE command, and must be specified in the CREATE TYPE BODY command in the same manner as specified in the CREATE TYPE command. return_type is the data type of the value the function returns and must match return_type given in the CREATE TYPE command.
variable_declaration is a declaration of a variable, which can be accessed only from within the subprogram. There can be none, one, or more variable declarations. statement is an SPL program statement.

8 Object Types and Objects : 8.2 Object Type Components

Table of Contents Previous Next