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 --- .../workingwithgenerateddatabasekeys.html | 149 +++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 site/trunk/site-publish/workingwithgenerateddatabasekeys.html (limited to 'site/trunk/site-publish/workingwithgenerateddatabasekeys.html') diff --git a/site/trunk/site-publish/workingwithgenerateddatabasekeys.html b/site/trunk/site-publish/workingwithgenerateddatabasekeys.html new file mode 100644 index 0000000000..c3b4f13b21 --- /dev/null +++ b/site/trunk/site-publish/workingwithgenerateddatabasekeys.html @@ -0,0 +1,149 @@ + + + + + + + + + + + + + + + Apache Tuscany : WorkingWithGeneratedDatabaseKeys + + + + + + + + + + + + + + + +
+ + + + +   + +
+ + +
+
+ + + + + + + + + +
+  Apache Tuscany > Home > DAS Overview > DAS Java > DAS Java Documentation Menu > DAS Java Developer Guide > RDB DAS Java > RDB DAS - User Guide > WorkingWithGeneratedDatabaseKeys + + User List | Dev List | Issue Tracker   +
+ + + + + + + +
+ + +
+ +
+
+

WorkingWithGeneratedDatabaseKeys

+

The RDB DAS provides the ability to work with database generated keys. A piece of configuration information , typically via a configuration XML file, is used to indicate to the DAS that a column value is generated by the database. This piece of information is necessary when new rows are inserted to the database since the DAS will generate an INSERT statement that does not include the generated column.

+ +

The follwing example illustrates the use of generated keys with the DAS:

+
+

DAS das = DAS.FACTORY.createDAS(getConfig("CompanyConfig.xml"), getConnection());
+ Command select = das.getCommand("all companies");
+ DataObject root = select.executeQuery();

+ +

// Create a new Company
+ DataObject company = root.createDataObject("COMPANY");
+ //Initialize properties of the new company
+ company.setString("NAME", "Do-rite Pest Control");

+ +

// Flush changes
+ das.applyChanges(root);

+ +

// Inspect the id
+ Integer id = (Integer) company.get("ID");

+
+

The first line creates a DAS instance form the factory passing it a stream over the file "CompanyConfig.xml". Here are the contents of that file:

+
+
<Config xsi:noNamespaceSchemaLocation="http:///org.apache.tuscany.das.rdb/config.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+      <Command name="all companies" SQL="select * from COMPANY" kind="Select"/>
+
+      <Table tableName="COMPANY">
+        <Column columnName="ID" primaryKey="true" generated="true"/>
+      </Table>
+
+   </Config>
+
+
+

Note that only the 'ID' column is specified in the file since this is the only column we need to attach any information to. Notice also that when the new Company instance in created, no value is assigned to the 'ID' property since this value will be supplied by the database when the insert operation is performed.

+ +

As part of the "apply changes" processing, the DAS will propogate the database-supplied key values back to the respective DataObjects in the graph. The purpose of this is to make the values available to the application if needed.

+ +

This simple example only demosntrates the insertion of a flat graph of data since the graph consists only of Company instances. But, the DAS is capable of more complex scenarios. The DAS can also handle graphs of related DataObjects each with generated columns.

+
+
+
+ + +
+ + + + + + website stats + + + + + + -- cgit v1.2.3