Chapter 9 Working with Object-Oriented Models
The class mapping allows to identify the physical data objects (tables or views) used to store class instances in a relational database. Once the source tables or views are identified and mapped with the classes of the current model, you can define mappings between attributes and table columns.
You have to use the Mapping tab of a class property sheet to define class mappings. It contains the following sub-tabs:
The Class Sources sub-tab allows you to associate one or several tables or views in the data source to the current class. These tables and views will store the classes in the relational database.
You can use the Add Objects tool to select tables or views from the physical data models opened in the current workspace.
For more information about the Add Objects tool, see the "Mapping Editor" chapter in the General Features Guide.
Each attribute can be associated with a column of the selected tables or views in order to specify where and how attribute values are stored in the database. When a class inherits from a non-generated class via a generalization link, the attributes of the parent class appear in the Selection dialog box in order to let you create a mapping with these inherited attributes. The attributes of a non-generated derived class also appear in the Selection dialog box.
For more information about the different tools in the toolbar, see the "Mapping Editor" chapter in the General Features Guide.
The Operations Mapping sub-tab allows to associate a SQL query to an operation of a class.
For more information about operation mappings, see section "Mapping an operation".
The Criteria sub-tab allows to specify join criteria between source tables or views. For example: EMPLOYEE.ID < 100
The following SQL queries are automatically computed to figure out how data of class instances are retrieved from or stored into the database:
select ADDRESS.LINE1 "LINE1", ADDRESS.LINE2 "LINE2", ADDRESS.CITY "CITY", ADDRESS.ZIPCODE "ZIPCODE", ADDRESS.COUNTRY "COUNTRY" from ADDRESS
insert into ADDRESS( ADDRESS.LINE1, ADDRESS.LINE2, ADDRESS.CITY, ADDRESS.ZIPCODE, ADDRESS.COUNTRY) values ( %LINE1%, %LINE2%, %CITY%, %ZIPCODE%, %COUNTRY%)
update ADDRESS set ADDRESS.LINE1 = %LINE1%, ADDRESS.LINE2 = %LINE2%, ADDRESS.CITY = %CITY%, ADDRESS.ZIPCODE = %ZIPCODE%, ADDRESS.COUNTRY = %COUNTRY%
delete line* from ADDRESS
Each statement is automatically generated. If you modify a statement, it becomes user-defined and can no longer be automatically calculated, even when you update the mapping. You can tell that a statement is user-defined because the User-Defined tool is pressed in the toolbar.
You can recover the computed expression by clicking the User-Defined tool, this will remove any non calculated expression from the tab.
The syntax of SQL queries follows a predefined template. You can customize the query syntax by modifying the SelectStatement, InsertStatement, UpdateStatement, and DeleteStatement entries in the Profile category of the object language or extended model definition.
For more information on customizing templates, see section Defining templates, in chapter Generation Reference Guide in the Advanced User Documentation .
Copyright (C) 2006. Sybase Inc. All rights reserved. |
![]() |