Differences between revisions 11 and 12
Revision 11 as of 2006-11-15 21:57:41
Size: 4579
Editor: willianmaja
Comment:
Revision 12 as of 2009-09-20 22:47:30
Size: 4579
Editor: localhost
Comment: converted to 1.6 markup
No differences found!

This Tutorial purpose is to provide a simple "how to" and give a step-by-step to build a simple aplication using DAS/SDO features from Tuscany project. Here you'll build our "CompanyWeb Sample Web Application". This sample uses Mysql and Tomcat.

A. Initial Setup:

  • 1- Install Tomcat{latest version} and Mysql{latest version}.

    2- Download dependencies and libraries

    3- Create companyweb directory in {Tomcat root}/webapps/. EX: {Tomcat root}/webapps/companyweb

    4- Create the directory {Tomcat root}/webapps/companyweb/WEB-INF/lib and put the libraries in it. Otherwise you can put them in {Tomcat root}/common/lib

    5- The required libraries are:

    • i) common-{latest version}.jar ii) ecore-{latest version}.jar iii) ecore-change-{latest version}.jariv) ecore-xmi-{lateste version}.jarv) log4j-{latest version}.jar vi) sdo-api-xxx.jar vii) tuscany-das-rdb-xxx.jar viii) tuscany-sdo-xxx.jarix) xsd-{latest version}.jar

      x) mysql-connector-java-{latest version}.jar -> This is the JDBC connector, It'll be used to connect to Mysql database.

B. Creating CompanyWeb Database

  • After the setting up your enviroment, the next step will be to create the databse where the DAS will connect and manage the transaction with the SDO features.

    1- Run the following commands in the Mysql Command Shell

    • create database companyweb; -> This command will create the CompanyWeb database

      use companyweb; -> Set the shell to work with companyweb database

    2- Create a text file and name it as "comapnyweb.sql", you should insert the following lines in this file:'

CREATE TABLE EMPLOYEE (

  • ID INTEGER NOT NULL AUTO_INCREMENT, NAME VARCHAR(30), SN VARCHAR(10), MANAGER SMALLINT, DEPARTMENTID INTEGER, PRIMARY KEY (ID)
  • );

CREATE TABLE DEPARTMENT (

  • ID INTEGER NOT NULL AUTO_INCREMENT, NAME VARCHAR(30), LOCATION VARCHAR(30), NUMBER VARCHAR(10), COMPANYID INTEGER, EOTM INTEGER, PRIMARY KEY (ID)
  • );

CREATE TABLE COMPANY (

  • ID INTEGER NOT NULL AUTO_INCREMENT, NAME VARCHAR(30), PRIMARY KEY (ID)
  • );

CREATE UNIQUE INDEX SQL060217085530980 ON COMPANY (ID ASC);

CREATE UNIQUE INDEX SQL060217085531710 ON DEPARTMENT (ID ASC);

INSERT INTO COMPANY VALUES (51, "ACME Publishing"); INSERT INTO COMPANY VALUES (52, "Do-rite plumbing"); INSERT INTO COMPANY VALUES (53, "MegaCorp");

  • 3- Run the following command in the Mysql Shell
    • source {path}/companyweb.sql -> Executes the script to create tables, constraints, etc.

C. Creating XML configuration file

  • 1- Create the file CompanyConfig.xml in the directory {Tomcat root}/webapps/companyweb/WEB-INF/classes 2- Edit it and write the following code:

<?xml version="1.0" encoding="ASCII"?> <Config xsi:noNamespaceSchemaLocation="http:///org.apache.tuscany.das.rdb/config.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

  • <Command name="all companies" SQL="select * from COMPANY" kind="Select"/>

    <Command name="all companies and departments" SQL="select * from COMPANY left outer join DEPARTMENT on COMPANY.ID = DEPARTMENT.COMPANYID" kind="Select"/>

    <Command name="all departments for company" SQL="select * from COMPANY inner join DEPARTMENT on COMPANY.ID = DEPARTMENT.COMPANYID where COMPANY.ID = ?" kind="Select"/>

    <Command name="company by id with departments" SQL="select * from COMPANY left outer join DEPARTMENT on COMPANY.ID = DEPARTMENT.COMPANYID where COMPANY.ID = ?" kind="Select"/>

    <Table tableName="COMPANY">

    • <Column columnName="ID" primaryKey="true" generated="true"/>

    </Table>

    • <Table tableName="DEPARTMENT">

      • <Column columnName="ID" primaryKey="true" generated="true"/>

      </Table>

      <Relationship name="departments" primaryKeyTable="COMPANY" foreignKeyTable="DEPARTMENT" many="true">

    • <KeyPair primaryKeyColumn="ID" foreignKeyColumn="COMPANYID"/>

    </Relationship>

</Config>

  • 3- Save the file.

D. Creating the class wich manages the DAS/SDO features

  • 1- Create the file CompanyCLient.java in the directory {Tomcat root}/webapps/companyweb/WEB-INF/classes/org/apache/tuscany/samples/das/companyweb 2- Write the following code in the file :

--HOW to make the jsp. http://people.apache.org/~kelvingoodson/das_java/RC4b/

Tuscany/TuscanyJava/DAS_Java_Overview/RDBDAS_HOWTO_HelloDASApp (last edited 2009-09-20 22:47:30 by localhost)