Apache Tuscany > Home > DAS Overview > DAS C++ > DAS C++ Documentation Menu > RDB DAS C++ - User Guide > RDB DAS CPP - WorkingWithCompoundKeys User List | Dev List | Issue Tracker  

WorkingWithCompoundKeys

The RDB DAS provides the ability to work with single-column keys as well as keys composed of multiple columns (compound keys). RDB DAS clients can specify the primary key for a table as well as foreign keys that reference other tables. The primary key for a table can be identified to the DAS via configuration (typically via a configuration xml file). The following is an example config file that defines a compound primary key:

<Config xsi:noNamespaceSchemaLocation="http:///org.apache.tuscany.das.rdb/config.xsd">

      <Table tableName="ORDERDETAILS">
         <Column columnName="ORDERID" primaryKey="true"/>
         <Column columnName="PRODUCTID" primaryKey="true"/>
      </Table>

   </Config>

Relationships between tables are in terms of primary keys and foreign keys and so foreign keys can also be compound. The following example illustrates a relationship using a compound foreign key:

<Config xsi:noNamespaceSchemaLocation="http:///org.apache.tuscany.das.rdb/config.xsd">

      <Table tableName="ORDERDETAILS">
         <Column columnName="ORDERID" primaryKey="true"/>
         <Column columnName="PRODUCTID" primaryKey="true"/>
      </Table>

      <Table tableName="ORDERDETAILSDESC">
         <Column columnName="ID" primaryKey="true"/>
      </Table>

      <Relationship name="orderDetailsDesc" primaryKeyTable="ORDERDETAILS"
                     foriegnKeyTable="ORDERDETAILSDESC" many="true">
         <KeyPair primaryKeyColumn="ORDERID" foriegnKeyColumn="ORDERID"  />
         <KeyPair primaryKeyColumn="PRODUCTID" foreignKeyColumn="PRODUCTID" />
      </Relationship>
   </Config>
website stats