From a87d1fe45862c35bdf9fc351d071f3c12f962f8e Mon Sep 17 00:00:00 2001
From: lresende The DAS Java
+Samples demonstrates the DAS features and how to get started with
+them. Below a list of available samples: This stand-alone sample demonstrates DAS in the context of a simple web application.
+ This stand-alone sample demonstrates DAS in the context of a simple java application.
+ Advanced-webapp
+ DAS Web
+ This web sample demonstrates DAS advanced features in the
+ context of a simple web application using Ajax. Some of the features demonstrated are :
+ Basic CRUD, Optimistic Concurrency Control (OCC), Result Set Shape, Column Converter,
+ Integration with dbConfig
+
+This web sample demonstrates DAS advanced features in the context of a simple web application using Ajax.
+In future more features will get added.
+
+There are two options for running this sample:
+
+
+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-advanced-webapp/ to test further.
+
+Alternatively, you can deploy the sample to your own configured Tomcat installation by following the instructions below. DAS Samples
+
+
+
+
\ No newline at end of file
diff --git a/das-java/branches/das-java-beta2/samples/advanced-webapp/build.xml b/das-java/branches/das-java-beta2/samples/advanced-webapp/build.xml
new file mode 100644
index 0000000000..e8d9d5fbdf
--- /dev/null
+++ b/das-java/branches/das-java-beta2/samples/advanced-webapp/build.xml
@@ -0,0 +1,52 @@
+
+
+
+
+
+
+ Company-webapp
+
+
+
+
+
+
+ Customer
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+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.
+
+
+
+
+
+ Running the sample
+
+
+
+
+Running from Tomcat configured by the build
+
+Deploying the sample-ajax-das WAR into a Tomcat you configure yourself
+
+
+These instructions assume that you have either :
+
+
+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 .
+
+ <!-- Global Datasource for Derby ajaxdastest database --> + <Resource name="jdbc/ajaxdastest" + type="javax.sql.DataSource" auth="Container" + description="Derby database for DAS Advanced 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.
+ <!-- Global Datasource for MySQL ajaxdastest database --> + <Resource name="jdbc/ajaxdastest" + type="javax.sql.DataSource" auth="Container" + description="MySQL database for DAS Advanced sample" + maxActive="100" maxIdle="30" maxWait="10000" + username="dastest" password="dastest" + driverClassName="com.mysql.jdbc.Driver" + url="jdbc:mysql://localhost/ajaxdastest?createDatabaseIfNotExist=true"/> ++ + Requirement: MySQL service should be up with configured port open for TCPIP communication. +
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.
+ +Used for menu/submenu rendering, is quite generic and can be used to display any menu.
+ +Tuscany DAS web sample demonstrates - simple adhoc queries, DAS predefined commands execution and + some advanced features like Optimistic Concurrency Control (OCC), Converter, Result Set Shape etc. +
+Check more details by navigating menu. + Press Refresh! button anytime for database refresh. +
+ + + + \ No newline at end of file diff --git a/das-java/branches/das-java-beta2/samples/advanced-webapp/src/main/webapp/jsp/converter.jsp b/das-java/branches/das-java-beta2/samples/advanced-webapp/src/main/webapp/jsp/converter.jsp new file mode 100644 index 0000000000..a3610e7639 --- /dev/null +++ b/das-java/branches/das-java-beta2/samples/advanced-webapp/src/main/webapp/jsp/converter.jsp @@ -0,0 +1,117 @@ + + +<%-- + * 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. + --%> + +<%-- JSTL tags --%> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> +<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%> + + + + + + + + + + + +<%@ page import="java.util.*" %> + + + + + + + + + diff --git a/das-java/branches/das-java-beta2/samples/advanced-webapp/src/main/webapp/jsp/default.css b/das-java/branches/das-java-beta2/samples/advanced-webapp/src/main/webapp/jsp/default.css new file mode 100644 index 0000000000..5680fab9ed --- /dev/null +++ b/das-java/branches/das-java-beta2/samples/advanced-webapp/src/main/webapp/jsp/default.css @@ -0,0 +1,35 @@ +/* + * 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. + */ + +BODY {BACKGROUND-COLOR: #FFFFFF; COLOR: #333366; FONT-FAMILY: 'Times New Roman'} +H1 {COLOR: #6666CC; FONT-FAMILY: 'Times New Roman'; TEXT-TRANSFORM: capitalize } +H2 {COLOR: #6666CC; FONT-FAMILY: 'Times New Roman'; TEXT-TRANSFORM: capitalize } +H3 {COLOR: #6666CC; FONT-FAMILY: 'Times New Roman'; TEXT-TRANSFORM: capitalize } +H4 {COLOR: #6666CC; FONT-FAMILY: 'Times New Roman'; TEXT-TRANSFORM: capitalize } +H5 {COLOR: #6666CC; FONT-FAMILY: 'Times New Roman'; TEXT-TRANSFORM: capitalize } +H6 {COLOR: #6666CC; FONT-FAMILY: 'Times New Roman'; TEXT-TRANSFORM: capitalize } +TH {COLOR: #000000; font-weight: bold } + +#TRowEven {background-color: #ccff99} +#TRowOdd {background-color: #ffffcc} + +A:link {cursor:hand; color: #3300FF; text-decoration: none;} +A:visited {cursor:hand; color: #3300FF; text-decoration: none; } +A:active {cursor:hand; color:#FEAA02; text-decoration: none;} +A:hover {cursor:hand; color:#FEAA02;} diff --git a/das-java/branches/das-java-beta2/samples/advanced-webapp/src/main/webapp/jsp/indexAdhoc.jsp b/das-java/branches/das-java-beta2/samples/advanced-webapp/src/main/webapp/jsp/indexAdhoc.jsp new file mode 100644 index 0000000000..f212d744f1 --- /dev/null +++ b/das-java/branches/das-java-beta2/samples/advanced-webapp/src/main/webapp/jsp/indexAdhoc.jsp @@ -0,0 +1,87 @@ + + +<%-- + * 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. + --%> + +<%-- JSTL tags --%> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> +<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%> + + + + + + + + + + + +<%@ page import="java.util.*" %> + + + + + + + + + diff --git a/das-java/branches/das-java-beta2/samples/advanced-webapp/src/main/webapp/jsp/indexCommand.jsp b/das-java/branches/das-java-beta2/samples/advanced-webapp/src/main/webapp/jsp/indexCommand.jsp new file mode 100644 index 0000000000..55dcb56e38 --- /dev/null +++ b/das-java/branches/das-java-beta2/samples/advanced-webapp/src/main/webapp/jsp/indexCommand.jsp @@ -0,0 +1,85 @@ + + +<%-- + * 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. + --%> + +<%-- JSTL tags --%> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> +<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%> + + + + + + + + + + + +<%@ page import="java.util.*" %> + + + + + + + + + diff --git a/das-java/branches/das-java-beta2/samples/advanced-webapp/src/main/webapp/jsp/main.css b/das-java/branches/das-java-beta2/samples/advanced-webapp/src/main/webapp/jsp/main.css new file mode 100644 index 0000000000..264facc985 --- /dev/null +++ b/das-java/branches/das-java-beta2/samples/advanced-webapp/src/main/webapp/jsp/main.css @@ -0,0 +1,120 @@ +/* + * 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. + */ + +body +{ + margin: 0px; + border: 0px; + padding: 0px; + font-family: Verdana, Arial, Sans-Serif; + font-size: 0px; +} + +img +{ + border: none 0px #ffffff; +} + +h1 +{ + background-color: #ffcc00; + border-bottom: solid 1px #333333; + padding: 5px; + margin: 0px; + font-size: x-large; +} + +h2 +{ + font-size: large; +} + +p +{ + font-size: small; +} + +/* Real menu */ +ul, li +{ + font-size: small; + margin-top: 0px; + margin-right: 0px; + margin-bottom: 0px; + display: block; +} + +ul +{ + width: 130px; + border: solid 1px #333333; + border-top: solid 5px #333333; + border-right: solid 2px #333333; + padding: 0px; +} + +li ul +{ + display: none; + position: absolute; + margin-left: 100px; + margin-top: -20px; +} + +li a +{ + padding: 2px; + text-decoration: none; + color: #000000; + background-color: #ffffee; + width: 100%; + display: block; + border-bottom: dashed 1px #333333; + text-indent: 2px; + font-size: small; +} + +li a:hover +{ + background-color: #ffcc00; + font-weight: bold; + border-bottom: solid 1px #333333; +} + +li +{ + float: left; + width: 98%; +} + +a.hassubmenu +{ + background-image: url(../img/lay_dmnuhassub.gif); + background-repeat: no-repeat; + background-position: 120px 7px; +} + +#mainmenu +{ + margin: 10px; + margin-left: 5px; + float: left; + border-bottom: solid 2px #333333; + margin-bottom: 100%; +} \ No newline at end of file diff --git a/das-java/branches/das-java-beta2/samples/advanced-webapp/src/main/webapp/jsp/occ.jsp b/das-java/branches/das-java-beta2/samples/advanced-webapp/src/main/webapp/jsp/occ.jsp new file mode 100644 index 0000000000..ed5a7ee0c1 --- /dev/null +++ b/das-java/branches/das-java-beta2/samples/advanced-webapp/src/main/webapp/jsp/occ.jsp @@ -0,0 +1,77 @@ + + +<%-- + * 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. + --%> + +<%-- JSTL tags --%> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> +<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%> + + + + + + + + + + + +<%@ page import="java.util.*" %> + + + + + + + + + diff --git a/das-java/branches/das-java-beta2/samples/advanced-webapp/src/main/webapp/jsp/rss.jsp b/das-java/branches/das-java-beta2/samples/advanced-webapp/src/main/webapp/jsp/rss.jsp new file mode 100644 index 0000000000..2d217d68b3 --- /dev/null +++ b/das-java/branches/das-java-beta2/samples/advanced-webapp/src/main/webapp/jsp/rss.jsp @@ -0,0 +1,78 @@ + + +<%-- + * 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. + --%> + +<%-- JSTL tags --%> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> +<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%> + + + + + + + + + + + +<%@ page import="java.util.*" %> + + + + + + + + + diff --git a/das-java/branches/das-java-beta2/samples/advanced-webapp/src/main/webapp/xsl/company.xsl b/das-java/branches/das-java-beta2/samples/advanced-webapp/src/main/webapp/xsl/company.xsl new file mode 100644 index 0000000000..99d9dc1fad --- /dev/null +++ b/das-java/branches/das-java-beta2/samples/advanced-webapp/src/main/webapp/xsl/company.xsl @@ -0,0 +1,44 @@ + + + +COMPANYID | +COMPANYNAME | +
---|---|
+ |
+
+ |
+
COMPANYID | +COMPANYNAME | +||||
---|---|---|---|---|---|
+ |
+
+ |
+
DEPID | +DEPNAME | +
---|---|
+ |
+
+ |
+
ID | +LASTNAME | +ADDRESS | +
---|---|---|
+ |
+
+ |
+
+ |
+
+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:
+
+
+
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 (default) accessed via a DataSource.
+ +There are two options for running this sample:
+ ++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/company-webapp/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-company-webapp/ +to test further. +
+ ++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 - Derby + ++ <!-- 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.
+ <!-- Global Datasource for MySQL dastest database --> + <Resource name="jdbc/dastest" + type="javax.sql.DataSource" auth="Container" + description="MySQL database for DAS Company sample" + maxActive="100" maxIdle="30" maxWait="10000" + username="dastest" password="dastest" + driverClassName="com.mysql.jdbc.Driver" + url="jdbc:mysql://localhost/dastest?createDatabaseIfNotExist=true"/> ++ + Requirement:MySQL service should be up with configured port open for TCPIP communication.
+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.
+ + + + diff --git a/das-java/branches/das-java-beta2/samples/company-webapp/src/main/java/org/apache/tuscany/samples/das/companyweb/CompanyClient.java b/das-java/branches/das-java-beta2/samples/company-webapp/src/main/java/org/apache/tuscany/samples/das/companyweb/CompanyClient.java new file mode 100644 index 0000000000..d0519ecc08 --- /dev/null +++ b/das-java/branches/das-java-beta2/samples/company-webapp/src/main/java/org/apache/tuscany/samples/das/companyweb/CompanyClient.java @@ -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.samples.das.companyweb; + +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Random; + +import org.apache.tuscany.das.rdb.Command; +import org.apache.tuscany.das.rdb.DAS; + +import commonj.sdo.DataObject; + +public class CompanyClient { + + private Random generator = new Random(); + + private DAS das = DAS.FACTORY.createDAS(getConfig("CompanyConfig.xml")); + + public final List getCompanies() { + + Command read = das.getCommand("all companies"); + DataObject root = read.executeQuery(); + return root.getList("COMPANY"); + + } + + public final List getCompaniesWithDepartments() { + + Command read = das.getCommand("all companies and departments"); + DataObject root = read.executeQuery(); + return root.getList("COMPANY"); + } + + public final List getDepartmentsForCompany(int id) { + Command read = das.getCommand("all departments for company"); + read.setParameter(1, new Integer(id)); + DataObject root = read.executeQuery(); + return root.getList("COMPANY"); + } + + public final void addDepartmentToFirstCompany() { + Command read = das.getCommand("all companies and departments"); + DataObject root = read.executeQuery(); + DataObject firstCustomer = root.getDataObject("COMPANY[1]"); + + DataObject newDepartment = root.createDataObject("DEPARTMENT"); + newDepartment.setString("NAME", "Default Name"); + firstCustomer.getList("departments").add(newDepartment); + + das.applyChanges(root); + + } + + public final void deleteDepartmentsFromFirstCompany() { + + // This section gets the ID of the first Company just so I can + // demonstrate a parameterized command next + Command readAll = das.getCommand("all companies and departments"); + DataObject root = readAll.executeQuery(); + int idOfFirstCustomer = root.getInt("COMPANY[1]/ID"); + System.out.println("ID of first company is: " + idOfFirstCustomer); + + // Read a specific company based on the known ID + Command readCust = das.getCommand("company by id with departments"); + readCust.setParameter(1, new Integer(idOfFirstCustomer)); + root = readCust.executeQuery(); + + // Delete all the comany's departments from the graph + DataObject firstCustomer = root.getDataObject("COMPANY[1]"); + + // Shallow copy of list for deleting. This is required to avoid the + // dreaded + // ConcurrentModificationException since #delete operation also removes + // from the original list + List allDepartments = new ArrayList(firstCustomer.getList("departments")); + + Iterator i = allDepartments.iterator(); + DataObject department; + while (i.hasNext()) { + department = (DataObject) i.next(); + System.out.println("Deleting department named: " + department.getString("NAME")); + department.delete(); + } + + das.applyChanges(root); + + } + + public final void changeFirstCompanysDepartmentNames() { + + // This section gets the ID of the first Company just so I can + // demonstrate a parameterized command next + Command readAll = das.getCommand("all companies and departments"); + DataObject root = readAll.executeQuery(); + int idOfFirstCustomer = root.getInt("COMPANY[1]/ID"); + System.out.println("ID of first company is: " + idOfFirstCustomer); + + // Read a specific company based on the known ID + Command readCust = das.getCommand("company by id with departments"); + readCust.setParameter(1, new Integer(idOfFirstCustomer)); + root = readCust.executeQuery(); + + // Modify all the comany's department names + DataObject firstCustomer = root.getDataObject("COMPANY[1]"); + Iterator i = firstCustomer.getList("departments").iterator(); + DataObject department; + while (i.hasNext()) { + department = (DataObject) i.next(); + System.out.println("Modifying department: " + department.getString("NAME")); + department.setString("NAME", getRandomDepartmentName()); + } + das.applyChanges(root); + + } + + + public void releaseResources() { + das.releaseResources(); + } + + // Utilities + + private String getRandomDepartmentName() { + int number = generator.nextInt(1000) + 1; + return "Dept-" + number; + } + + private InputStream getConfig(String fileName) { + return getClass().getClassLoader().getResourceAsStream(fileName); + } + +} diff --git a/das-java/branches/das-java-beta2/samples/company-webapp/src/main/java/org/apache/tuscany/samples/das/companyweb/CompanyDBInit.java b/das-java/branches/das-java-beta2/samples/company-webapp/src/main/java/org/apache/tuscany/samples/das/companyweb/CompanyDBInit.java new file mode 100644 index 0000000000..edd62e6f30 --- /dev/null +++ b/das-java/branches/das-java-beta2/samples/company-webapp/src/main/java/org/apache/tuscany/samples/das/companyweb/CompanyDBInit.java @@ -0,0 +1,70 @@ +/* + * 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.samples.das.companyweb; + +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintWriter; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.tuscany.das.rdb.dbconfig.DBInitializer; + +public class CompanyDBInit extends HttpServlet { + private static final long serialVersionUID = -4795999792460944805L; + private static final String dbConfigFile = "CompanyWebDBConfig.xml"; + + public void init() throws ServletException { + try { + DBInitializer dbInitializer; + dbInitializer = new DBInitializer(getConfig(dbConfigFile)); + if (! dbInitializer.isDatabaseReady()) { + dbInitializer.initializeDatabase(true); + } + } catch (Exception e) { + + e.printStackTrace(); + log(e.toString(), e); + throw new ServletException(e); + } + } + + /* + * (non-Java-doc) + * + * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest arg0, HttpServletResponse arg1) + */ + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + response.setContentType("text/html"); + + PrintWriter out = response.getWriter(); + + out.println(); + out.println("+This stand-alone sample demonstrates the RDB Data Access Service in the context of a simple java application. +
+ ++The sample will run and output the following: +
+ ++
+Buildfile: build.xml + +run: + [java] ************* Initializing database ************* + [java] ** DB type : derby + [java] ** Database : jdbc:derby:target/dastest; create = true + [java] ** User : + [java] ** Password : + [java] ************************************************ + [java] Setting up for derby run! + [java] Dropping tables + [java] Dropping procedures + [java] Creating tables + [java] Creating procedures + [java] Inserting data in tables + [java] Database setup complete! + [java] + [java] Result:select all customers + [java] ID:1 LASTNAME:John ADDRESS:USA + [java] ID:2 LASTNAME:Amita ADDRESS:INDIA + [java] ID:3 LASTNAME:Patrick ADDRESS:UK + [java] ID:4 LASTNAME:Jane ADDRESS:UN + [java] + [java] Result:insert new customer + [java] ID:1 LASTNAME:John ADDRESS:USA + [java] ID:2 LASTNAME:Amita ADDRESS:INDIA + [java] ID:3 LASTNAME:Patrick ADDRESS:UK + [java] ID:4 LASTNAME:Jane ADDRESS:UN + [java] ID:5 LASTNAME:Jenny ADDRESS:USA + [java] + [java] Result:update first customer + [java] ID:1 LASTNAME:BlueBerry ADDRESS:USA + [java] ID:2 LASTNAME:Amita ADDRESS:INDIA + [java] ID:3 LASTNAME:Patrick ADDRESS:UK + [java] ID:4 LASTNAME:Jane ADDRESS:UN + [java] ID:5 LASTNAME:Jenny ADDRESS:USA + [java] + [java] Result:delete last customer + [java] Deleting customer named: Jenny + [java] ID:1 LASTNAME:BlueBerry ADDRESS:USA + [java] ID:2 LASTNAME:Amita ADDRESS:INDIA + [java] ID:3 LASTNAME:Patrick ADDRESS:UK + [java] ID:4 LASTNAME:Jane ADDRESS:UN + +BUILD SUCCESSFUL ++ + +
+Observation:The build.xml ant file only works on DAS Java binary distribution. +
+ + + +
+The sample is pre-configured to run using an embedded Derby database.Follow below instructions to run the sample on another database (e.g MySQL).
+
+Observations: +
This utility provides a jar file to be used by RDB DAS +sample applications (web or standalone) to do database setup.
+ +
+So far the samples provided canned pre-created Derby database with tables
+and data. There was no convenient way to refresh table
+data during the samples execution. This utility supports
+APIs
<table> element lists tables in proper sequence, i.e.
+parent tables first and then child tables. This sequence will be used in
+create,insert,delete,drop
+to take care of referential integrity.
+
+The config file required by utility supports the following features through
+different attributes and elements. Sample xml file is shown at the end.
This element
+provides connection specific information - like vendor specific database URL,
+user name, password etc. If the DataSource is
+element inside ConnectionInfo. These two ways of connection specification are
+mutually exclusive.
+
+
This
+element needs to specify the table names required by the sample. Only these
+tables will be considered for creation, data population. This
+
+
+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.
<!--
+ +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.
+ +-->
+ +<DBConfig +xmlns="http:///org.apache.tuscany.das.rdb/dbconfig.xsd">
+ +<ConnectionInfo>
+ +<ConnectionProperties +
+ +driverClass="org.apache.derby.jdbc.EmbeddedDriver" +
+ +databaseURL="jdbc:derby:target/dastest; +create = true"
+ +loginTimeout="600000"/>
+ +</ConnectionInfo>
+ +<Table name="COMPANY"
+ +SQLCreate="CREATE +TABLE COMPANY (ID INT PRIMARY KEY NOT NULL, NAME VARCHAR(30), +EOTMID INTEGER)" >
+ +<row>51, 'ACME +Publishing', 0</row>
+ +<row>52, +'Do-rite plumbing', 0</row>
+ +<row>53, 'MegaCorp', 0</row>
+ +</Table>
+ +<Table name="DEPARTMENT"
+ +SQLCreate="CREATE +TABLE DEPARTMENT (ID INT PRIMARY KEY NOT NULL GENERATED ALWAYS AS IDENTITY, +NAME
+ +VARCHAR(30),LOCATION +VARCHAR(30), DEPNUMBER VARCHAR(10),COMPANYID INT)" >
+ +<row>'Advanced +Technologies', 'NY', '123', 1</row>
+ +<row>'Default +Name', '', '', 51</row>
+ +<row>'Default +Name', '', '', 51</row>
+ +<row>'Default +Name', '', '', 51</row>
+ +<row>'Default +Name', '', '', 51</row>
+ +<row>'Default +Name', '', '', 51</row>
+ +<row>'Default +Name', '', '', 51</row>
+ +</Table>
+ +<Table name="EMPLOYEE"
+ +SQLCreate="CREATE +TABLE EMPLOYEE (ID INT PRIMARY KEY NOT NULL GENERATED ALWAYS AS IDENTITY,NAME
+ +VARCHAR(30),SN +VARCHAR(10), MANAGER SMALLINT, DEPARTMENTID INT)" >
+ +<row>'John +Jones','E0001',0,12</row>
+ +<row>'Mary +Smith','E0002',1,null</row>
+ + <row>'Jane
+Doe','E0003',0,12</row>
<row>'Al
+Smith','E0004',1,12</row>
</Table>
+ +</DBConfig>
+ +mvn
[INFO] ---------------------------------------------------------------------------- +[INFO] Reactor Summary: +[INFO] ---------------------------------------------------------------------------- +[INFO] Tuscany Testing in Tomcat .............................. SUCCESS [0.961s] +[INFO] Tuscany Testing Tomcat DAS Sample - Companyweb ......... SUCCESS [1:09.771s] +[INFO] Tuscany Testing Ajax DAS Web Sample .................... SUCCESS [47.458s] +[INFO] ---------------------------------------------------------------------------- +[INFO] ---------------------------------------------------------------------------- +[INFO] BUILD SUCCESSFUL
+[INFO] ---------------------------------------------------------------------------- +[INFO] Total time: 1 minute 59 seconds +[INFO] Finished at: Sun Jun 10 01:23:19 VET 2007 +[INFO] Final Memory: 9M/17M +[INFO] ----------------------------------------------------------------------------
+
mvn clean
.Note
+Because the html unit tests execute multiple user actions that change the contents of the database tables, is recommended +that you always run these tests in a clean environment (after a mvn clean), +otherwise you may experience failure on some tests as the expected result data might have been affected by previous test runs.
+ + \ No newline at end of file diff --git a/das-java/branches/das-java-beta2/samples/testing/tomcat/server.xsl b/das-java/branches/das-java-beta2/samples/testing/tomcat/server.xsl new file mode 100644 index 0000000000..b53d1d50c7 --- /dev/null +++ b/das-java/branches/das-java-beta2/samples/testing/tomcat/server.xsl @@ -0,0 +1,51 @@ + +