Object Creation

OQL allows us to create persistent or transient objects using the new operator. The general syntax for an object creation is as follows:
[new] [<[expr]>] class_name({path_expression : expr })
  1. the operator new is optionnal: when the operator is missing, the construct is called an implicit new construct. When the optionnal following construct ``<[expr]>'' is not used, there is no functionnal differences between using new or not.
  2. the optionnal construct after the new operator indicates the target location of the object to create:
    1. if this construct is omitted, the object will be a persistent object created in the current default database,
    2. if this construct is under the form <expr>, the OQL interpreter expects for a database object handle as the result of the expression evaluation. This database will be used as the target location. For instance:
      new < oql$db > Person();
      
      will create a Person instance in the database pointed by oql$db, which is in fact the current database.
    3. if this construct is under the form <>, the object will be a transient object.
  3. the class_name indicates the name of a valid user type in the context of the current database.
  4. the path_expression indicates an attribute name or a sequence of attributes using the optional array operator, for instance the following path expressions are valid for an object construction:
    name
    lastname
    addr.street
    addr.town[3]
    spouse.name
    
  5. the expr behind path_expression is any OQL expression as soon as its result type matches the expected type of the path_expression.
  6. the order of evaluation of the expressions is in the {path_expression : expr} sequence is from left to right.
  7. the expression returns the oid of the created object.
For instance: The new operator can also be used to create basic type object. Note that in this case, the operator is mandatory. The syntax for basic type creation is as follows:
new [<[expr]>] basic_type (value).
  1. where basic_type denotes an ODL basic type. It may be one of the following type: int32, int16, int32, char, byte, float or oid. Note that the type string is not allowed here.
  2. the value must be an atomic value of an OQL type mapped from the ODL basic type
For instance: Finally, the new operator can be also used to create collections. The syntax for collection creation is as follows:
[new] [<[expr]>] coll_type< class_name [, coll_name]> ([collection of elements])
  1. the new operator is optionnal,
  2. where coll_type denotes type of the collection: set, bag, array or list,
  3. the class_name denotes the name of the class of the elements of the collection, for instance Person*, Car*,
  4. coll_name is an optionnal string which denotes the name of the collection to create,
  5. the optionnal collection of elements within parenthesis contains the elements (generally oids) to insert initially in the created collection,
  6. the expression returns the oid of the created collection.
For instance:
General Information
Operator new
Syntax new [<[expr]>] class_name({path_expression : expr })
Type n-ary
Operand Types any type
Result Type oid or object
Functions creates an persistent or transient object

Expression Examples
expression result
john := new Person(name: "john",
                   lastname: "wayne",
                   age : fib(10));
returns the oid of the created Person instance
new Person(name: "mary",
           lastname: "poppins",
           addr.town : "jungle",
           addr.street[0] : 'a',
           addr.street[1] : 'b',
           spouse : john,
           spouse.age : 72
           );
returns the oid of the created Person instance

EyeDB manual