Some rules for translating the static diagrams of the
object schema are given below. Also here the inference engine refines the products of translation by using
the information contained within the dynamic models of the object oriented schema.
- For each transient class generate a PC++ class with same name, attributes and methods. In this case, the
syntax is equivalent to a that of a C++ class.
- For each persistent class generate a PC++ dbclass with same name, attributes and methods.
- For each generalization/specialization relation insert the name of the superclass in the inheritance chain of the
subclass.
- For each binary bidirectional relation insert a macro Association(class-name, molteplicity) within the private
methods of the classes involved in the relation. Class-name is the name of the other class involved in the relation,
whereas molteplicity is the cardinality of the relation. The PC++ compiler will use the friend mechanism
to prevent update anomalies (see case study).
- For each qualified bidirectional association relation insert a macro
Association(class-name, molteplicity, association-name) within the private methods of
the classes involved in the relation. In addition to normal relations, here there is the additional argument
association-name indicating the name of the relation. Moreover, an additional macro
Make-Class(relation-name, identifier1, identifier2, qualifier) is generated where relation-name
is the name of the qualified relation, identifier1 and identifier2 are the instance identifiers of the
two classes involved in the relation, and qualifier is the qualifier attribute. The macro Make-Class
causes the PC++ compiler create the table relation-name with fields identifier1, identifier2,
qualifier, and the pair (identifier1, qualifier) as the primary key. The attribute qualifier
is also inserted as a data member of the qualified class.
The application of these rules to the classes Transaction and Bank of the class diagram of Figure 2 produces the following PC++ code :
-
- class Transaction{
-
- private:
-
- ... date-time;
-
- Association(EntryStation, one);
-
- ............
-
- };
-
- dbclass Bank{
-
- private:
-
- public:
-
- Boolean verifycard(cardcode1, password1)
-
- ............
-
- };
-
- MakeClass(Issues, CardAuthorizationID, BankID, card-code);
-
-
-
- Boolean Bank::verifycard(cardcode1, password1){
-
- if cardID1=SELECT(Issues,cardauthorizationID,
bankID=this.bankID, cardcode=cardcode1) then
-
- cardobj=LOAD(CardAuthorization, cardID=
cardID1);
-
- return cardobj.verifyauthorization(password1);
-
- else
-
- end
-
- }
Successively, the PC++ compiler will translate the PC++ code given above, producing
the following C++/SQL/ODBC code for the classes above:
-
- class Transaction: public virtual Identifier {
-
- private:
-
- OID TransactionID;
-
- ... date-time;
-
- EntryStation* EntryStationobj;
-
- friend EntryStationAddTransactobj(Transaction*);
-
- friend EntryStationDelTransactobj(Transaction*);
-
- ............
-
- public:
-
- void Store();
-
- Transaction Load(OID ); /* Load an object with a specific identifier from the persistent storage device */
-
- void AddEntryStationobj (EntryStation* );
-
- void DelEntryStationobj (EntryStation* );
-
- ............
-
- };
-
- class Bank: public virtual Identifier {
-
- private:
-
- OID BankID;
-
- ... name;
-
- ... bank-code;
-
- ............
-
- public:
-
- void Store();
-
- Bank Load(OID);
-
- Boolean verifycard(cardcode1, password1)
-
- ............
-
- };
-
- Boolean Bank::verifycard(cardcode1, password1){
-
- if cardID1=StatementExec("SELECT cardauthorizationID FROM Issues
WHERE bankID=this.bankID, cardcode=cardcode1") then
-
- CardAuthorization cardobj;
-
- cardobj.Load(cardID1);
-
- return cardobj.verifyauthorization(password1);
-
- else
-
- end
-
- }
Next: Conclusions
Up: OMAR Programming with PC++
Previous: Persistency in PC++