From 200a40b332420f94992eb39a6d0ea1cf1490ffc4 Mon Sep 17 00:00:00 2001 From: coreyg Date: Fri, 21 Nov 2014 09:30:19 +0000 Subject: Adding tuscany's website to their svn repo for svnpubsub git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1640879 13f79535-47bb-0310-9956-ffa450edef68 --- .../site-publish/workingwithrelationships.html | 149 +++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 site/trunk/site-publish/workingwithrelationships.html (limited to 'site/trunk/site-publish/workingwithrelationships.html') diff --git a/site/trunk/site-publish/workingwithrelationships.html b/site/trunk/site-publish/workingwithrelationships.html new file mode 100644 index 0000000000..263b28ce67 --- /dev/null +++ b/site/trunk/site-publish/workingwithrelationships.html @@ -0,0 +1,149 @@ + + + + + + + + + + + + + + + Apache Tuscany : WorkingWithRelationships + + + + + + + + + + + + + + + +
+ + + + +   + +
+ + +
+
+ + + + + + + + + +
+  Apache Tuscany > Home > DAS Overview > DAS Java > DAS Java Documentation Menu > DAS Java Developer Guide > RDB DAS Java > RDB DAS - User Guide > WorkingWithRelationships + + User List | Dev List | Issue Tracker   +
+ + + + + + + +
+ + +
+ +
+
+

WorkingWithRelationships

+ +

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:

+
+

DAS das = DAS.FACTORY.createDAS(getConfig("CustomerOrderConfig.xml"), getConnection());
+ // Read some customers and related orders
+ Command select = das.createCommand("SELECT * FROM CUSTOMER LEFT JOIN ANORDER ON CUSTOMER.ID = ANORDER.CUSTOMER_ID WHERE CUSTOMER.ID = 1");

+ +

DataObject root = select.executeQuery();
+ DataObject customer = root.getDataObject("CUSTOMER[1]");
+ List orders = customer.getList("orders");

+
+

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>
+
+     <Table tableName="ANORDER">
+        <Column columnName="ID" primaryKey="true"/>
+     </Table>
+
+     <Relationship name="orders" primaryKeyTable="CUSTOMER" foreignKeyTable="ANORDER" many="true">
+        <KeyPair primaryKeyColumn="ID" foreignKeyColumn="CUSTOMER_ID"/>
+     </Relationship>
+
+   </Config>
+
+
+

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 + + + + + + -- cgit v1.2.3