Copyright (c) 2005 The Apache Software Foundation or its licensors, as applicable.

Licensed 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.

Tuscany RDB DAS Sample

 

This stand-alone sample demonstrates usage of the SDO RDB Data Access Service in the context of a simple web application.

 

The application starts with a canned database of Companies and their related Departments.  Through the web page interface, a user can:

 

  1. Display all Companies in the database
  2. Display all Companies and related Departments
  3. Add a new Department to a Company
  4. Delete all Departments from a Company
  5. Change the names of Departments in a Company

 

So, this simple application covers all CRUD operations as well as the some relationship manipulation (adding a Department associates that Department with the Company).  The sample runs on Tomcat 5.5 and uses Derby database.  Access to the database is via a DataSource.

Set Up

  1. Download and install the most recent stable version of Tomcat 5.5.  You can find it here: http://tomcat.apache.org/download-55.cgi
  2. Down load the most recent official release of Derby from here: http://db.apache.org/derby/index.html.  The only file you’ll need from this download is derby.jar
  3. Stop Tomcat
  4. Move the following files (details in appendix) to {Tomcat_Home}/common/lib:
    1. tuscany-das-rdb-SNAPSHOT.jar
    2. sdo-api-SNAPSHOT.jar
    3. tuscany-sdo-impl-SNAPSHOT.jar
    4. xsd{latest version}.jar
    5. ecore-{latest version}..jar
    6. ecore-change-{latest version}..jar
    7. ecore-xmi-{latest version}.jar
    8. common-{latest version}.jar
    9. derby.jar
  5. Add the following files to {Tomcat_Home}/work
    1. companyWeb-SNAPSHOT.war
    2. CompanyAppGbl.xml
  6. Install the canned Derby database by copying the dastest directory to {Tomcat_Home}/Databases.  The “dastest” directory is found at /java/samples/das/companyweb.  So, just copy this directory, create a “Databases” directory from {Tomcat Home} and drop in the “dastest” folder with all it contents.
  7. Define a DataSource by adding a datasource definition to {Tomcat_Home}/conf/server.xml.
    1. Find the end-of-section marker </GlobalNamingResources> and add the following lines just above it:

 

        <!-- Global Datasource for Derby dastest database -->
         <Resource name="jdbc/dastest"
              type="javax.sql.DataSource"  auth="Container"
              description="Derby database for DAS Company sample"
              maxActive="100" maxIdle="30" maxWait="10000"
              username="" password="" 
              driverClassName="org.apache.derby.jdbc.EmbeddedDriver"
              url="jdbc:derby:Databases/dastest"/>
                       
  1.   Start tomcat and
    1. go to the manager console http://localhost:8080/manager/html
    2. Scroll down to the “deploy” section and enter the following:

 

Context Path (optional):      /CompanyApp
XML Configuration file URL:   work/CompanyAppGbl.xml
WAR or Directory URL:         work/CompanyApp.war
 
    1. Hit the “deploy” button

 

  1. Get to the sample application by clicking the named application in the “path” column of the application sectiom of the manager console.  Alternatively, you can point your browser to http://localhost:8080/CompanyApp/

 

Sample Architecture

This is a simple, single-page, web application.  The main components of this application are:

  • The RDB Data Access Service (DAS)
  • SDO
  • CompanyClient.java
  • Company.jsp
  • The canned Derby database

 

 

The CompanyClient uses the DAS directly and provides high-level services to the jsp such as:

public final List getCompanies()

This is a good place to look for how you might use the DAS in your own application.

 

The Company.jsp responds to client interaction by invoking services of the CompanyClient.  It receives data from the CompanyClient as SDO data graphs and manipulates SDOs directly to display data.

 

The canned Derby database comes preloaded with Companies and related Departments.  The database instance is a simple file folder.

 

The DAS accepts directives (commands) from the CompanyClient and reads and writes to the derby database instance appropriately.

 

Appendix

 

The following specifies where you can find the dependency jars you need to run this sample.  These jars are available only after you have successfully downloaded and build Tuscany/java.  Instructions for building can be found here:

https://svn.apache.org/repos/asf/incubator/tuscany/java/BUILDING.txt

 

Dendendency jar locations:

  • tuscany-das-rdb-SNAPSHOT.jar – /java/das/rdb/target
  • sdo-api-SNAPSHOT.jar – /java/spec/sdo/target
  • tuscany-sdo-impl-SNAPSHOT.jar – /java/sdo/impl/target
  • xsd{latest version}.jar – {user}/.m2/repository/org/eclipse/xsd
  • ecore-{latest version}.jar – {user}/.m2/repository/org/eclipse/emf/ecore
  • ecore-change-{latest version}.jar – {user}/.m2/repository/org/eclipse/emf/ecore-change
  • ecore-xmi-{latest version}.jar jar – {user}/.m2/repository/org/eclipse/emf/ecore-xmi
  • common-{latest version}.jar jar – {user}/.m2/repository/org/eclipse/emf/common
  • derby.jar

 

Conventions:

  • {user} refers the directory where Maven2 is installed on your machine.  On my machine, “{user}” is “C:\Documents and Settings\Administrator”
  • {Tomcat_Home} refers to the directory that Tomcat is installed on your machine.  On my machine, this is “C:\Program Files\Apache Software Foundation\Tomcat 5.5”
  • {latest version} means the tag associated with the latest version available in the maven2 repository.  For example the version of ecore-{latest version}.jar that I used for testing this sample is “ecore-2.2.0-I200602160000.jar”