Modeling Services > Relations > Set-relations > Handling Set-relations
 
Handling Set-relations
The class templates IlsOwnsSet and IlsUsesSet provide member functions to manipulate set-relations. Their use is described in the examples below. For more information, see also the Rogue Wave® Server Reference Manual.
To find out whether an object associated with a given key belongs to a set-relation, you must call the function IlsOwnsSet::isIn or IlsUsesSet::isIn:
_flights.isIn("FOO030")
To add an object to a set-relation, you can use the function put or the insertion operator << in the following manner:
_flight<<new Flight("FOO030");
_flights.put(new Flight("FOO030"));
Duplicates are not allowed. If you try to put in a set two objects associated with the same key, the exception IlsAlreadyInSet will be thrown.
To remove an object from a relation-set, you can use the extraction operator >> as follows:
_flights>>foo030;
foo030 is a variable of type CFlightPR.
You can also use the function IlsOwnsSet::suppress or IlsUsesSet::suppress:
_flights.suppress("FOO030");
If there is no match for the key passed to the function, the exception IlsNotFound is thrown.
The function clear empties a set-relation at once:
_flights.clear();
If the minimal cardinality specified for the set is different from zero, a call to the clear function will throw the exception IlsMinCardViolated.
The function get returns the object associated with the specified key:
_flights.get("FOO030")
To get the number of objects in a set, use the function IlsOwnsSet::getCount or IlsUsesSet::getCount:
_flights.getCount();

Version 5.8
Copyright © 2014, Rogue Wave Software, Inc. All Rights Reserved.