2016/05/28 - Apache Tuscany has been retired.

For more information, please explore the Attic.

 
 Apache Tuscany > Home > DAS Overview > DAS Java > DAS Java Documentation Menu > DAS Java Developer Guide > RDB DAS Java > RDB DAS - User Guide > 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" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

      <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" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

      <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