Tuscany RDB DAS Ajax web Sample

 

This web sample demonstrates DAS advanced features in the context of a simple web application using Ajax.

The application user can navigate the menu to see examples of different DAS features.
The application uses “dbConfig” utility to create canned
Derby database with required tables and populate initial data in them. For refreshing database data to initial state, user can click on Refresh Button.
 

            Adhoc Query (CRUD operations on COMPANY and DEPARTMENT using adhoc Sql statements)

            DAS Command (CRUD operations on COMPANY and DEPARTMENT using DAS config commands)

            Advanced Features

►Optimistic Concurrency Control (Using BOOK. NAME)

Converter (Using CUSTOMER.LASTNAME)

Result Set Shape (Using CUSTOMER table)

In future more features will get added.

 

Running the sample

There are two options for running this sample:

 

  1. Run from Tomcat configured by the build
  2. Deploying the sample-ajax-das 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/sample-ajax-das/target. This sample application is deployed to an instance of Tomcat as part of our automated sample testing.  For this, follow instructions from reademe.htm 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-ajax-das/ to test further.

Deploying the sample-ajax-das 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 to 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 5.5 or Tomcat 6.  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}/common/lib (for Tomcat 5.5) or to {Tomcat_Home}/ lib (for Tomcat 6) – e.g. derby-10.1.2.1.jar.
  5. Add the sample war file to {Tomcat_Home}/webapps
    1. sample-ajax-das.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 ajaxdastest database -->

         <Resource name="jdbc/ajaxdastest"

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/ajaxdastest;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/ajaxdastest;create=true "/>

        

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

 

 

Sample Architecture

 

The design is modular and reusable by other web samples. There are java servlet, other java classes, jsp, javascript, xml, xsl, css and html files.

 

Client Side Files

Javascripts

Ajax.js and dasmenu.js are generic (not DAS specific) and reusable by any web sample.

  • Ajax.js

Set response handler when request is passed to servlet. Response handler’s  job is transform xml response using xsl into html or plain text based on the example’s requirement.

  • Dasmenu.js

Used for menu/submenu rendering, is quite generic and can be used to display any menu.

 

HTMLs & jsps (DAS specific files)

DASMenu.html and DASWebSampleFrame.html are for giving frame and menu to web sample. DASMenu.html calls required .jsps like indexAdhoc.jsp, indexCommand.jsp, occ.jsp, converter.jsp. These jsps are all DAS specific. The .jsp file is responsible for deciding the DAS config file required by current sample and relevant .xsl file.

 

Serverside files

 

CommandServlet.java and ServiceProcessor.java

Used for invoking required service and returning results back to ajax.js. These files are not DAS specific.

 

DASQueryProcessor.java

Specific to DAS sample, has logic to invoke required sample example.