• Tidak ada hasil yang ditemukan

Method Invocation

Dalam dokumen EYEDB Object Query Language (Halaman 34-37)

Instance Method Invocation

OQL allows one to call a instance method with or without parameters. The method can be written in C++ or in OQL.

As in C++, method calls use a combination of the path expression operator and the function call operator.

As inC++orJava, methods can be overloaded: that means that one can have differents methods with the same name and a different signature or differents methods with the same name and the same signature in a class hierarchy. The choice of the method to invoke is done at evaluation time not at compile time. For instance let two methodsPerson Person::f(in int, in int) and int Person::f(in float, in string), the method to be invoked in the expression p->f(x, y)is decided at evaluation time according to the true types ofxandy:

p := first(select Person);

x := 1; y := 2;

p->f(x, y); // X::f(in int, in int) is invoked

p->f(x, y)->name; // this is valid because p->f(x, y) returns a Person x := 1.3; y := "hello";

p->f(x, y); // X::f(in float, in string) is invoked

p->f(x, y)->name; // this is not valid because p->f(x, y) returns an integer

A major contribution of object orientation is the possibility of manipulating polymorphic objects and thanks to the late binding mechanism to carry out generic actions on the elements of these objects.

For instance, let the two methods void Person::doit(in int)and void Employee::doit(in int), the method to be invoked in the expressionp->doit(x)is decided at evaluation time according to the true type of p:

p := new Person();

p->doit(1); // Person::doit(in int) is invoked p := new Employee();

p->doit(1); // Employee::doit(in int) is invoked To invoke a method, the following conditions must be realize:

1. the object or oid on which the method is applied must be an instance of a class, for instanceX.

2. the name of the invoked method, the number and the type of arguments must be compatible with an existing method in the classX,

3. the result type must match the expected type in the expression.

For instance, let the methods int compute(in int, int float)and int compute(in int, in float, in int[], out string) in the classX. To invoke the first method on an instance of X, one needs to apply the method compute to an instance of Xwith one integer and one float, for instance:

x := new X();

x.compute(1, 2.3);

x.compute(a := fact(10), float(fib(10)));

To invoke the second method on an instance of X, one needs to apply the methodcompute to an instance of X with an integer, a float, an ordered collection of integer and a reference to a variable, for instance:

x.compute(1, 23.4, list(1, 2, 3, 4), &a);

The following table shows the mapping (which defines the compatibility) between the ODL and the OQL types.

ODL/OQL Mapping

ODL Type OQL Type

in int16 integer

out int16 identifier

inout int16 identifierinitialized to aninteger

in int32 integer

out int32 identifier

inout int32 identifierinitialized to aninteger

in int64 integer

out int64 identifier

inout int64 identifierinitialized to aninteger

in byte char

out byte identifier

inout byte identifierinitialized to achar

in char char

out char identifier

inout char identifierinitialized to achar

in string string

out string identifier

inout string identifierinitialized to astring

in float float

out float identifier

inout float identifierinitialized to afloat

in oid oid

out oid identifier

inout oid identifierinitialized to aoid

in object * oidof any class

out object * identifier

inout object * identifier initialized to an oid of any class

in X *(Xdenotes a class instance) oidof classX out X *(Xdenotes a class instance) identifier

inout X *(Xdenotes a class instance) identifierinitialized to aoidof classX in X *[](Xdenotes a class instance) ordered collection ofoidof classX out X *[](Xdenotes a class instance) identifier

inout X *[](Xdenotes a class instance) identifier initialized to an ordered col- lection of oidof classX

in X[](Xdenotes any ODL type) ordered collection of atoms bound toX out X[](Xdenotes any ODL type) identifier

inout X[](Xdenotes any ODL type) identifier initialized to an ordered col- lection of atoms bound toX

Note: contrary to the ODMG 3 specifications, one currently needs to use parenthesis to invoke a method even if the method has no arguments.

General Information

Operators .

->

Syntaxes expr. expr (expr list) expr->expr (expr list)

Type n-ary

Operand Types first operand: oid or object, second operand:

identifier, other operands: any type

Result Type type of the atom returned by the method call Functions invokes the method denoted by the second

operand applied to the object denoted by the first operand, using the other operands as arguments.

The first operand must denote an EyeDB in- stance (object or literal) of an agregat including the method whose name is the second operand.

The number of arguments and the type of argu- ments must match one of the methods included in the class of the object denoted by the first operand.

Note these two operators are identical

Expression Examples

expression result comments

p->getOid() the value of the oid of object denoted by p

as getOid() is a na- tive method of the class object, each object can call this method

img->compute(1, 2.3) the value returned by the method call

the first operand must denote an EyeDB instance (object or literal) of an agregat including the method whose name iscompute first(select Person.name

= "wayne").getSpouse()

the value returned by the method call

Class Method Invocation

OQL allows one to call a class method with or without parameters. The method can be written in C++ or in OQL. As in C++, method calls use a combination of the scope operator and the function call operator. To invoke a class method, the following conditions must be realize:

1. the name of the invoked method, the number and the type of arguments must be compatible with an existing method in the classX,

2. the result type must match the expected type in the expression.

The overloading and the late binding mechanisms are the same as for the instance method invocations.

General Information

Operator ::

Syntaxe identifier::identifier(expr list)

Type n-ary

Operand Types first operand: identifier, second operand:

identifier, other operands: any type Result Type type of the atom returned by the method call Functions invokes the class method denoted by the second

operand applied to the class denoted by the first operand, using the other operands as arguments.

The first operand must denote anEyeDBclass of an agregat including the class method whose name is the second operand. The number of arguments and the type of arguments must match one of the class methods included in the class denoted by the first operand.

Expression Examples

expression result comments

EyeDB::getVersion() 2.8.8 getVersion() is a

native static method of the classEyeDB Person::checkName("johnny") the value returned by

the method call

the class method checkName must exist in the class Person and must take one and only one input string argument.

Dalam dokumen EYEDB Object Query Language (Halaman 34-37)

Dokumen terkait