Extended Macros
Use this kind of macros when you need to have strict control on access to a relation and/or on how the relation is edited, that is, how targets are replaced, added or removed.
There are three kinds of extended macros:
Those that allow you to redefine only the relation modifiers and use the default accessors:
ILS_W_RELATION_1 and
ILS_W_RELATION_N.
Those that allow you to redefine the runtime relation accessors
and modifiers:
ILS_RW_RELATION_1 and
ILS_RW_RELATION_N.
Those that allow you to redefine the runtime relation accessors with no associated modifiers:
ILS_R_RELATION_1 and
ILS_R_RELATION_N.
For instance, let us assume you need to control the insertion and extraction of a new employee into a department. You will define a modifier with the following signature:
IlsBoolean Department::updateEmployees(Employee&,
IlsBoolean addStatus)
The first argument is the employee to be added or removed.
The second is a Boolean status which indicates whether it is an insertion (status to
IlsTrue) or a deletion (status to
IlsFalse).
The result of the modifier is a Boolean value. When the result is false, the transaction that triggered the modification is automatically rolled back on both the server side and the component side (see
Interaction Cycles).
If, for instance, you decide there should not be two employees with the same name in a department, you might write the following code:
IlsBoolean Department::updateEmployees(Employee& newE,
IlsBoolean addStatus){
if (addStatus){
if (isAlreadyInDept(newE)){
IlsString msg;
msg << "Employee " << newE.name.getValue()
<< " already in the " name.getValue()
<< " department "
IlsMvServer::ReplyMessage(IlsMessage::AppliError(msg));
return IlsFalse;
}
else{
newE.cut(ILS_OWNERSHIP);
employees << &newE;
return IlsTrue;
}
}
else { // addStatus==IlsFalse
if (employees.isIn(&newE)){
employees >> &newE;
return IlsTrue;
}
else
return IlsFalse;
}
}
The function IlsMvServer::ReplyMessage sends a reply message to the component that triggered the modification. (See also the function IlsMvComponent::recvMessage).
In the macros related to the class Department, the macro:
ILS_OWNS_N(Department,Employee,employees)
is replaced by the macro:
ILS_W_RELATION_N(Department,Employee,employees,updateEmployees)
You may want to refer to the Reference Manual for information on how to get the signature of the functions required by each extended macro.
Note: Macros for n-ary relations do no require any targets accessors, because such accessors are never used directly by the view interpreter. |
Version 6.3
Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.