Tuscany RDB DAS Companyweb Sample

 

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

 

The application starts with a 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 some relationship manipulation (adding a Department associates that Department with the Company).  The sample runs on Tomcat 6.0 and employs a Derby database accessed via a DataSource.

Running the sample

There are two options for running this sample:

 

  1. Run from Tomcat configured by the build
  2. Deploying the CompanyWeb WAR into a Tomcat you configure yourself

Running from Tomcat configured by the build

You need to download the Tuscany RDB DAS source distribution and run maven build to use this option. When you build using maven from the source root {SRC_ROOT} directory, the sample war file is created under {SRC_ROOT}/samples/companyweb/target. This sample application is deployed to an instance of Tomcat as part of our automated sample testing.  For this, follow readme.htm instructions from {SRC_ROOT}/samples/testing/tomcat. This will in-effect run the htmlunit tests on the sample. The sample deployed on Tomcat instance will be ready this way and you can just point your browser to http://localhost:8080/sample-companyweb/ to test further.

Deploying the CompanyWeb WAR into a Tomcat you configured yourself

Alternatively, you can deploy the sample to your own configured Tomcat installation by following the instructions below.  These instructions assume that you have either 1) downloaded the Tuscany binary distribution or 2) Downloaded the Tuscany source and run maven build, see the following link for more details steps on how to build DAS Sample applications http://incubator.apache.org/tuscany/das-java-developer-guide.html .

Set Up

  1. Download and install the most recent stable version of Tomcat 6.0.  You can find it here: http://tomcat.apache.org/download-60.cgi
  2. Download 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 (version).jar
  3. Stop Tomcat
  4. Copy derby(version).jar (from the derby distribution) to {Tomcat_Home} /lib: - derby-10.1.2.1.jar
  5. Add the sample war file to {Tomcat_Home}/webapps
    1. sample-companyweb.war
  6. 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:{absolute path}Databases/dastest;create=true"/>

 

 Requirement: You must include the absolute path to the “Databases” directory in the above url attribute.  Fore example:

 

         url="jdbc:derby:c:\apache-tomcat-6.0.13\Databases/dastest;create=true"/>

 

As the new utility, dbConfig is embedded in this sample war, the Derby database “dastest” will get created with required tables and data when the web application gets loaded for the first time in tomcat.

 

  1. Start tomcat and point your browser to: http://localhost:8080/sample-companyweb/

 

example: http://localhost:8080/sample-companyweb/

 

Sample Architecture

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

 

 

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 DAS accepts directives (commands) from the CompanyClient and reads and writes to the derby database instance appropriately.