You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by lr...@apache.org on 2007/05/15 19:55:03 UTC

svn commit: r538267 [1/2] - in /incubator/tuscany/java/das/samples/dbconfig: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/tuscany/ src/main/java/org/apache/tuscany/das/ src/main/java/org/apache/...

Author: lresende
Date: Tue May 15 10:55:01 2007
New Revision: 538267

URL: http://svn.apache.org/viewvc?view=rev&rev=538267
Log:
[work in progress] DBInitializer strawman and initial implementation

Added:
    incubator/tuscany/java/das/samples/dbconfig/
    incubator/tuscany/java/das/samples/dbconfig/pom.xml
    incubator/tuscany/java/das/samples/dbconfig/readme.html
    incubator/tuscany/java/das/samples/dbconfig/src/
    incubator/tuscany/java/das/samples/dbconfig/src/main/
    incubator/tuscany/java/das/samples/dbconfig/src/main/java/
    incubator/tuscany/java/das/samples/dbconfig/src/main/java/org/
    incubator/tuscany/java/das/samples/dbconfig/src/main/java/org/apache/
    incubator/tuscany/java/das/samples/dbconfig/src/main/java/org/apache/tuscany/
    incubator/tuscany/java/das/samples/dbconfig/src/main/java/org/apache/tuscany/das/
    incubator/tuscany/java/das/samples/dbconfig/src/main/java/org/apache/tuscany/das/rdb/
    incubator/tuscany/java/das/samples/dbconfig/src/main/java/org/apache/tuscany/das/rdb/Data/
    incubator/tuscany/java/das/samples/dbconfig/src/main/java/org/apache/tuscany/das/rdb/Data/TestData.java
    incubator/tuscany/java/das/samples/dbconfig/src/main/java/org/apache/tuscany/das/rdb/Data/TestDataWithExplicitColumns.java
    incubator/tuscany/java/das/samples/dbconfig/src/main/java/org/apache/tuscany/das/rdb/dbconfig/
    incubator/tuscany/java/das/samples/dbconfig/src/main/java/org/apache/tuscany/das/rdb/dbconfig/DBConfigUtil.java
    incubator/tuscany/java/das/samples/dbconfig/src/main/java/org/apache/tuscany/das/rdb/dbconfig/DBConnectionHelper.java
    incubator/tuscany/java/das/samples/dbconfig/src/main/java/org/apache/tuscany/das/rdb/dbconfig/DBDataHelper.java
    incubator/tuscany/java/das/samples/dbconfig/src/main/java/org/apache/tuscany/das/rdb/dbconfig/DBHelper.java
    incubator/tuscany/java/das/samples/dbconfig/src/main/java/org/apache/tuscany/das/rdb/dbconfig/DBInitializer.java
    incubator/tuscany/java/das/samples/dbconfig/src/main/java/org/apache/tuscany/das/rdb/dbconfig/DataSourceInitializationException.java
    incubator/tuscany/java/das/samples/dbconfig/src/main/java/org/apache/tuscany/das/rdb/dbconfig/DatabaseInitializerException.java
    incubator/tuscany/java/das/samples/dbconfig/src/main/resources/
    incubator/tuscany/java/das/samples/dbconfig/src/main/resources/CannedSampleDBConfig.xml
    incubator/tuscany/java/das/samples/dbconfig/src/main/resources/DBConfig.xsd
    incubator/tuscany/java/das/samples/dbconfig/src/main/resources/META-INF/
    incubator/tuscany/java/das/samples/dbconfig/src/main/resources/META-INF/LICENSE.txt
    incubator/tuscany/java/das/samples/dbconfig/src/main/resources/META-INF/MANIFEST.MF
    incubator/tuscany/java/das/samples/dbconfig/src/main/resources/META-INF/NOTICE
    incubator/tuscany/java/das/samples/dbconfig/src/main/resources/META-INF/README.txt
    incubator/tuscany/java/das/samples/dbconfig/src/main/resources/log4jconfig.properties
    incubator/tuscany/java/das/samples/dbconfig/src/test/
    incubator/tuscany/java/das/samples/dbconfig/src/test/java/
    incubator/tuscany/java/das/samples/dbconfig/src/test/java/org/
    incubator/tuscany/java/das/samples/dbconfig/src/test/java/org/apache/
    incubator/tuscany/java/das/samples/dbconfig/src/test/java/org/apache/tuscany/
    incubator/tuscany/java/das/samples/dbconfig/src/test/java/org/apache/tuscany/das/
    incubator/tuscany/java/das/samples/dbconfig/src/test/java/org/apache/tuscany/das/rdb/
    incubator/tuscany/java/das/samples/dbconfig/src/test/java/org/apache/tuscany/das/rdb/dbconfig/
    incubator/tuscany/java/das/samples/dbconfig/src/test/java/org/apache/tuscany/das/rdb/dbconfig/DBInitializerTestCase.java
    incubator/tuscany/java/das/samples/dbconfig/src/test/resources/
    incubator/tuscany/java/das/samples/dbconfig/src/test/resources/dbConfig.xml

Added: incubator/tuscany/java/das/samples/dbconfig/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/samples/dbconfig/pom.xml?view=auto&rev=538267
==============================================================================
--- incubator/tuscany/java/das/samples/dbconfig/pom.xml (added)
+++ incubator/tuscany/java/das/samples/dbconfig/pom.xml Tue May 15 10:55:01 2007
@@ -0,0 +1,98 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.tuscany.das.samples</groupId>
+        <artifactId>tuscany-das-samples</artifactId>
+        <version>1.0-incubating-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>tuscany-das-sample-dbconfig</artifactId>
+    <packaging>jar</packaging>
+    <name>Tuscany DAS Canned DB Initializer Utility</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.tuscany.das</groupId>
+            <artifactId>tuscany-das-rdb</artifactId>
+            <version>${das.version}</version>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.derby</groupId>
+            <artifactId>derby</artifactId>
+            <version>10.1.2.1</version>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>3.8.1</version>
+	        <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <!-- this will place the java source files inside the jar -->
+    <build>
+        <sourceDirectory>src/main/java</sourceDirectory>
+        <resources>
+            <resource>
+                <directory>src/main/java</directory>
+            </resource>
+            <resource>
+              <directory>src/main/resources</directory>
+            </resource>
+        </resources>
+
+		<plugins>
+		    <plugin>
+			<groupId>org.apache.tuscany.sdo</groupId>
+			<artifactId>tuscany-sdo-plugin</artifactId>
+			<executions>
+			    <execution>
+				<id>config</id>
+				<configuration>
+				    <schemaFile>${basedir}/src/main/resources/DBConfig.xsd</schemaFile>
+				    <noNotification>true</noNotification>
+				    <noUnsettable>true</noUnsettable>
+				</configuration>
+				<goals>
+				    <goal>generate</goal>
+				</goals>
+			    </execution>
+			</executions>
+		    </plugin>
+
+		    <plugin>
+			<groupId>org.apache.maven.plugins</groupId>
+			<artifactId>maven-surefire-plugin</artifactId>
+			<configuration>
+			    <includes>
+				<include>**/*TestCase.java</include>
+			    </includes>
+			</configuration>
+		    </plugin>
+		</plugins>
+
+    </build>
+    
+    
+</project>

Added: incubator/tuscany/java/das/samples/dbconfig/readme.html
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/samples/dbconfig/readme.html?view=auto&rev=538267
==============================================================================
--- incubator/tuscany/java/das/samples/dbconfig/readme.html (added)
+++ incubator/tuscany/java/das/samples/dbconfig/readme.html Tue May 15 10:55:01 2007
@@ -0,0 +1,615 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html xmlns:v="urn:schemas-microsoft-com:vml"
+ xmlns:o="urn:schemas-microsoft-com:office:office"
+ xmlns:w="urn:schemas-microsoft-com:office:word"
+ xmlns:st1="urn:schemas-microsoft-com:office:smarttags"
+ xmlns="http://www.w3.org/TR/REC-html40">
+<head>
+  <meta http-equiv="Content-Type"
+ content="text/html; charset=windows-1252">
+  <meta name="ProgId" content="Word.Document">
+  <meta name="Generator" content="Microsoft Word 10">
+  <meta name="Originator" content="Microsoft Word 10">
+  <link rel="File-List" href="readme_files/filelist.xml">
+  <title>Tuscany RDB DAS Database Setup Utility/title&gt;</title>
+  <o:smarttagtype
+ namespaceuri="urn:schemas-microsoft-com:office:smarttags" name="City"></o:smarttagtype>
+  <o:smarttagtype
+ namespaceuri="urn:schemas-microsoft-com:office:smarttags" name="State"></o:smarttagtype><o:smarttagtype
+ namespaceuri="urn:schemas-microsoft-com:office:smarttags" name="place"></o:smarttagtype><!--[if gte mso 9]><xml>
+ <o:DocumentProperties>
+  <o:Author>IBM_USER</o:Author>
+  <o:LastAuthor>IBM_USER</o:LastAuthor>
+  <o:Revision>5</o:Revision>
+  <o:TotalTime>25</o:TotalTime>
+  <o:Created>2006-10-19T16:54:00Z</o:Created>
+  <o:LastSaved>2006-10-24T16:41:00Z</o:LastSaved>
+  <o:Pages>1</o:Pages>
+  <o:Words>739</o:Words>
+  <o:Characters>4216</o:Characters>
+  <o:Company>IBM</o:Company>
+  <o:Lines>35</o:Lines>
+  <o:Paragraphs>9</o:Paragraphs>
+  <o:CharactersWithSpaces>4946</o:CharactersWithSpaces>
+  <o:Version>10.6735</o:Version>
+ </o:DocumentProperties>
+</xml><![endif]--><!--[if gte mso 9]><xml>
+ <w:WordDocument>
+  <w:SpellingState>Clean</w:SpellingState>
+  <w:GrammarState>Clean</w:GrammarState>
+  <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
+ </w:WordDocument>
+</xml><![endif]--><!--[if !mso]><object
+ classid="clsid:38481807-CA0E-42D2-BF39-B33AF135CC4D" id=ieooui></object>
+<style>
+st1\:*{behavior:url(#ieooui) }
+</style>
+<![endif]-->
+  <style>
+<!--
+ /* Style Definitions */
+ p.MsoNormal, li.MsoNormal, div.MsoNormal
+	{mso-style-parent:"";
+	margin:0in;
+	margin-bottom:.0001pt;
+	mso-pagination:widow-orphan;
+	font-size:12.0pt;
+	font-family:"Times New Roman";
+	mso-fareast-font-family:"Times New Roman";}
+h1
+	{mso-style-next:Normal;
+	margin-top:12.0pt;
+	margin-right:0in;
+	margin-bottom:3.0pt;
+	margin-left:0in;
+	mso-pagination:widow-orphan;
+	page-break-after:avoid;
+	mso-outline-level:1;
+	font-size:16.0pt;
+	font-family:Arial;
+	mso-font-kerning:16.0pt;}
+h3
+	{mso-style-next:Normal;
+	margin-top:12.0pt;
+	margin-right:0in;
+	margin-bottom:3.0pt;
+	margin-left:0in;
+	mso-pagination:widow-orphan;
+	page-break-after:avoid;
+	mso-outline-level:3;
+	font-size:13.0pt;
+	font-family:Arial;}
+p.MsoFootnoteText, li.MsoFootnoteText, div.MsoFootnoteText
+	{mso-style-noshow:yes;
+	margin:0in;
+	margin-bottom:.0001pt;
+	mso-pagination:widow-orphan;
+	font-size:10.0pt;
+	font-family:"Times New Roman";
+	mso-fareast-font-family:"Times New Roman";}
+span.MsoFootnoteReference
+	{mso-style-noshow:yes;
+	vertical-align:super;}
+a:link, span.MsoHyperlink
+	{color:blue;
+	text-decoration:underline;
+	text-underline:single;}
+a:visited, span.MsoHyperlinkFollowed
+	{color:purple;
+	text-decoration:underline;
+	text-underline:single;}
+code
+	{font-family:"Courier New";
+	mso-ascii-font-family:"Courier New";
+	mso-fareast-font-family:"Times New Roman";
+	mso-hansi-font-family:"Courier New";
+	mso-bidi-font-family:"Courier New";}
+pre
+	{margin:0in;
+	margin-bottom:.0001pt;
+	mso-pagination:widow-orphan;
+	font-size:10.0pt;
+	font-family:"Courier New";
+	mso-fareast-font-family:"Times New Roman";}
+span.codefrag
+	{mso-style-name:codefrag;}
+span.SpellE
+	{mso-style-name:"";
+	mso-spl-e:yes;}
+span.GramE
+	{mso-style-name:"";
+	mso-gram-e:yes;}
+@page Section1
+	{size:8.5in 11.0in;
+	margin:1.0in 1.25in 1.0in 1.25in;
+	mso-header-margin:.5in;
+	mso-footer-margin:.5in;
+	mso-paper-source:0;}
+div.Section1
+	{page:Section1;}
+ /* List Definitions */
+ @list l0
+	{mso-list-id:486359905;
+	mso-list-template-ids:631539286;}
+@list l0:level1
+	{mso-level-start-at:7;
+	mso-level-tab-stop:.5in;
+	mso-level-number-position:left;
+	text-indent:-.25in;}
+@list l0:level2
+	{mso-level-number-format:alpha-lower;
+	mso-level-tab-stop:1.0in;
+	mso-level-number-position:left;
+	text-indent:-.25in;}
+@list l1
+	{mso-list-id:621955822;
+	mso-list-template-ids:-1687880648;}
+@list l2
+	{mso-list-id:646667692;
+	mso-list-type:hybrid;
+	mso-list-template-ids:-728441462 67698689 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;}
+@list l2:level1
+	{mso-level-number-format:bullet;
+	mso-level-text:\F0B7;
+	mso-level-tab-stop:.5in;
+	mso-level-number-position:left;
+	text-indent:-.25in;
+	font-family:Symbol;}
+@list l2:level2
+	{mso-level-tab-stop:1.0in;
+	mso-level-number-position:left;
+	text-indent:-.25in;}
+@list l2:level3
+	{mso-level-tab-stop:1.5in;
+	mso-level-number-position:left;
+	text-indent:-.25in;}
+@list l2:level4
+	{mso-level-tab-stop:2.0in;
+	mso-level-number-position:left;
+	text-indent:-.25in;}
+@list l2:level5
+	{mso-level-tab-stop:2.5in;
+	mso-level-number-position:left;
+	text-indent:-.25in;}
+@list l2:level6
+	{mso-level-tab-stop:3.0in;
+	mso-level-number-position:left;
+	text-indent:-.25in;}
+@list l2:level7
+	{mso-level-tab-stop:3.5in;
+	mso-level-number-position:left;
+	text-indent:-.25in;}
+@list l2:level8
+	{mso-level-tab-stop:4.0in;
+	mso-level-number-position:left;
+	text-indent:-.25in;}
+@list l2:level9
+	{mso-level-tab-stop:4.5in;
+	mso-level-number-position:left;
+	text-indent:-.25in;}
+@list l3
+	{mso-list-id:975526902;
+	mso-list-type:hybrid;
+	mso-list-template-ids:1435802096 67698703 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;}
+@list l3:level1
+	{mso-level-tab-stop:.5in;
+	mso-level-number-position:left;
+	text-indent:-.25in;}
+@list l3:level2
+	{mso-level-tab-stop:1.0in;
+	mso-level-number-position:left;
+	text-indent:-.25in;}
+@list l3:level3
+	{mso-level-tab-stop:1.5in;
+	mso-level-number-position:left;
+	text-indent:-.25in;}
+@list l3:level4
+	{mso-level-tab-stop:2.0in;
+	mso-level-number-position:left;
+	text-indent:-.25in;}
+@list l3:level5
+	{mso-level-tab-stop:2.5in;
+	mso-level-number-position:left;
+	text-indent:-.25in;}
+@list l3:level6
+	{mso-level-tab-stop:3.0in;
+	mso-level-number-position:left;
+	text-indent:-.25in;}
+@list l3:level7
+	{mso-level-tab-stop:3.5in;
+	mso-level-number-position:left;
+	text-indent:-.25in;}
+@list l3:level8
+	{mso-level-tab-stop:4.0in;
+	mso-level-number-position:left;
+	text-indent:-.25in;}
+@list l3:level9
+	{mso-level-tab-stop:4.5in;
+	mso-level-number-position:left;
+	text-indent:-.25in;}
+@list l4
+	{mso-list-id:1305811547;
+	mso-list-type:hybrid;
+	mso-list-template-ids:1677090400 67698703 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;}
+@list l4:level1
+	{mso-level-tab-stop:.5in;
+	mso-level-number-position:left;
+	text-indent:-.25in;}
+@list l4:level2
+	{mso-level-number-format:alpha-lower;
+	mso-level-tab-stop:1.0in;
+	mso-level-number-position:left;
+	text-indent:-.25in;}
+@list l4:level3
+	{mso-level-number-format:roman-lower;
+	mso-level-tab-stop:1.5in;
+	mso-level-number-position:right;
+	text-indent:-9.0pt;}
+@list l4:level4
+	{mso-level-tab-stop:2.0in;
+	mso-level-number-position:left;
+	text-indent:-.25in;}
+@list l4:level5
+	{mso-level-tab-stop:2.5in;
+	mso-level-number-position:left;
+	text-indent:-.25in;}
+@list l4:level6
+	{mso-level-tab-stop:3.0in;
+	mso-level-number-position:left;
+	text-indent:-.25in;}
+@list l4:level7
+	{mso-level-tab-stop:3.5in;
+	mso-level-number-position:left;
+	text-indent:-.25in;}
+@list l4:level8
+	{mso-level-tab-stop:4.0in;
+	mso-level-number-position:left;
+	text-indent:-.25in;}
+@list l4:level9
+	{mso-level-tab-stop:4.5in;
+	mso-level-number-position:left;
+	text-indent:-.25in;}
+@list l5
+	{mso-list-id:1502042143;
+	mso-list-template-ids:-751028068;}
+@list l6
+	{mso-list-id:1605966365;
+	mso-list-type:hybrid;
+	mso-list-template-ids:14685132 67698703 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;}
+@list l6:level1
+	{mso-level-tab-stop:.5in;
+	mso-level-number-position:left;
+	text-indent:-.25in;}
+@list l6:level2
+	{mso-level-tab-stop:1.0in;
+	mso-level-number-position:left;
+	text-indent:-.25in;}
+@list l6:level3
+	{mso-level-tab-stop:1.5in;
+	mso-level-number-position:left;
+	text-indent:-.25in;}
+@list l6:level4
+	{mso-level-tab-stop:2.0in;
+	mso-level-number-position:left;
+	text-indent:-.25in;}
+@list l6:level5
+	{mso-level-tab-stop:2.5in;
+	mso-level-number-position:left;
+	text-indent:-.25in;}
+@list l6:level6
+	{mso-level-tab-stop:3.0in;
+	mso-level-number-position:left;
+	text-indent:-.25in;}
+@list l6:level7
+	{mso-level-tab-stop:3.5in;
+	mso-level-number-position:left;
+	text-indent:-.25in;}
+@list l6:level8
+	{mso-level-tab-stop:4.0in;
+	mso-level-number-position:left;
+	text-indent:-.25in;}
+@list l6:level9
+	{mso-level-tab-stop:4.5in;
+	mso-level-number-position:left;
+	text-indent:-.25in;}
+@list l7
+	{mso-list-id:1898277882;
+	mso-list-template-ids:822871964;}
+@list l7:level2
+	{mso-level-number-format:alpha-lower;
+	mso-level-tab-stop:1.0in;
+	mso-level-number-position:left;
+	text-indent:-.25in;}
+@list l8
+	{mso-list-id:2031451446;
+	mso-list-template-ids:-2051742690;}
+@list l8:level1
+	{mso-level-number-format:bullet;
+	mso-level-text:\F0B7;
+	mso-level-tab-stop:.5in;
+	mso-level-number-position:left;
+	text-indent:-.25in;
+	mso-ansi-font-size:10.0pt;
+	font-family:Symbol;}
+@list l9
+	{mso-list-id:2084135049;
+	mso-list-template-ids:2028617002;}
+@list l9:level1
+	{mso-level-start-at:8;
+	mso-level-tab-stop:.5in;
+	mso-level-number-position:left;
+	text-indent:-.25in;}
+ol
+	{margin-bottom:0in;}
+ul
+	{margin-bottom:0in;}
+-->
+  </style><!--[if gte mso 10]>
+<style>
+ /* Style Definitions */
+ table.MsoNormalTable
+	{mso-style-name:"Table Normal";
+	mso-tstyle-rowband-size:0;
+	mso-tstyle-colband-size:0;
+	mso-style-noshow:yes;
+	mso-style-parent:"";
+	mso-padding-alt:0in 5.4pt 0in 5.4pt;
+	mso-para-margin:0in;
+	mso-para-margin-bottom:.0001pt;
+	mso-pagination:widow-orphan;
+	font-size:10.0pt;
+	font-family:"Times New Roman";}
+</style>
+<![endif]--><!--[if gte mso 9]><xml>
+ <u1:shapelayout u2:ext="edit">
+  <u1:idmap u2:ext="edit" data="1"/>
+ </u1:shapelayout>
+</xml><![endif]--><!--[if gte mso 9]><xml>
+ <o:shapedefaults v:ext="edit" spidmax="3074"/>
+</xml><![endif]--><!--[if gte mso 9]><xml>
+ <o:shapelayout v:ext="edit">
+  <o:idmap v:ext="edit" data="1"/>
+ </o:shapelayout></xml><![endif]-->
+</head>
+<body lang="EN-US" link="blue" vlink="purple" style="">
+<div class="Section1"><!--
+
+
+<p class=MsoNormal><span style="font-size: 9pt">&nbsp;</span></p>
+<pre><a name="header-text">Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+&quot;License&quot;); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+&quot;AS IS&quot; BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.   </a></pre>
+<p class=MsoNormal><span style="font-size: 9pt"><br>
+&nbsp;</span></p>
+<p class=MsoNormal><span style='font-size:9.0pt'>
+<o:p>&nbsp;</o:p></span></p>
+
+-->
+<h1><st1:state><st1:place>Tuscany</st1:place></st1:state> RDB DAS
+Database Setup Utility<o:p></o:p></h1>
+<p class="MsoNormal"><u3:p>&nbsp;</u3:p></p>
+<p class="MsoNormal">This utility provides a jar file to be used by RDB
+DAS
+sample applications (web or standalone) to do database setup.&nbsp; <br>
+</p>
+<p class="MsoNormal"><br>
+So far&nbsp; the samples provided canned pre-created Derby database
+with tables and data.
+&nbsp; There was no convenient way to&nbsp; refresh&nbsp;
+table&nbsp; data&nbsp; during&nbsp; the samples&nbsp; execution.&nbsp; This
+utility&nbsp; supports Derby database at present.<o:p></o:p></p>
+<p class="MsoNormal"><u3:p>&nbsp;<br>
+The&nbsp; Database Setup Utility uses a config file to get the setup
+information and exposes following APIs:-<br>
+</u3:p></p>
+<h1><span style="font-size: 12pt; font-family: &quot;Times New Roman&quot;;">public
+DBInitHelper(String ConfigFileLocation)<u3:p></u3:p></span></h1>
+<h1><span style="font-size: 12pt; font-family: &quot;Times New Roman&quot;;">public
+DBInitHelper(InputStream ConfigFileStream)<u3:p></u3:p></span></h1>
+<h1><span style="font-size: 12pt; font-family: &quot;Times New Roman&quot;;">public void initializeDB(boolean force) - Create database tables and fill data. If force=true, all tables will be dropped and recreated.<u3:p></u3:p>
+</span></h1>
+<h1><span style="font-size: 12pt; font-family: &quot;Times New Roman&quot;;">public void
+createSchema(boolean force) - create database tables (with force=true,
+if a table pre-exists, it will be dropped and
+recreated)<u3:p></u3:p></span></h1>
+<h1><span style="font-size: 12pt; font-family: &quot;Times New Roman&quot;;">public void
+boolean deleteSchema() - delete all database tables, returns false on failure <u3:p></u3:p></span></h1>
+<h1><span style="font-size: 12pt; font-family: &quot;Times New Roman&quot;;">public void
+refreshData(boolean force) - populate tables data (with force=true, if
+data pre-exists, it will be deleted and fresh data will be inserted)<u3:p></u3:p></span></h1>
+<h1><span style="font-size: 12pt; font-family: &quot;Times New Roman&quot;;">public
+boolean deleteData() - delete data from tables, return false on failure<u3:p></u3:p></span></h1>
+<h1><span style="font-size: 12pt; font-family: &quot;Times New Roman&quot;;">public
+boolean isSchemaCreated() - will return
+true, if the tables exist in the database<u3:p></u3:p></span></h1>
+<h1><span style="font-size: 12pt; font-family: &quot;Times New Roman&quot;;">public
+boolean isDataCreated() - will return
+true, if the tables have data<u3:p></u3:p></span></h1>
+<p class="MsoNormal"><u3:p><br>
+
+<h3>Assumptions:</h3>
+TableList elemenr lists tables in proper sequence, i.e. parent tables first and then child tables.
+This sequence will be used in create,insert,delete,drop <br>to take care of referential integrity.
+<br>
+<br>
+The config file required by utility supports the following features
+through different attributes and elements. Sample xml file will be
+shown later:-</u3:p></p>
+</u3:p></p>
+<h3>createOrImport</h3>
+This attribute can have one of the
+two values- create or import. If it is set to create, the hardcoded
+classes inside the utility jar <br>
+<p class="MsoNormal"><u3:p>like CompanyData, DepartmentData will be
+used. </u3:p>If
+it is set to import, user needs to supply &lt;TablesData&gt; element in
+the config and data in tables <br>
+<u3:p></u3:p></p>
+<p class="MsoNormal"><u3:p>will be populated based on the values
+specified in this element.
+</u3:p></p>
+<h3>ConnectionInfo</h3>
+This element provides connection
+specific information - like vendor specific database URL, user name,
+password etc. If the DataSource is
+<p class="MsoNormal"><u3:p>provided by the web container, user needs to
+only fill dataSource attribute in this. In case of standalone J2SE
+samples, user needs to fill ConnectionProperties <br>
+element inside ConnectionInfo. These two ways of connection
+specification are mutually exclusive.<br>
+</u3:p></p>
+<h3>TableList</h3>
+&nbsp; This element needs to specify the
+table names required by the sample. Only these tables will be
+considered for creation, data population. This
+<p class="MsoNormal"><u3:p>gives flexibility to the user to chose the
+required set of tables based on the sample's requirement.<br>
+</u3:p></p>
+<h3>TablesData</h3>
+This element is optional. It will be
+used only in case of createOrImport=import. In this, the table name,
+column names, data types and data
+<p class="MsoNormal"><u3:p>can be conveniently specified by the user
+(check the sample xml given below). Advantage of using import instead
+of create is flexibility over the set of data <br>
+</u3:p></p>
+<p class="MsoNormal"><u3:p>to be used for the tables.</u3:p></p>
+<p class="MsoNormal"><u3:p><br>
+</u3:p></p>
+<h3>Set Up</h3>
+<br>
+To use this utility, include its jar and required database driver's jar
+in the classpath. Provide the config file used by this utility ,
+similar to the example below, in the source folder of the sample.<br>
+<h3>DBConfig.xml example</h3>
+<br>
+<p class="MsoNormal"><u3:p></u3:p></p>
+<p class="MsoNormal"><u3:p></u3:p></p>
+<p class="MsoNormal"><u3:p>&lt;?xml version="1.0" encoding="ASCII"?&gt;<br>
+&lt;!--<br>
+&nbsp; Licensed to the Apache Software Foundation (ASF) under one<br>
+&nbsp; or more contributor license agreements.&nbsp; See the NOTICE file<br>
+&nbsp; distributed with this work for additional information<br>
+&nbsp; regarding copyright ownership.&nbsp; The ASF licenses this file<br>
+&nbsp; to you under the Apache License, Version 2.0 (the<br>
+&nbsp; "License"); you may not use this file except in compliance<br>
+&nbsp; with the License.&nbsp; You may obtain a copy of the License at<br>
+<br>
+&nbsp; http://www.apache.org/licenses/LICENSE-2.0<br>
+<br>
+&nbsp; Unless required by applicable law or agreed to in writing,<br>
+&nbsp; software distributed under the License is distributed on an<br>
+&nbsp; "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY<br>
+&nbsp; KIND, either express or implied.&nbsp; See the License for the<br>
+&nbsp; specific language governing permissions and limitations<br>
+&nbsp; under the License.<br>
+&nbsp;--&gt;<br>
+&nbsp;&lt;DBConfig
+xmlns="http:///org.apache.tuscany.das.rdb/DBConfig.xsd"
+createOrImport="create"&gt; <br>
+&nbsp;&nbsp; &nbsp;<br>
+&nbsp;&nbsp;&nbsp; &lt;!--Uncomment below for web container derby
+database setup--&gt;<br>
+&nbsp;&nbsp; &nbsp;&lt;!--&lt;ConnectionInfo
+dataSource="java:comp/env/jdbc/dastest"&gt;<br>
+&nbsp;&nbsp; &nbsp;&lt;/ConnectionInfo&gt;--&gt;<br>
+&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
+&nbsp;&nbsp;&nbsp; &lt;!--Uncomment below for standalone derby database
+setup--&gt;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
+&nbsp;&nbsp; &nbsp;&lt;!--&lt;ConnectionInfo dataSource=""&gt;<br>
+&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &lt;ConnectionProperties<br>
+&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
+driverClass="org.apache.derby.jdbc.EmbeddedDriver"<br>
+&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
+databaseURL="jdbc:derby:c:/dastest; create = true"<br>
+&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
+loginTimeout="600000"/&gt;<br>
+&nbsp;&nbsp; &nbsp;&lt;/ConnectionInfo&gt;--&gt;<br>
+&nbsp;&nbsp; &nbsp;<br>
+&nbsp;&nbsp; &nbsp;&lt;!--Uncomment below for web container MySQL
+database setup--&gt;<br>
+&nbsp;&nbsp; &nbsp;&lt;!--&lt;ConnectionInfo
+dataSource="java:comp/env/jdbc/dastest"&gt;<br>
+&nbsp;&nbsp; &nbsp;&lt;/ConnectionInfo&gt;--&gt;<br>
+&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; <br>
+&nbsp;&nbsp;&nbsp; &lt;!--Uncomment below for standalone MySQL database
+setup--&gt;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
+&nbsp;&nbsp; &nbsp;&lt;!--&lt;ConnectionInfo dataSource=""&gt;<br>
+&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &lt;ConnectionProperties<br>
+&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
+driverClass="com.mysql.jdbc.Driver"<br>
+&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
+databaseURL="jdbc:mysql:///dastest?createDatabaseIfNotExist=true"<br>
+&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; userName="root"<br>
+&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
+password="mypwd"<br>
+&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
+loginTimeout="600000"/&gt;<br>
+&nbsp;&nbsp; &nbsp;&lt;/ConnectionInfo&gt;--&gt;<br>
+&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; <br>
+&nbsp;&nbsp; &nbsp;&lt;!--Uncomment below for web container DB2
+database setup--&gt;<br>
+&nbsp;&nbsp; &nbsp;&lt;!--&lt;ConnectionInfo
+dataSource="java:comp/env/jdbc/dastest"&gt;<br>
+&nbsp;&nbsp; &nbsp;&lt;/ConnectionInfo&gt;--&gt;<br>
+&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; <br>
+&nbsp;&nbsp;&nbsp; &lt;!--Uncomment below for standalone DB2 database
+setup--&gt;<br>
+&nbsp;&nbsp; &nbsp;&lt;ConnectionInfo dataSource=""&gt;<br>
+&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &lt;ConnectionProperties<br>
+&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
+driverClass="com.ibm.db2.jcc.DB2Driver"<br>
+&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
+databaseURL="jdbc:db2:DASTEST"<br>
+&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
+loginTimeout="600000"/&gt;<br>
+&nbsp;&nbsp; &nbsp;&lt;/ConnectionInfo&gt;<br>
+&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
+&nbsp;&nbsp; &nbsp;&lt;TableList&gt;<br>
+&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;
+&lt;TableName&gt;COMPANY&lt;/TableName&gt;<br>
+&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;
+&lt;TableName&gt;DEPARTMENT&lt;/TableName&gt;&nbsp;&nbsp;&nbsp;
+&nbsp;&nbsp;&nbsp; <br>
+&nbsp;&nbsp; &nbsp;&lt;/TableList&gt;<br>
+&nbsp;&nbsp; &nbsp;<br>
+&nbsp;&nbsp; &nbsp;&lt;TablesData&gt;<br>
+&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &lt;TableData TableName="COMPANY"
+Columns="'NAME'" SqlTypes="Types.VARCHAR"&gt;<br>
+&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
+&lt;TableRow&gt;'ACME Publishing'&lt;/TableRow&gt;<br>
+&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
+&lt;TableRow&gt;'Do-rite plumbing'&lt;/TableRow&gt;<br>
+&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
+&lt;TableRow&gt;'MegaCorp'&lt;/TableRow&gt;<br>
+&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &lt;/TableData&gt;<br>
+&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; <br>
+&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &lt;TableData
+TableName="DEPARTMENT" Columns="'NAME', 'LOCATION', 'DEPNUMBER'"
+SqlTypes="Types.VARCHAR, Types.VARCHAR, Types.VARCHAR"&gt;<br>
+&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
+&lt;TableRow&gt;'Advanced Technologies', 'NY', '123'&lt;/TableRow&gt;<br>
+&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;
+&lt;/TableData&gt;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
+&nbsp;&nbsp; &nbsp;&lt;/TablesData&gt;<br>
+&lt;/DBConfig&gt;<br>
+<br>
+<br>
+&nbsp;<br>
+</u3:p></p>
+</div>
+</body>
+</html>

Added: incubator/tuscany/java/das/samples/dbconfig/src/main/java/org/apache/tuscany/das/rdb/Data/TestData.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/samples/dbconfig/src/main/java/org/apache/tuscany/das/rdb/Data/TestData.java?view=auto&rev=538267
==============================================================================
--- incubator/tuscany/java/das/samples/dbconfig/src/main/java/org/apache/tuscany/das/rdb/Data/TestData.java (added)
+++ incubator/tuscany/java/das/samples/dbconfig/src/main/java/org/apache/tuscany/das/rdb/Data/TestData.java Tue May 15 10:55:01 2007
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.tuscany.das.rdb.Data;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.Timestamp;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * 
+ * Abstract superclass to refresh data in the table named tableName
+ * when the column names and sqlTypes are not specified. Methods are 
+ * also provided to query data. 
+ *
+ */
+public abstract class TestData {
+
+    protected static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd hh:ss:mm.SSS");
+
+    protected static final Timestamp TIMESTAMP = getTimestamp();
+    
+    protected Object[][] data;
+
+    protected Connection connection;
+
+    private int currentRow = -1;
+ 
+    public String tableName;
+
+    public TestData(Connection c, Object[][] customerData) {
+        this.connection = c;
+        this.data = customerData;
+    }
+
+    public int size() {
+        return data[0].length;
+    }
+
+    public int numberOfRows() {
+        return data.length;
+    }
+
+    public boolean next() {
+        ++currentRow;
+        return currentRow < numberOfRows();
+    }
+
+    public abstract String getTableName();
+
+    public Object getObject(int i) {
+        return data[currentRow][i - 1];
+    }
+
+    public void refresh() throws SQLException {
+        deleteRowsFromTable();
+        insertRows();
+    }
+
+    protected void deleteRowsFromTable() throws SQLException {
+        PreparedStatement ps = connection.prepareStatement("delete from " + getTableName());
+        ps.execute();
+        ps.close();
+    }
+
+    protected void insertRows() throws SQLException {
+        StringBuffer sql = new StringBuffer();
+        sql.append("insert into ");
+        sql.append(getTableName());
+        sql.append(" values (");
+        for (int i = 1; i < size(); i++) {
+            sql.append("?,");
+        }
+        sql.append("?)");
+        PreparedStatement ps = connection.prepareStatement(sql.toString());
+
+        while (next()) {
+            for (int i = 1; i <= size(); i++) {
+                ps.setObject(i, getObject(i));
+            }
+            ps.execute();
+            ps.clearParameters();
+        }
+        ps.close();
+    }
+
+    // Utilities
+    protected static Date getDate() {
+
+        try {
+            return DATE_FORMAT.parse("1966-12-20 00:00:00.0");
+        } catch (ParseException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    protected static Date getDate(String timeStamp) {
+
+        try {
+            return DATE_FORMAT.parse(timeStamp);
+        } catch (ParseException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    public static Timestamp getTimestamp() {
+        return new Timestamp(getDate().getTime());
+    }
+
+    public static Timestamp getTimestamp(String timeStamp) {
+        return new Timestamp(getDate(timeStamp).getTime());
+    }
+
+}

Added: incubator/tuscany/java/das/samples/dbconfig/src/main/java/org/apache/tuscany/das/rdb/Data/TestDataWithExplicitColumns.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/samples/dbconfig/src/main/java/org/apache/tuscany/das/rdb/Data/TestDataWithExplicitColumns.java?view=auto&rev=538267
==============================================================================
--- incubator/tuscany/java/das/samples/dbconfig/src/main/java/org/apache/tuscany/das/rdb/Data/TestDataWithExplicitColumns.java (added)
+++ incubator/tuscany/java/das/samples/dbconfig/src/main/java/org/apache/tuscany/das/rdb/Data/TestDataWithExplicitColumns.java Tue May 15 10:55:01 2007
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.das.rdb.Data;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+
+/**
+ * 
+ * Superclass to refresh data in the table named tableName
+ * when the column names and sqlTypes are specified. Extends 
+ * TestData.
+ *
+ */
+public class TestDataWithExplicitColumns extends TestData {
+
+    private String[] columns;
+
+    private int[] sqlTypes;
+    
+    public String getTableName(){
+    	return this.tableName;
+    }
+    
+    public void setTableName(String tableName){
+    	this.tableName = tableName;
+    }
+    
+    public TestDataWithExplicitColumns(Connection c, Object[][] data, String[] columns, int[] sqlTypes) {
+        super(c, data);
+        this.columns = columns;
+        this.sqlTypes = sqlTypes;
+    }
+
+    public TestDataWithExplicitColumns(Connection c, String tableName, Object[][] data, String[] columns, int[] sqlTypes) {
+        this(c, data, columns, sqlTypes);
+        this.setTableName(tableName);
+    }
+    
+    private String getColumn(int i) {
+        return columns[i - 1];
+    }
+
+    private int getSqlType(int i) {
+        return sqlTypes[i - 1];
+    }
+
+    // Create an insert statement of the following form ...
+    // "INSERT INTO table_name (column1, column2,...) VALUES (value1, value2,....)"
+    // This is necessary for tables with a generated column since the PK value is not provided
+    protected void insertRows() throws SQLException {
+        StringBuffer sql = new StringBuffer();
+        sql.append("insert into ");
+        sql.append(getTableName());
+
+        sql.append(" (");
+        for (int i = 1; i <= size(); i++) {
+            sql.append(getColumn(i));
+            if (i < size()) {
+                sql.append(',');
+            }
+        }
+        sql.append(" )");
+
+        sql.append(" values (");
+        for (int i = 1; i < size(); i++) {
+            sql.append("?,");
+        }
+        sql.append("?)");
+
+        PreparedStatement ps = connection.prepareStatement(sql.toString());
+
+        while (next()) {
+            for (int i = 1; i <= size(); i++) {
+                ps.setObject(i, getObject(i), getSqlType(i));
+            }
+            ps.execute();
+            ps.clearParameters();
+        }
+    }
+}

Added: incubator/tuscany/java/das/samples/dbconfig/src/main/java/org/apache/tuscany/das/rdb/dbconfig/DBConfigUtil.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/samples/dbconfig/src/main/java/org/apache/tuscany/das/rdb/dbconfig/DBConfigUtil.java?view=auto&rev=538267
==============================================================================
--- incubator/tuscany/java/das/samples/dbconfig/src/main/java/org/apache/tuscany/das/rdb/dbconfig/DBConfigUtil.java (added)
+++ incubator/tuscany/java/das/samples/dbconfig/src/main/java/org/apache/tuscany/das/rdb/dbconfig/DBConfigUtil.java Tue May 15 10:55:01 2007
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.tuscany.das.rdb.dbconfig;
+
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.tuscany.sdo.util.SDOUtil;
+
+import commonj.sdo.helper.XMLHelper;
+
+/**
+ * Config util provides config-related utilities such as loading a Config
+ * instance from an InputStream
+ * 
+ */
+public final class DBConfigUtil {
+
+    private DBConfigUtil() {
+        
+    }
+    
+    public static DBConfig loadDBConfig(InputStream dbconfigStream) {
+
+        if (dbconfigStream == null) {
+            throw new RuntimeException("Cannot load configuration from a null InputStream. "
+                    + "Possibly caused by an incorrect config xml file name");
+        }
+
+        SDOUtil.registerStaticTypes(DbconfigFactory.class);
+        XMLHelper helper = XMLHelper.INSTANCE;
+
+        try {
+            return (DBConfig) helper.load(dbconfigStream).getRootObject();
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+}

Added: incubator/tuscany/java/das/samples/dbconfig/src/main/java/org/apache/tuscany/das/rdb/dbconfig/DBConnectionHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/samples/dbconfig/src/main/java/org/apache/tuscany/das/rdb/dbconfig/DBConnectionHelper.java?view=auto&rev=538267
==============================================================================
--- incubator/tuscany/java/das/samples/dbconfig/src/main/java/org/apache/tuscany/das/rdb/dbconfig/DBConnectionHelper.java (added)
+++ incubator/tuscany/java/das/samples/dbconfig/src/main/java/org/apache/tuscany/das/rdb/dbconfig/DBConnectionHelper.java Tue May 15 10:55:01 2007
@@ -0,0 +1,151 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.tuscany.das.rdb.dbconfig;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.sql.DataSource;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+
+public class DBConnectionHelper {
+	private static final Logger logger = Logger.getLogger("DBConnectionHelper.class");
+	
+	protected DBConnectionHelper(){
+		logger.log(Level.DEBUG, "DBConnectionHelper()");
+	}
+    
+    /**
+     * Basic validation of Config for connection information and call to 
+     * connection helper to establish database connection. Connection using 
+     * DriverManager or DataSource are supported.
+     *
+     */
+    public static Connection createConnection(ConnectionInfo connectionInfo) {
+        logger.log(Level.DEBUG, "DBConnectionHelper.initializeDatasourceConnection(ConnectionInfo)");
+        
+        if (connectionInfo == null || 
+            (connectionInfo.getDataSource() == null && connectionInfo.getConnectionProperties() == null)) {
+            throw new RuntimeException("No connection has been provided and no data source has been specified");
+        }
+
+        if(connectionInfo.getDataSource() != null && connectionInfo.getConnectionProperties() != null){
+            throw new RuntimeException("Use either dataSource or ConnectionProperties. Can't use both !");
+        }
+        
+        Connection connection = null;
+        
+        if(connectionInfo.getConnectionProperties() != null){
+            connection = initializeDriverManagerConnection(connectionInfo);
+        }else{
+            connection = initializeDatasourceConnection(connectionInfo);
+        }
+        
+        return connection;
+        
+    }
+    /**
+     * Initializes a DB connection on a managed environmet (e.g inside Tomcat)
+     */
+	private static Connection initializeDatasourceConnection(ConnectionInfo connectionInfo){
+		logger.log(Level.DEBUG, "DBConnectionHelper.initializeDatasourceConnection(ConnectionInfo)");
+        
+        InitialContext ctx;
+        Connection connection;
+        
+        try {
+            ctx = new InitialContext();
+        } catch (NamingException e) {
+            throw new RuntimeException(e);
+        }
+        try {
+            DataSource ds = (DataSource) ctx.lookup(connectionInfo.getDataSource());
+            try {
+                connection = ds.getConnection();
+                if (connection == null) {
+                    throw new RuntimeException("Could not obtain a Connection from DataSource");
+                }
+                connection.setAutoCommit(true);
+                
+            } catch (SQLException e) {
+                throw new RuntimeException(e);
+            }
+        } catch (NamingException e) {
+            throw new RuntimeException(e);
+        }
+        
+        logger.log(Level.DEBUG, "DBConnectionHelper.initializeDatasourceConnection() exit");
+        return connection;
+    }
+    
+    /**
+     * Initialize a DB connection on a J2SE environment
+     * For more info, see http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/drivermanager.html
+     */
+	private static Connection initializeDriverManagerConnection(ConnectionInfo connectionInfo) {
+		logger.log(Level.DEBUG, "DBConnectionHelper.initializeDriverManagerConnection(ConnectionInfo)");
+    	
+        if (connectionInfo.getConnectionProperties() == null) {
+            throw new DataSourceInitializationException("No existing context and no connection properties");
+        }
+
+        if (connectionInfo.getConnectionProperties().getDriverClass() == null) {
+            throw new DataSourceInitializationException("No jdbc driver class specified!");
+        }
+
+        Connection connection;
+        
+        try {
+            //initialize driver and register it with DriverManager
+            Class.forName(connectionInfo.getConnectionProperties().getDriverClass());
+            
+            //prepare to initialize connection
+            String databaseUrl = connectionInfo.getConnectionProperties().getDatabaseURL();
+            String userName = connectionInfo.getConnectionProperties().getUserName();
+            String userPassword = connectionInfo.getConnectionProperties().getPassword();
+            int loginTimeout = connectionInfo.getConnectionProperties().getLoginTimeout();
+            
+            DriverManager.setLoginTimeout(loginTimeout);
+            if( (userName == null || userName.length() ==0) && (userPassword == null || userPassword.length()==0) ){
+                //no username or password suplied
+                connection = DriverManager.getConnection(databaseUrl);
+            }else{
+                connection = DriverManager.getConnection(databaseUrl, userName, userPassword);
+            }
+            
+            if(connection == null){
+                throw new DataSourceInitializationException("Error initializing connection : null");
+            }
+            
+            connection.setAutoCommit(true);
+        }catch(ClassNotFoundException cnf){
+            throw new DataSourceInitializationException("JDBC Driver '" + connectionInfo.getConnectionProperties().getDriverClass() + "' not found", cnf);
+        }catch(SQLException sqle){
+            throw new DataSourceInitializationException(sqle.getMessage(), sqle);
+        }
+        logger.log(Level.DEBUG, "DBConnectionHelper.initializeDriverManagerConnection() exit");
+        return connection;
+    }
+}

Added: incubator/tuscany/java/das/samples/dbconfig/src/main/java/org/apache/tuscany/das/rdb/dbconfig/DBDataHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/samples/dbconfig/src/main/java/org/apache/tuscany/das/rdb/dbconfig/DBDataHelper.java?view=auto&rev=538267
==============================================================================
--- incubator/tuscany/java/das/samples/dbconfig/src/main/java/org/apache/tuscany/das/rdb/dbconfig/DBDataHelper.java (added)
+++ incubator/tuscany/java/das/samples/dbconfig/src/main/java/org/apache/tuscany/das/rdb/dbconfig/DBDataHelper.java Tue May 15 10:55:01 2007
@@ -0,0 +1,687 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.tuscany.das.rdb.dbconfig;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Iterator;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+
+public class DBDataHelper {
+    private static final String CLASS_NAME = "DBDataHelper";
+
+    private final Logger logger = Logger.getLogger("DBDataHelper.class");
+
+    private final DBConfig dbConfig;
+
+    protected DBDataHelper(DBConfig dbConfig) {
+        this.logger.log(Level.DEBUG, "DBDataHelper()");
+        this.dbConfig = dbConfig;
+    }
+
+    public boolean isDatabasePopulated() {
+        boolean isPopulated = true;
+
+        this.logger.log(Level.DEBUG, CLASS_NAME + ".isDatabasePopulated()");
+
+        Iterator tableIterator = dbConfig.getTable().iterator();
+        while (tableIterator.hasNext()) {
+            Table table = (Table) tableIterator.next();
+
+            this.logger.log(Level.DEBUG, CLASS_NAME + ".isDatabasePopulated() calling isTablePopulated() for '" + table.getName() + "'");
+            isPopulated = this.isTablePopulated(table.getName());
+            if (isPopulated == false) {
+                break;
+            }
+        }
+        return isPopulated;
+    }
+
+    /**
+     * 
+     * @param tableName
+     * @return Count of rows present in the table specified by tableName
+     */
+    protected boolean isTablePopulated(String tableName) {
+        boolean isPopulated = false;
+        Connection dbConnection = null;
+        Statement dbStatement = null;
+
+        try {
+            dbConnection = DBConnectionHelper.createConnection(dbConfig.getConnectionInfo());
+            dbStatement = dbConnection.createStatement();
+            String sqlString = "select count(*) from " + tableName;
+
+            this.logger.log(Level.DEBUG, CLASS_NAME + ".isTablePopulated()=> sqlString => '" + sqlString + "'");
+
+            ResultSet rs = dbStatement.executeQuery(sqlString);
+            rs.next();
+
+            if (rs != null) {
+                this.logger.log(Level.DEBUG, CLASS_NAME + ".isTablePopulated()=> pointer set");
+            }
+
+            int count = rs.getInt(1);
+            this.logger.log(Level.DEBUG, CLASS_NAME + ".isTablePopulated()=> '" + tableName + "' => " + count);
+
+            if (count > 0) {
+                isPopulated = true;
+            }
+
+        } catch (SQLException e) {
+            // ignore and return false
+        } finally {
+            try {
+                dbStatement.close();
+            } catch (SQLException e1) {
+                // ignore and return false
+            }
+        }
+
+        return isPopulated;
+    }
+
+    public void initializeDatabaseData() {
+        Connection dbConnection = null;
+        Statement dbStatement = null;
+
+        try {
+            dbConnection = DBConnectionHelper.createConnection(dbConfig.getConnectionInfo());
+            dbStatement = dbConnection.createStatement();
+
+            Iterator tableIterator = dbConfig.getTable().iterator();
+            while (tableIterator.hasNext()) {
+                Table table = (Table) tableIterator.next();
+
+                Iterator dataIterator = table.getRow().iterator();
+                while (dataIterator.hasNext()) {
+                    String tableRow = (String) dataIterator.next();
+
+                    String sqlString = "INSERT INTO " + table.getName() + " VALUES (" + tableRow + ")";
+
+                    this.logger.log(Level.DEBUG, CLASS_NAME + ".initializeDatabaseData()=> sqlString => '" + sqlString + "'");
+
+                    try {
+                        dbStatement.executeQuery(sqlString);
+                    }catch(SQLException e){
+                        //ignore and jump to new table
+                        this.logger.log(Level.DEBUG, CLASS_NAME + ".initializeDatabaseData() - Error inserting table data : " + e.getMessage(), e);
+                    }
+
+                }
+            }
+        } catch (SQLException e) {
+            // ignore and return false
+            this.logger.log(Level.DEBUG, CLASS_NAME + ".initializeDatabaseData() - Internal error : " +  e.getMessage(), e);
+        } finally {
+            try {
+                dbStatement.close();
+            } catch (SQLException e1) {
+                // ignore and return false
+            }
+        }
+    }
+
+    // /**
+    // *
+    // * @return true, if data is present for all tables specified in Config, else
+    // * return false.
+    // */
+    // protected boolean checkDataCreated(){
+    // this.logger.log(Level.DEBUG, "DBDataHelper.checkDataCreated()");
+    // if(this.dbInitHelper.tableNames != null){
+    // for(int i=0; i<this.dbInitHelper.tableNames.size(); i++){
+    // this.logger.log(Level.DEBUG, "DBDataHelper.checkDataCreated() calling checkDataExists() for "+
+    // this.dbInitHelper.tableNames.get(i));
+    // if(checkDataExists((String)this.dbInitHelper.tableNames.get(i)) == 0){
+    // return false;
+    // }
+    // }
+    // }
+    // return true;
+    // }
+    //		
+    // /**
+    // *Create data in table only in case it is empty, for all the tables
+    // *specified in Config.
+    // */
+    // protected void checkCreateTablesData()throws Exception{
+    // if(this.dbInitHelper.tableNames != null){
+    // for(int i=0; i<this.dbInitHelper.tableNames.size(); i++){
+    // String tableName = (String)this.dbInitHelper.tableNames.get(i);
+    // if(checkDataExists(tableName) == 0){
+    // if(this.dbInitHelper.createOrImport.equals("create")){
+    // createTableData(tableName);
+    // }
+    // if(this.dbInitHelper.createOrImport.equals("import")){
+    // importTableData(tableName);
+    // }
+    // }
+    // }
+    // }
+    // }
+    //	
+    // /**
+    // *
+    // * @param tableName
+    // * @return Count of rows present in the table specified by tableName
+    // */
+    // protected int checkDataExists(String tableName){
+    // Statement s = null;
+    // try{
+    // s = this.dbInitHelper.connection.createStatement();
+    // String sqlString = "select count(*) from "+tableName;
+    //			
+    // this.logger.log(Level.DEBUG, "DBDataHelper.checkDataExists()-> sqlString:"+sqlString);
+    //			
+    // ResultSet rs = s.executeQuery(sqlString);
+    // rs.next();
+    //			
+    // if(rs != null){
+    // this.logger.log(Level.DEBUG, "DBDataHelper.checkDataExists()-> pointer set");
+    // }
+    //			
+    // int cnt = rs.getInt(1);
+    // this.logger.log(Level.DEBUG, "DBDataHelper.checkDataExists()-> "+tableName+" "+cnt);
+    // return cnt;
+    // }catch(SQLException e){
+    // return 0;//table does not exist
+    // }finally{
+    // try{
+    // s.close();
+    // }catch(SQLException e1){
+    // //ignore;
+    // }
+    // }
+    // }
+    //	
+    // /**
+    // * Test utility to print COMPANY, DEPARTMENT data to given PrintStream
+    // * @param stream
+    // * @throws SQLException
+    // */
+    // protected void readDBstdout(PrintStream stream) throws SQLException {
+    // try {
+    // Statement s = this.dbInitHelper.connection.createStatement();
+    // ResultSet rs = s.executeQuery("SELECT ID, NAME FROM COMPANY ORDER BY ID");
+    // while (rs.next()) {
+    // stream.print(rs.getString(1));
+    // stream.print(" ");
+    // stream.print(rs.getString(2));
+    // stream.print(" ");
+    // stream.println();
+    // int id = rs.getInt(1);
+    // Statement s1 = this.dbInitHelper.connection.createStatement();
+    // ResultSet rs1 = s1.executeQuery("SELECT ID, NAME, LOCATION, DEPNUMBER FROM DEPARTMENT WHERE ID=" + id);
+    // stream.println("====Company Departments");
+    // while (rs1.next()) {
+    // stream.print("\t");
+    // stream.print(rs1.getString(1));
+    // stream.print(" ");
+    // stream.print(rs1.getString(2));
+    // stream.print(" ");
+    // stream.print(rs1.getString(3));
+    // stream.print(" ");
+    // stream.print(rs1.getString(4));
+    // stream.println();
+    // }
+    // rs1.close();
+    // s1.close();
+    // stream.println();
+    // }
+    // rs.close();
+    // s.close();
+    // this.dbInitHelper.connection.commit();
+    // } catch (Exception e) {
+    // e.printStackTrace();
+    // }
+    // }
+    //
+    //	
+    // /**
+    // * Test utility to print table data for tables like COMPANY, DEPARTMENT
+    // * when logging is ON
+    // */
+    // protected void checkTableData(String tableName){
+    // Statement s = null;
+    // try{
+    // s = this.dbInitHelper.connection.createStatement();
+    // String sqlString = "select * from "+tableName;
+    //			
+    // this.logger.log(Level.DEBUG, "DBDataHelper.checkTableData()-> sqlString:"+sqlString);
+    //			
+    // ResultSet rs = s.executeQuery(sqlString);
+    //			
+    // if(rs != null){
+    // while(rs.next()){
+    // if(tableName.equals("COMPANY")){
+    // int ID = rs.getInt(1);
+    // String NAME = rs.getString(2);
+    // int EOTMID = rs.getInt(3);
+    // this.logger.log(Level.DEBUG, "COMPANY:"+ ID+","+NAME+","+EOTMID);
+    // }
+    //					
+    // if(tableName.equals("DEPARTMENT")){
+    // int ID = rs.getInt(1);
+    // String NAME = rs.getString(2);
+    // String LOCATION = rs.getString(3);
+    // String DEPNUMBER = rs.getString(4);
+    // int COMPANYID = rs.getInt(5);
+    // this.logger.log(Level.DEBUG, "DEPARTMENT:"+ ID+","+NAME+","+LOCATION+","+DEPNUMBER+","+COMPANYID);
+    // }
+    // }
+    // }
+    //			
+    // }catch(SQLException e){
+    // }finally{
+    // try{
+    // s.close();
+    // }catch(SQLException e1){
+    // //ignore;
+    // }
+    // }
+    // }
+    //	
+    // /**
+    // * Delete data from all the tables specified in Config.
+    // * Assumption:table names listed in Config are in parent first fashion
+    // * @return true upon successful data deletion, false otherwise
+    // */
+    // protected boolean deleteData(){
+    // try{
+    // Statement s = this.dbInitHelper.connection.createStatement();
+    //		
+    //			
+    // if(this.dbInitHelper.tableNames != null){
+    // //can generalize as below based on assumption
+    // String sqlString = "DELETE FROM ";
+    // for(int i=this.dbInitHelper.tableNames.size()-1; i>-1; i--){
+    // String tableName = (String)this.dbInitHelper.tableNames.get(i);
+    // s.execute(sqlString+tableName);
+    // this.logger.log(Level.DEBUG, "DBDataHelper.deleteData()->deleted "+tableName +" data");
+    // }
+    // }
+    //		
+    // s.close();
+    // this.logger.log(Level.DEBUG, "DBDataHelper.deleteData -> returning");
+    // }catch(Exception e){
+    // this.logger.log(Level.DEBUG, "DBDataHelper.deleteData ->encountered exception "+e.getMessage());
+    // return false;
+    // }
+    // return true;
+    // }
+    //	
+    // /**
+    // * Delete existing data and "create" hardcoded set of data for all tables
+    // * specified in Config based on data in classes like CompanyData,
+    // * DepartmentData...
+    // * @throws SQLException
+    // */
+    // protected void createTablesData() throws SQLException{
+    // if(this.dbInitHelper.tableNames != null){
+    // this.logger.log(Level.DEBUG, "DBDataHelper.createTablesData()->calling deleteData()");
+    //			
+    // //always force=true
+    // deleteData();
+    // for(int i=0; i<this.dbInitHelper.tableNames.size(); i++){
+    // String tableName = (String)this.dbInitHelper.tableNames.get(i);
+    //				
+    // this.logger.log(Level.DEBUG, "DBDataHelper.createTablesData()->calling createTableData() for "+tableName);
+    // createTableData(tableName);
+    // }
+    // }
+    // }
+    //	
+
+    // /**
+    // * "Import" data specified in Config into tables.
+    // * @throws SQLException
+    // */
+    // protected void importTablesData() throws SQLException{
+    // this.logger.log(Level.DEBUG, "DBDataHelper.importTablesData()");
+    // String tableName=null;
+    //		
+    // if(this.dbInitHelper.dbConfig.getTablesData() != null){
+    // TablesData tablesData = this.dbInitHelper.dbConfig.getTablesData();
+    //			
+    // List tableDataList = tablesData.getTableData();
+    //			
+    // if(tableDataList != null){
+    // for(int i=0; i<tableDataList.size(); i++){
+    // TableData tableData = (TableData)tableDataList.get(i);
+    // tableName = tableData.getTableName();
+    // this.logger.log(Level.DEBUG, "DBDataHelper.importTablesData()->calling importTableData() for "+tableName);
+    // importTableData(tableName);
+    // }
+    // }
+    // }
+    // }
+    //	
+    // /**
+    // * "Import" data specified in Config into table specified by tableName.
+    // * @throws SQLException
+    // */
+    // protected void importTableData(String tableName) throws SQLException{
+    // TestDataWithExplicitColumns testDataWithExplicitColumns = null;
+    // String[] columns=null;
+    // int[] sqlTypes=null;
+    // Object[][] data=null;
+    // TableData tableData = null;
+    //		
+    // if(this.dbInitHelper.dbConfig.getTablesData() != null){
+    // TablesData tablesData = this.dbInitHelper.dbConfig.getTablesData();
+    //			
+    // List tableDataList = tablesData.getTableData();
+    // if(tableDataList != null){
+    // for(int i=0; i<tableDataList.size(); i++){
+    // tableData = (TableData)tableDataList.get(i);
+    // String curTableName = tableData.getTableName();
+    // if(curTableName.equals(tableName)){
+    // break;
+    // }
+    // }
+    // }
+    //			
+    // if(tableData != null){
+    // this.logger.log(Level.DEBUG, "DBDataHelper.importTableData() got TableData for "+tableName);
+    // //column names
+    // columns = formColumnsArray(tableData.getColumns());
+    //				
+    // this.logger.log(Level.DEBUG, "DBDataHelper.importTableData() formed columns");
+    //				
+    // //sql data types
+    // sqlTypes = formSqlTypesArray(tableData.getSqlTypes());
+    // this.logger.log(Level.DEBUG, "DBDataHelper.importTableData() formed sqlTypes");
+    //				
+    // List tableRows = tableData.getTableRow();
+    // if(tableRows != null){
+    // //actual data to be inserted
+    // data = formData(tableRows);
+    // this.logger.log(Level.DEBUG, "DBDataHelper.importTableData() formed data");
+    // }
+    //				
+    // testDataWithExplicitColumns =
+    // new TestDataWithExplicitColumns(this.dbInitHelper.connection, tableName, data, columns, sqlTypes);
+    //				
+    // testDataWithExplicitColumns.refresh();
+    // this.logger.log(Level.DEBUG, "DBDataHelper.importTableData() - refreshed");
+    // }
+    // }
+    // }
+    //	
+    // /**
+    // *
+    // * @param columns comma separated list of column names
+    // * @return array of colum names
+    // */
+    // protected String[] formColumnsArray(String columns){
+    // Vector columnsVect = formValues(columns);
+    //		
+    // //dump vector into array
+    // String[] columnsArray = new String[columnsVect.size()];
+    // for(int i=0; i<columnsVect.size(); i++){
+    // columnsArray[i] = (String)columnsVect.get(i);
+    // }
+    // return columnsArray;
+    // }
+    //	
+    // /**
+    // *
+    // * @param curStr comma separated list of column names
+    // * @return vector of column names
+    // */
+    // protected Vector formValues(String curStr){
+    // Vector<String> resultVect = new Vector<String>();
+    // int quoteIdx;
+    // int nextQuoteIdx;
+    //
+    // while(curStr != null && curStr.length() != 0){
+    // this.logger.log(Level.DEBUG, "DBDataHelper.formValues():"+curStr);
+    // quoteIdx = curStr.indexOf("'");
+    // if(quoteIdx == -1) break;
+    //			
+    // nextQuoteIdx = curStr.indexOf("'", quoteIdx+1);
+    // if(nextQuoteIdx == -1) break;
+    //		
+    // this.logger.log(Level.DEBUG, "DBDataHelper.formValues() got:"+curStr.substring(quoteIdx+1, nextQuoteIdx));
+    //			
+    // resultVect.add(curStr.substring(quoteIdx+1, nextQuoteIdx));
+    // if(curStr.length()>nextQuoteIdx+1){
+    // curStr = curStr.substring(nextQuoteIdx+1);
+    // }
+    // else{
+    // break;
+    // }
+    // }
+    // this.logger.log(Level.DEBUG, "DBDataHelper.formValues(): returning");
+    // return resultVect;
+    // }
+    //	
+    // /**
+    // *
+    // * @param sqlTypes comma separated list of sql types
+    // * @return int array corresponding to columns' sql types
+    // */
+    // protected int[] formSqlTypesArray(String sqlTypes){
+    // Vector<Integer> typesVect = new Vector<Integer>();
+    // StringTokenizer strtok = new StringTokenizer(sqlTypes, ",");
+    //		
+    // while(strtok.hasMoreTokens()){
+    // String sqlTypeStr = strtok.nextToken();
+    //			
+    // if(sqlTypeStr.trim().equals("Types.VARCHAR")){
+    // this.logger.log(Level.DEBUG, "DBDataHelper.formSqlTypesArray(): adding varchar");
+    // typesVect.add(new Integer(java.sql.Types.VARCHAR));
+    // }
+    //			
+    // else if(sqlTypeStr.trim().equals("Types.INTEGER")){
+    // this.logger.log(Level.DEBUG, "DBDataHelper.formSqlTypesArray(): adding int");
+    // typesVect.add(new Integer(java.sql.Types.INTEGER));
+    // }
+    //			
+    // else if(sqlTypeStr.trim().equals("Types.DATE")){
+    // this.logger.log(Level.DEBUG, "DBDataHelper.formSqlTypesArray(): adding date");
+    // typesVect.add(new Integer(java.sql.Types.DATE));
+    // }
+    //			
+    // else if(sqlTypeStr.trim().equals("Types.FLOAT")){
+    // this.logger.log(Level.DEBUG, "DBDataHelper.formSqlTypesArray(): adding float");
+    // typesVect.add(new Integer(java.sql.Types.FLOAT));
+    // }
+    //			
+    // else if(sqlTypeStr.trim().equals("Types.DOUBLE")){
+    // this.logger.log(Level.DEBUG, "DBDataHelper.formSqlTypesArray(): adding double");
+    // typesVect.add(new Integer(java.sql.Types.DOUBLE));
+    // }
+    //			
+    // else if(sqlTypeStr.trim().equals("Types.DECIMAL")){
+    // this.logger.log(Level.DEBUG, "DBDataHelper.formSqlTypesArray(): adding decimal");
+    // typesVect.add(new Integer(java.sql.Types.DECIMAL));
+    // }
+    //			
+    // else if(sqlTypeStr.trim().equals("Types.ARRAY")){
+    // this.logger.log(Level.DEBUG, "DBDataHelper.formSqlTypesArray(): adding array");
+    // typesVect.add(new Integer(java.sql.Types.ARRAY));
+    // }
+    //			
+    // else if(sqlTypeStr.trim().equals("Types.BIGINT")){
+    // this.logger.log(Level.DEBUG, "DBDataHelper.formSqlTypesArray(): adding bigint");
+    // typesVect.add(new Integer(java.sql.Types.BIGINT));
+    // }
+    //			
+    // else if(sqlTypeStr.trim().equals("Types.BINARY")){
+    // this.logger.log(Level.DEBUG, "DBDataHelper.formSqlTypesArray(): adding binary");
+    // typesVect.add(new Integer(java.sql.Types.BINARY));
+    // }
+    //			
+    // else if(sqlTypeStr.trim().equals("Types.BIT")){
+    // this.logger.log(Level.DEBUG, "DBDataHelper.formSqlTypesArray(): adding bit");
+    // typesVect.add(new Integer(java.sql.Types.BIT));
+    // }
+    //			
+    // else if(sqlTypeStr.trim().equals("Types.BLOB")){
+    // this.logger.log(Level.DEBUG, "DBDataHelper.formSqlTypesArray(): adding blob");
+    // typesVect.add(new Integer(java.sql.Types.BLOB));
+    // }
+    //			
+    // else if(sqlTypeStr.trim().equals("Types.BOOLEAN")){
+    // this.logger.log(Level.DEBUG, "DBDataHelper.formSqlTypesArray(): adding boolean");
+    // typesVect.add(new Integer(java.sql.Types.BOOLEAN));
+    // }
+    //			
+    // else if(sqlTypeStr.trim().equals("Types.CHAR")){
+    // this.logger.log(Level.DEBUG, "DBDataHelper.formSqlTypesArray(): adding char");
+    // typesVect.add(new Integer(java.sql.Types.CHAR));
+    // }
+    //			
+    // else if(sqlTypeStr.trim().equals("Types.CLOB")){
+    // this.logger.log(Level.DEBUG, "DBDataHelper.formSqlTypesArray(): adding clob");
+    // typesVect.add(new Integer(java.sql.Types.CLOB));
+    // }
+    //			
+    // else if(sqlTypeStr.trim().equals("Types.DATALINK")){
+    // this.logger.log(Level.DEBUG, "DBDataHelper.formSqlTypesArray(): adding datalink");
+    // typesVect.add(new Integer(java.sql.Types.DATALINK));
+    // }
+    //			
+    // else if(sqlTypeStr.trim().equals("Types.DISTINCT")){
+    // this.logger.log(Level.DEBUG, "DBDataHelper.formSqlTypesArray(): adding distinct");
+    // typesVect.add(new Integer(java.sql.Types.DISTINCT));
+    // }
+    //			
+    // else if(sqlTypeStr.trim().equals("Types.JAVA_OBJECT")){
+    // this.logger.log(Level.DEBUG, "DBDataHelper.formSqlTypesArray(): adding java_object");
+    // typesVect.add(new Integer(java.sql.Types.JAVA_OBJECT));
+    // }
+    //			
+    // else if(sqlTypeStr.trim().equals("Types.LONGVARBINARY")){
+    // this.logger.log(Level.DEBUG, "DBDataHelper.formSqlTypesArray(): adding longvarbinary");
+    // typesVect.add(new Integer(java.sql.Types.LONGVARBINARY));
+    // }
+    //			
+    // else if(sqlTypeStr.trim().equals("Types.LONGVARCHAR")){
+    // this.logger.log(Level.DEBUG, "DBDataHelper.formSqlTypesArray(): adding longvarchar");
+    // typesVect.add(new Integer(java.sql.Types.LONGVARCHAR));
+    // }
+    //			
+    // else if(sqlTypeStr.trim().equals("Types.NULL")){
+    // this.logger.log(Level.DEBUG, "DBDataHelper.formSqlTypesArray(): adding null");
+    // typesVect.add(new Integer(java.sql.Types.NULL));
+    // }
+    //			
+    // else if(sqlTypeStr.trim().equals("Types.NUMERIC")){
+    // this.logger.log(Level.DEBUG, "DBDataHelper.formSqlTypesArray(): adding numeric");
+    // typesVect.add(new Integer(java.sql.Types.NUMERIC));
+    // }
+    //			
+    // else if(sqlTypeStr.trim().equals("Types.OTHER")){
+    // this.logger.log(Level.DEBUG, "DBDataHelper.formSqlTypesArray(): adding other");
+    // typesVect.add(new Integer(java.sql.Types.OTHER));
+    // }
+    //			
+    // else if(sqlTypeStr.trim().equals("Types.REAL")){
+    // this.logger.log(Level.DEBUG, "DBDataHelper.formSqlTypesArray(): adding real");
+    // typesVect.add(new Integer(java.sql.Types.REAL));
+    // }
+    //			
+    // else if(sqlTypeStr.trim().equals("Types.REF")){
+    // this.logger.log(Level.DEBUG, "DBDataHelper.formSqlTypesArray(): adding ref");
+    // typesVect.add(new Integer(java.sql.Types.REF));
+    // }
+    //			
+    // else if(sqlTypeStr.trim().equals("Types.SMALLINT")){
+    // this.logger.log(Level.DEBUG, "DBDataHelper.formSqlTypesArray(): adding smallint");
+    // typesVect.add(new Integer(java.sql.Types.SMALLINT));
+    // }
+    //			
+    // else if(sqlTypeStr.trim().equals("Types.STRUCT")){
+    // this.logger.log(Level.DEBUG, "DBDataHelper.formSqlTypesArray(): adding struct");
+    // typesVect.add(new Integer(java.sql.Types.STRUCT));
+    // }
+    //			
+    // else if(sqlTypeStr.trim().equals("Types.TIME")){
+    // this.logger.log(Level.DEBUG, "DBDataHelper.formSqlTypesArray(): adding time");
+    // typesVect.add(new Integer(java.sql.Types.TIME));
+    // }
+    //			
+    // else if(sqlTypeStr.trim().equals("Types.TIMESTAMP")){
+    // this.logger.log(Level.DEBUG, "DBDataHelper.formSqlTypesArray(): adding timestamp");
+    // typesVect.add(new Integer(java.sql.Types.TIMESTAMP));
+    // }
+    //			
+    // else if(sqlTypeStr.trim().equals("Types.TINYINT")){
+    // this.logger.log(Level.DEBUG, "DBDataHelper.formSqlTypesArray(): adding tinyint");
+    // typesVect.add(new Integer(java.sql.Types.TINYINT));
+    // }
+    //			
+    // else if(sqlTypeStr.trim().equals("Types.VARBINARY")){
+    // this.logger.log(Level.DEBUG, "DBDataHelper.formSqlTypesArray(): adding varbinary");
+    // typesVect.add(new Integer(java.sql.Types.VARBINARY));
+    // }
+    // else{
+    // throw new RuntimeException("Invalid SQL Type specified in TablesData in Config "+sqlTypeStr.trim());
+    // }
+    // }
+    //		
+    // //dump vector into array
+    // int[] typesArray = new int[typesVect.size()];
+    // for(int i=0; i<typesVect.size(); i++){
+    // typesArray[i] = ((Integer)typesVect.get(i)).intValue();
+    // }
+    //		
+    // this.logger.log(Level.DEBUG, "DBDataHelper.formSqlTypesArray(): returning");
+    // return typesArray;
+    // }
+    //	
+    // /**
+    // *
+    // * @param tableRows list of string, where each string has comma separated values
+    // * @return array of rows of the table
+    // */
+    // protected Object[][] formData(List tableRows){
+    // Vector currentRow;
+    // Vector <Vector>allRows = new Vector<Vector>();
+    //		
+    // for(int i=0; i<tableRows.size(); i++){
+    // String curRowStr = (String)tableRows.get(i);
+    // currentRow = formValues(curRowStr);
+    // this.logger.log(Level.DEBUG, "DBDataHelper.formData() adding in allRows");
+    // allRows.add(currentRow);
+    // }
+    //		
+    // //form 2D array
+    // Object[][]data = new Object[allRows.size()][];
+    // for(int i=0; i<allRows.size(); i++){
+    // data[i] = new Object[ ((Vector)allRows.get(i)).size()];
+    //			
+    // for(int j=0; j<((Vector)allRows.get(i)).size(); j++){
+    // data[i][j] = ((Vector)allRows.get(i)).get(j);
+    // }
+    // }
+    //		
+    // this.logger.log(Level.DEBUG, "DBDataHelper.formData() returning");
+    // return data;
+    // }
+    //
+}

Added: incubator/tuscany/java/das/samples/dbconfig/src/main/java/org/apache/tuscany/das/rdb/dbconfig/DBHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/samples/dbconfig/src/main/java/org/apache/tuscany/das/rdb/dbconfig/DBHelper.java?view=auto&rev=538267
==============================================================================
--- incubator/tuscany/java/das/samples/dbconfig/src/main/java/org/apache/tuscany/das/rdb/dbconfig/DBHelper.java (added)
+++ incubator/tuscany/java/das/samples/dbconfig/src/main/java/org/apache/tuscany/das/rdb/dbconfig/DBHelper.java Tue May 15 10:55:01 2007
@@ -0,0 +1,166 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.tuscany.das.rdb.dbconfig;
+
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Iterator;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+
+public class DBHelper {
+    private static final String CLASS_NAME = "DBHelper";
+
+    private final Logger logger = Logger.getLogger("DBHelper.class");
+
+    private final DBConfig dbConfig;
+
+    /**
+     * Constructor
+     * 
+     * @param dbInitHelper
+     */
+    protected DBHelper(DBConfig dbConfig) {
+        this.logger.log(Level.DEBUG, CLASS_NAME + "()");
+        this.dbConfig = dbConfig;
+    }
+
+    /**
+     * Check if tables specified in Config exist
+     * 
+     * @return true if all specified tables exist, false otherwise
+     */
+    protected boolean isDatabaseReady() {
+        boolean bResult = true;
+
+        this.logger.log(Level.DEBUG, CLASS_NAME + "checkTablesCreated(DBConfig)");
+
+        Connection dbConnection = null;
+        DatabaseMetaData dbMetaData = null;
+        try {
+            dbConnection = DBConnectionHelper.createConnection(dbConfig.getConnectionInfo());
+            dbMetaData = dbConnection.getMetaData();
+
+            if (dbConfig.getTable() != null && dbConfig.getTable().size() > 0) {
+                Iterator tableIterator = dbConfig.getTable().iterator();
+                while (tableIterator.hasNext()) {
+                    Table table = (Table) tableIterator.next();
+
+                    if (!dbMetaData.getTables(null, null, table.getName(), null).next()) {
+                        bResult = false;
+                    }
+
+                }
+            }
+        } catch (SQLException e) {
+            this.logger.log(Level.DEBUG, "Error retrieving database metadata", e);
+        } finally {
+            try {
+                dbConnection.close();
+            } catch (SQLException e) {
+                // ignore here
+            }
+        }
+
+        this.logger.log(Level.DEBUG, CLASS_NAME + "checkTablesCreated(DBConfig) exit");
+        return bResult;
+    }
+
+    /**
+     * Create the database tables based on dbConfig definition
+     */
+    protected void initializeDatabase() {
+        this.logger.log(Level.DEBUG, CLASS_NAME + "initializeDatabase()");
+
+        Connection dbConnection = null;
+        Statement dbStatement = null;
+        try {
+            dbConnection = DBConnectionHelper.createConnection(dbConfig.getConnectionInfo());
+            dbStatement = dbConnection.createStatement();
+
+            if (dbConfig.getTable() != null && dbConfig.getTable().size() > 0) {
+                Iterator tableIterator = dbConfig.getTable().iterator();
+                while (tableIterator.hasNext()) {
+                    Table table = (Table) tableIterator.next();
+
+                    if (table.getSQLCreate() != null && table.getSQLCreate().length() > 0) {
+                        this.logger.log(Level.DEBUG, "Creating table '" + table.getName() + "' => " + table.getSQLCreate());
+
+                        dbStatement.execute(table.getSQLCreate());
+                    }
+                }
+            }
+        } catch (SQLException e) {
+            this.logger.log(Level.DEBUG, "Error retrieving database metadata", e);
+        } finally {
+            try {
+                dbConnection.close();
+            } catch (SQLException e) {
+                // ignore here
+            }
+        }
+
+        this.logger.log(Level.DEBUG, CLASS_NAME + "initializeDatabase() exit");
+    }
+
+    /**
+     * Create the database tables based on dbConfig definition
+     */
+    protected void dropDatabaseTables() {
+        this.logger.log(Level.DEBUG, CLASS_NAME + "initializeDatabase()");
+
+        Connection dbConnection = null;
+        Statement dbStatement = null;
+        try {
+            dbConnection = DBConnectionHelper.createConnection(dbConfig.getConnectionInfo());
+            dbStatement = dbConnection.createStatement();
+
+            if (dbConfig.getTable() != null && dbConfig.getTable().size() > 0) {
+                Iterator tableIterator = dbConfig.getTable().iterator();
+                while (tableIterator.hasNext()) {
+                    Table table = (Table) tableIterator.next();
+
+                    if (table.getSQLCreate() != null && table.getSQLCreate().length() > 0) {
+                        this.logger.log(Level.DEBUG, "Creating table '" + table.getName() + "' => " + table.getSQLCreate());
+
+                        try {
+                            dbStatement.execute("DROP TABLE " + table.getName());
+                        } catch (SQLException e) {
+                            this.logger.log(Level.DEBUG, "Error droping table '" + table.getName() + "'", e);
+                        }
+                    }
+                }
+            }
+        } catch (SQLException e) {
+            this.logger.log(Level.DEBUG, "Error droping table", e);
+        } finally {
+            try {
+                dbConnection.close();
+            } catch (SQLException e) {
+                // ignore here
+            }
+        }
+
+        this.logger.log(Level.DEBUG, CLASS_NAME + "initializeDatabase() exit");
+    }
+}

Added: incubator/tuscany/java/das/samples/dbconfig/src/main/java/org/apache/tuscany/das/rdb/dbconfig/DBInitializer.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/samples/dbconfig/src/main/java/org/apache/tuscany/das/rdb/dbconfig/DBInitializer.java?view=auto&rev=538267
==============================================================================
--- incubator/tuscany/java/das/samples/dbconfig/src/main/java/org/apache/tuscany/das/rdb/dbconfig/DBInitializer.java (added)
+++ incubator/tuscany/java/das/samples/dbconfig/src/main/java/org/apache/tuscany/das/rdb/dbconfig/DBInitializer.java Tue May 15 10:55:01 2007
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.tuscany.das.rdb.dbconfig;
+
+import java.io.InputStream;
+import java.sql.Connection;
+
+/**
+ * This is the master class having public utility APIs exposed for DAS sample creater - for table and data maintainance.
+ * 
+ */
+public class DBInitializer {
+    private static final String DEFAULT_CANNED_DB_CONFIGURATION = "CannedSampleDBConfig.xml";
+
+    /**
+     * Database configuration model
+     */
+    protected DBConfig dbConfig;
+
+    /**
+     * Database connection
+     */
+    protected Connection connection;
+
+    /**
+     * To manage database connection
+     */
+    protected DBConnectionHelper dbConnectionHelper;
+
+    /**
+     * To manage database phisical structure
+     */
+    protected DBHelper dbHelper;
+
+    /**
+     * To manage database population
+     */
+    protected DBDataHelper dbDataHelper;
+
+    //private final Logger logger = Logger.getLogger("DBInitializer.class");
+
+    /**
+     * Create instance of DBInitHelper based on default canned database configuration
+     * 
+     * @param dbconfigFileLocation
+     * @throws Exception
+     */
+    public DBInitializer() {
+        InputStream dbConfigStream = this.getClass().getClassLoader().getResourceAsStream(DEFAULT_CANNED_DB_CONFIGURATION);
+        init(dbConfigStream);
+    }
+
+    /**
+     * Create instance of DBInitHelper based on Config file location
+     * 
+     * @param dbconfigFileLocation
+     * @throws Exception
+     */
+    public DBInitializer(String dbconfigFileLocation) throws Exception {
+        InputStream dbConfigStream = this.getClass().getClassLoader().getResourceAsStream(dbconfigFileLocation);
+        init(dbConfigStream);
+    }
+
+    /**
+     * Create instance of DBInitHelper based on Config stream
+     * 
+     * @param dbconfigStream
+     * @throws Exception
+     */
+    public DBInitializer(InputStream dbConfigStream) throws Exception {
+        init(dbConfigStream);
+    }
+
+    /**
+     * Initialize helper members based on Config
+     * 
+     * @param dbconfigStream
+     */
+    protected void init(InputStream dbconfigStream) {
+        dbConfig = DBConfigUtil.loadDBConfig(dbconfigStream);
+
+        dbConnectionHelper = new DBConnectionHelper();
+        dbHelper = new DBHelper(dbConfig);
+        dbDataHelper = new DBDataHelper(dbConfig);
+
+    }
+
+    /**
+     * Check if the Database and all tables have been created on the database
+     * 
+     * @return return true if tables exist, else return false.
+     */
+    public boolean isDatabaseReady() {
+        return dbHelper.isDatabaseReady();
+    }
+
+    /**
+     * 
+     * @return - return true if all tables have at least a row, false otherwise
+     */
+    public boolean isDatabasePopulated() {
+        return dbDataHelper.isDatabasePopulated();
+    }
+
+    /**
+     * Create tables and populate data.
+     * 
+     * @param clean - If true, tables will be force dropped and recreated, else it will skip table creation for pre-existing tables.
+     * @throws Exception
+     */
+    public void initializeDatabase(boolean clean) throws DatabaseInitializerException {
+        if (clean) {
+            dbHelper.dropDatabaseTables();
+        }
+        dbHelper.initializeDatabase();
+        dbDataHelper.initializeDatabaseData();
+    }
+
+    /**
+     * Populate database data
+     * 
+     * @param clean If true, table data will be droped before data is created
+     */
+    public void initializeDatabaseData(boolean clean) throws DatabaseInitializerException{
+        if (clean) {
+            initializeDatabaseData(clean);
+        }
+
+    }
+
+    /**
+     * Refresh data in tables.
+     * 
+     * @throws Exception
+     */
+    public void refreshDatabaseData() throws DatabaseInitializerException {
+        initializeDatabase(true);
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org