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

For more information, please explore the Attic.

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


As mentioned elsewhere in this guide, the RDB DAS provides a simple, implicit mapping from SDO Types/Properties to Relational Tables/Columns. So, in the absence of configuration to the otherwise, reading a table named CUSTOMER with columns NAME and ADDRESS will result in a data graph containing SDO DataObjects of Type CUSTOMER with properties NAME and ADDRESS.

This is great for reading entities from a single table but clients often need to read data from related tables for example Customers and their related Orders. The RDB DAS can work with related database tables and reads that span tables produce graphs of related data objects. Continuing with our Customer->Order example, a client can read a set of Customers and related Orders by using a SELECT statement that includes a join as in the following example:

DASImpl* das = (DASImpl*) DASImpl::getFactory().createDAS(Config("CustomerOrderConfig.xml"), getConnection());
// Read some customers and related orders

DataObjectPtr root = select->executeQuery();
DataObjectPtr customer = root->getDataObject("customer[1]");
DataObjectList& orders = customer->getList("orders");

delete das; 

You can see that the client can work with the data graph as a set of related objects. Once the application has a handle to a customer, it can reference that customers related orders by accessing the customers "orders" property.

Notice that the example provides a config file as part of creating the DAS. This file contains mapping information that defines to the DAS how the queried tables are related. Here are the contents of the config file:

<Config xsi:noNamespaceSchemaLocation="http:///org.apache.tuscany.das.rdb/config.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

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

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

     <Relationship name="orders" primaryKeyTable="CUSTOMER" foreignKeyTable="ANORDER" many="true">
        <KeyPair primaryKeyColumn="ID" foreignKeyColumn="CUSTOMER_ID"/>


This config file specifies the primary keys of the related tables and then the relationship between them. It also provides a convenient name for the relationship. In short, this config specifies that the CUSTOMER table and ANORDER table are related via ANORDERs column named "CUSTOMER_ID" which references CUSTOMERS column named "ID". The name of the relationship is "orders"

As a side note, the config in this example is not required since the table definitions follow a "convention" recognized by the DAS. See []WorkingWithConventions.

website stats