summaryrefslogtreecommitdiffstats
path: root/tags/java-M1-20060522/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework
diff options
context:
space:
mode:
Diffstat (limited to 'tags/java-M1-20060522/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework')
-rw-r--r--tags/java-M1-20060522/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/DB2Setup.java35
-rw-r--r--tags/java-M1-20060522/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/DasTest.java155
-rw-r--r--tags/java-M1-20060522/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/DatabaseSetup.java238
-rw-r--r--tags/java-M1-20060522/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/DerbySetup.java42
-rw-r--r--tags/java-M1-20060522/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/JavaStoredProcs.java79
-rw-r--r--tags/java-M1-20060522/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/MySQLSetup.java96
-rw-r--r--tags/java-M1-20060522/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/RelationshipData.java81
-rw-r--r--tags/java-M1-20060522/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/TestData.java87
-rw-r--r--tags/java-M1-20060522/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/TestDataWithExplicitColumns.java82
9 files changed, 0 insertions, 895 deletions
diff --git a/tags/java-M1-20060522/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/DB2Setup.java b/tags/java-M1-20060522/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/DB2Setup.java
deleted file mode 100644
index 75df028490..0000000000
--- a/tags/java-M1-20060522/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/DB2Setup.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/**
- *
- * Copyright 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.
- */
-package org.apache.tuscany.das.rdb.test.framework;
-
-import junit.framework.Test;
-
-public class DB2Setup extends DatabaseSetup {
-
- public DB2Setup(Test test) {
- super(test);
- }
-
- protected void initConnectionProtocol() {
-
- platformName = "DB2";
- driverName = "com.ibm.db2.jcc.DB2Driver";
- databaseURL = "jdbc:db2:DASTEST";
-
- }
-
-}
diff --git a/tags/java-M1-20060522/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/DasTest.java b/tags/java-M1-20060522/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/DasTest.java
deleted file mode 100644
index c4e75d20a8..0000000000
--- a/tags/java-M1-20060522/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/DasTest.java
+++ /dev/null
@@ -1,155 +0,0 @@
-/**
- *
- * Copyright 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.
- */
-package org.apache.tuscany.das.rdb.test.framework;
-
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
-import java.sql.SQLException;
-import java.util.Iterator;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import commonj.sdo.DataObject;
-import commonj.sdo.Property;
-
-/**
- *
- */
-public class DasTest extends TestCase {
-
- public static Connection connection = null;
- private boolean usingDefaultSetup = false;
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() throws Exception {
-// if (usingDefaultSetup)
-// connection = null;
- }
-
- protected Connection getAutoConnection() throws SQLException {
-
- Connection c = primGetConnection();
- c.setAutoCommit(true);
- return connection;
-
- }
-
- protected Connection getConnection() throws SQLException {
-
- Connection c = primGetConnection();
- c.setAutoCommit(false);
- return connection;
- }
-
- /**
- * This provides the default connection for runing single test cases on a
- * chosen platform.
- */
- private Connection primGetConnection() {
- if (connection == null)
- defaultSetup();
- return connection;
- }
-
-
-
- /**
- * This is a bit of a hack since it counts on constructor initialization of the
- * DatabaseSet up class and also calls its setUp method directly. This is a misuse
- * of this JUnit TestSetup subclass .
- *
- * TODO - refactor to avoid this hackiness ... could move this logic to its own
- * class that is then invoked by DatabaseSetUp
- */
- private void defaultSetup() {
-
- usingDefaultSetup = true;
-
-// DatabaseSetup setUp = new DB2Setup(this);
- DatabaseSetup setUp = new DerbySetup(this);
- try {
- setUp.setUp();
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
-
- }
-
-
- //Utilities
- protected InputStream getConfig(String fileName) throws FileNotFoundException {
- return Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName);
- }
-
- protected void write(String label, ResultSet rs) throws IOException, SQLException {
-
- ResultSetMetaData md = rs.getMetaData();
- int count = md.getColumnCount();
- System.out.println("Contents of ResultSet from " + label);
- for (int i = 1; i <= count; i++) {
- System.out.print("\t");
- System.out.println (md.getColumnLabel(i));
- }
- System.out.println("");
- while (rs.next()) {
- for (int i = 1; i <= count; i++) {
- System.out.print("\t");
- System.out.print(rs.getString(i));
- }
- System.out.println("\t");
- }
- System.out.println("done");
- }
-
-
- protected void printList(List data) {
- Iterator i = data.iterator();
- while ( i.hasNext()) {
- System.out.println();
- DataObject obj = (DataObject) i.next();
- Iterator props = obj.getType().getProperties().iterator();
- while ( props.hasNext()) {
- Property p = (Property) props.next();
- if ( p.isMany() ) {
- System.out.print("[ " + p.getName() + " ] ");
- Iterator children = obj.getList(p).iterator();
- while ( children.hasNext()) {
- DataObject child = (DataObject) children.next();
- System.out.print("[ " + child.get("ID") + " ]");
- }
- System.out.println();
- } else if ( !p.getType().isDataType()) {
- DataObject child = obj.getDataObject(p);
- if ( child != null )
- System.out.println("[ " + p.getName() + " ] " + "[ " + child.get("ID") + " ]");
- } else {
- System.out.println("[ " + p.getName() + " ] " + obj.get(p));
- }
- }
- }
- }
-
-
-}
diff --git a/tags/java-M1-20060522/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/DatabaseSetup.java b/tags/java-M1-20060522/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/DatabaseSetup.java
deleted file mode 100644
index f0c5223cf0..0000000000
--- a/tags/java-M1-20060522/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/DatabaseSetup.java
+++ /dev/null
@@ -1,238 +0,0 @@
-/**
- *
- * Copyright 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.
- */
-package org.apache.tuscany.das.rdb.test.framework;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.SQLException;
-import java.sql.Statement;
-
-import junit.extensions.TestSetup;
-import junit.framework.Test;
-
-public class DatabaseSetup extends TestSetup {
-
- protected String platformName = "Not initialized";
-
- protected String driverName = "Not initialized";
-
- protected String databaseURL = "Not initialized";
-
- private Connection connection;
-
- protected Statement s;
-
- public DatabaseSetup(Test test) {
- super(test);
- initConnectionProtocol();
- initConnection();
- DasTest.connection = connection;
- }
-
- protected void initConnectionProtocol() {
- // Subclasses provide implementation
- }
-
- private void initConnection() {
-
- try {
-
- Class.forName(driverName).newInstance();
- connection = DriverManager.getConnection(databaseURL);
- connection.setAutoCommit(false);
-
- } catch (Exception e) {
- if (e instanceof SQLException)
- ((SQLException) e).getNextException().printStackTrace();
- throw new RuntimeException(e);
- }
-
- }
-
- protected void setUp() throws Exception {
-
- System.out.println("Setting up for " + platformName + " run");
-
- s = connection.createStatement();
-
- try {
- dropTables();
- dropProcedures();
- createTables();
- createProcedures();
- connection.commit();
- } catch (SQLException e) {
- connection.rollback();
- }
-
- }
-
- protected void tearDown() throws Exception {
-
- System.out.println("Ending " + platformName + " run");
- connection.close();
-
- }
-
- private void dropTables() {
-
-// System.out.println("Dropping tables");
-
- String[] statements = {
-
- "DROP TABLE CUSTOMER", "DROP TABLE ANORDER", "DROP TABLE ORDERDETAILS", "DROP TABLE ITEM",
- "DROP TABLE COMPANY", "DROP TABLE EMPLOYEE", "DROP TABLE DEPARTMENT", "DROP TABLE BOOK",
- "DROP TABLE PART", "DROP TABLE TYPETEST", "DROP TABLE CITIES", "DROP TABLE STATES",
- "DROP TABLE conmgt.SERVERSTATUS"
-
- };
-
- for (int i = 0; i < statements.length; i++) {
- try {
- s.execute(statements[i]);
- } catch (SQLException e) {
- // If the table does not exist then ignore the exception on drop
- if (!e.getMessage().contains("does not exist"))
- throw new RuntimeException(e);
- }
- }
- }
-
- protected void dropProcedures() {
-
-// System.out.println("Dropping procedures");
-
- String[] statements = {
-
- "DROP PROCEDURE GETALLCOMPANIES", "DROP PROCEDURE DELETECUSTOMER", "DROP PROCEDURE GETNAMEDCOMPANY",
- "DROP PROCEDURE GETCUSTOMERANDORDERS", "DROP PROCEDURE GETNAMEDCUSTOMERS"
-
- };
-
- for (int i = 0; i < statements.length; i++) {
- try {
- s.execute(statements[i]);
- } catch (SQLException e) {
- // If the proc does not exist then ignore the exception on drop
- if (!e.getMessage().contains("does not exist"))
- throw new RuntimeException(e);
- }
- }
- }
-
- private void createTables() {
-
-// System.out.println("Creating tables");
-
- try {
-
- s.execute(getCreateCustomer());
- s.execute(getCreateAnOrder());
- s.execute(getCreateOrderDetails());
- s.execute(getCreateItem());
- s.execute(getCreateCompany());
- s.execute(getCreateEmployee());
- s.execute(getCreateDepartment());
- s.execute(getCreateBook());
- s.execute(getCreatePart());
- s.execute(getCreateTypeTest());
- s.execute(getCreateStates());
- s.execute(getCreateCities());
- s.execute(getCreateServerStatus());
-
- } catch (SQLException e) {
- throw new RuntimeException(e);
- }
- }
-
- protected void createProcedures() {
-
-// System.out.println("Creating procedures");
- try {
-
- s.execute("CREATE PROCEDURE GETALLCOMPANIES() PARAMETER STYLE JAVA LANGUAGE JAVA READS SQL DATA DYNAMIC RESULT SETS 1 EXTERNAL NAME 'org.apache.tuscany.das.rdb.test.framework.JavaStoredProcs.getAllCompanies'");
- s.execute("CREATE PROCEDURE DELETECUSTOMER(theId int) PARAMETER STYLE JAVA LANGUAGE JAVA MODIFIES SQL DATA EXTERNAL NAME 'org.apache.tuscany.das.rdb.test.framework.JavaStoredProcs.deleteCustomer'");
- s.execute("CREATE PROCEDURE GETNAMEDCOMPANY(theName VARCHAR(100)) PARAMETER STYLE JAVA LANGUAGE JAVA READS SQL DATA DYNAMIC RESULT SETS 1 EXTERNAL NAME 'org.apache.tuscany.das.rdb.test.framework.JavaStoredProcs.getNamedCompany'");
- s.execute("CREATE PROCEDURE GETCUSTOMERANDORDERS(theID INTEGER) PARAMETER STYLE JAVA LANGUAGE JAVA READS SQL DATA DYNAMIC RESULT SETS 1 EXTERNAL NAME 'org.apache.tuscany.das.rdb.test.framework.JavaStoredProcs.getCustomerAndOrders'");
- s.execute("CREATE PROCEDURE GETNAMEDCUSTOMERS(theName VARCHAR(100), OUT theCount INTEGER) PARAMETER STYLE JAVA LANGUAGE JAVA READS SQL DATA DYNAMIC RESULT SETS 1 EXTERNAL NAME 'org.apache.tuscany.das.rdb.test.framework.JavaStoredProcs.getNamedCustomers'");
- // TODO - "GETNAMEDCUSTOMERS" is failing on DB2 with SQLCODE: 42723. Need to investigate
- } catch (SQLException e) {
- throw new RuntimeException(e);
- }
- }
-
- //
- // This section povides methods that return strings for table creation.
- // Platform-specific sublcasses
- // can override these as necessary
- //
-
- protected String getCreateCustomer() {
- return "CREATE TABLE CUSTOMER (ID INT PRIMARY KEY NOT NULL, LASTNAME VARCHAR(30) DEFAULT 'Garfugengheist', ADDRESS VARCHAR(30))";
- }
-
- protected String getCreateAnOrder() {
- return "CREATE TABLE ANORDER (ID INT PRIMARY KEY NOT NULL, PRODUCT VARCHAR(30), QUANTITY INT, CUSTOMER_ID INT)";
- }
-
- protected String getCreateOrderDetails() {
- return "CREATE TABLE ORDERDETAILS (ORDERID INT NOT NULL, PRODUCTID INT NOT NULL, PRICE FLOAT, PRIMARY KEY (ORDERID, PRODUCTID))";
- }
-
- protected String getCreateItem() {
- return "CREATE TABLE ITEM (ID INT PRIMARY KEY NOT NULL, NAME VARCHAR(30))";
- }
-
- protected String getCreateCompany() {
- return "CREATE TABLE COMPANY (ID INT PRIMARY KEY NOT NULL GENERATED ALWAYS AS IDENTITY ,NAME VARCHAR(30), EOTMID INT)";
- }
-
- protected String getCreateEmployee() {
- return "CREATE TABLE EMPLOYEE (ID INT PRIMARY KEY NOT NULL GENERATED ALWAYS AS IDENTITY, NAME VARCHAR(30), SN VARCHAR(10), MANAGER SMALLINT, DEPARTMENTID INT)";
- }
-
- protected String getCreateDepartment() {
- return "CREATE TABLE DEPARTMENT (ID INT PRIMARY KEY NOT NULL GENERATED ALWAYS AS IDENTITY, NAME VARCHAR(30), LOCATION VARCHAR(30), NUMBER VARCHAR(10), COMPANYID INT)";
- }
-
- protected String getCreateBook() {
- return "CREATE TABLE BOOK (BOOK_ID INT PRIMARY KEY NOT NULL, NAME VARCHAR(50), AUTHOR VARCHAR(30), QUANTITY INT, OCC INTEGER)";
- }
-
- protected String getCreatePart() {
- return "CREATE TABLE PART (ID INT PRIMARY KEY NOT NULL, NAME VARCHAR(50), QUANTITY INT, PARENT_ID INT )";
- }
-
- protected String getCreateTypeTest() {
- return "CREATE TABLE TYPETEST (ID INT PRIMARY KEY NOT NULL, ATIMESTAMP TIMESTAMP, ADECIMAL DECIMAL(9,2), AFLOAT FLOAT)";
- }
-
- protected String getCreateStates() {
- return "CREATE TABLE STATES (ID INT PRIMARY KEY NOT NULL, NAME VARCHAR(2))";
- }
-
- protected String getCreateCities() {
- return "CREATE TABLE CITIES (ID INT PRIMARY KEY NOT NULL, NAME VARCHAR(50), STATE_ID INT, CONSTRAINT FK1 FOREIGN KEY (STATE_ID) REFERENCES STATES (ID) ON DELETE NO ACTION ON UPDATE NO ACTION)";
- }
-
- protected String getCreateServerStatus() {
-
- return "CREATE TABLE CONMGT.SERVERSTATUS (STATUSID INTEGER PRIMARY KEY NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1 ,INCREMENT BY 1), MANAGEDSERVERID INTEGER NOT NULL, TIMESTAMP TIMESTAMP NOT NULL)";
-
- }
-
-}
diff --git a/tags/java-M1-20060522/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/DerbySetup.java b/tags/java-M1-20060522/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/DerbySetup.java
deleted file mode 100644
index 082b1ec50a..0000000000
--- a/tags/java-M1-20060522/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/DerbySetup.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/**
- *
- * Copyright 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.
- */
-package org.apache.tuscany.das.rdb.test.framework;
-
-import java.util.Properties;
-
-import junit.framework.Test;
-
-public class DerbySetup extends DatabaseSetup {
-
- public DerbySetup(Test test) {
- super(test);
- }
-
- protected void initConnectionProtocol() {
-
- //Set the derby property to explicitly specify the database location relative
- //from current directory to "target"
- Properties p = System.getProperties();
- p.put("derby.system.home", "target");
-
- platformName = "Derby";
- driverName = "org.apache.derby.jdbc.EmbeddedDriver";
- databaseURL = "jdbc:derby:dastest; create = true";
-
- }
-
-}
diff --git a/tags/java-M1-20060522/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/JavaStoredProcs.java b/tags/java-M1-20060522/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/JavaStoredProcs.java
deleted file mode 100644
index cd314e0fce..0000000000
--- a/tags/java-M1-20060522/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/JavaStoredProcs.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/**
- *
- * Copyright 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.
- */
-package org.apache.tuscany.das.rdb.test.framework;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-
-/**
- * Stored Procedures for DB2 and Derby SP tests
- *
- */
-public class JavaStoredProcs {
-
- public static void getAllCompanies(ResultSet[] results) throws SQLException {
-
- Connection conn = DriverManager.getConnection("jdbc:default:connection");
- PreparedStatement ps = conn.prepareStatement("SELECT * FROM COMPANY");
- results[0] = ps.executeQuery();
- }
-
- public static void deleteCustomer(int theId) throws SQLException {
-
- Connection conn = DriverManager.getConnection("jdbc:default:connection");
- PreparedStatement ps = conn.prepareStatement("DELETE FROM CUSTOMER WHERE ID = ?");
- ps.setInt(1, theId);
- ps.execute();
-
- }
-
- public static void getNamedCompany(String theName, ResultSet[] results) throws SQLException {
-
- Connection conn = DriverManager.getConnection("jdbc:default:connection");
- PreparedStatement ps = conn.prepareStatement("SELECT * FROM COMPANY WHERE NAME = ?");
- ps.setString(1, theName);
- results[0] = ps.executeQuery();
- }
-
- public static void getCustomerAndOrders(int theId, ResultSet[] results) throws SQLException {
-
- Connection conn = DriverManager.getConnection("jdbc:default:connection");
- PreparedStatement ps = conn
- .prepareStatement("SELECT * FROM CUSTOMER LEFT JOIN ANORDER ON CUSTOMER.ID = ANORDER.CUSTOMER_ID WHERE CUSTOMER.ID = ?");
- ps.setInt(1, theId);
- results[0] = ps.executeQuery();
- }
-
- public static void getNamedCustomers(String theName, int[] outCount, ResultSet[] results) throws SQLException {
-
- Connection conn = DriverManager.getConnection("jdbc:default:connection");
- PreparedStatement ps = conn.prepareStatement("SELECT * FROM CUSTOMER WHERE LASTNAME = ?");
- ps.setString(1, theName);
- results[0] = ps.executeQuery();
-
- ps = conn.prepareStatement("SELECT COUNT(*) FROM CUSTOMER WHERE LASTNAME = ?");
- ps.setString(1, theName);
-
- ResultSet rs = ps.executeQuery();
- rs.next();
- outCount[0] = rs.getInt(1);
- }
-
-}
diff --git a/tags/java-M1-20060522/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/MySQLSetup.java b/tags/java-M1-20060522/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/MySQLSetup.java
deleted file mode 100644
index b3616882f4..0000000000
--- a/tags/java-M1-20060522/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/MySQLSetup.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/**
- *
- * Copyright 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.
- */
-package org.apache.tuscany.das.rdb.test.framework;
-
-import java.sql.SQLException;
-
-
-import junit.framework.Test;
-
-public class MySQLSetup extends DatabaseSetup {
-
- public MySQLSetup(Test test) {
- super(test);
- }
-
- protected void initConnectionProtocol() {
-
- platformName = "MySQL";
- driverName = "com.mysql.jdbc.Driver";
- databaseURL = "jdbc:mysql:///dastest?user=dastester&password=dastester";
-
- }
-
-
- protected void createProcedures () {
-
- String createGetAllCompanies =
- "CREATE PROCEDURE `dastest`.`GETALLCOMPANIES` () "+
- " SELECT * FROM COMPANY ";
-
-
- String createDeleteCustomer =
- "CREATE PROCEDURE `dastest`.`DELETECUSTOMER` (theId INT) " +
- " DELETE FROM CUSTOMER WHERE ID = theId ";
-
-
- String createGetNamedCustomers =
- "CREATE PROCEDURE `dastest`.`GETNAMEDCUSTOMERS`(IN thename VARCHAR(30), OUT theCount INTEGER ) " +
- " BEGIN " +
- " SELECT * FROM CUSTOMER AS CUSTOMER WHERE LASTNAME = theName; " +
- " SET theCount = (SELECT COUNT(*) FROM CUSTOMER WHERE LASTNAME = theName); " +
- " END ";
-
- String createGetCustomerAndOrders =
- " CREATE PROCEDURE `dastest`.`GETCUSTOMERANDORDERS` (theId INT) " +
- " SELECT * FROM CUSTOMER LEFT JOIN ANORDER ON CUSTOMER.ID = ANORDER.CUSTOMER_ID WHERE CUSTOMER.ID = theId ";
-
-
- String createGetNamedCompany =
- " CREATE PROCEDURE `dastest`.`GETNAMEDCOMPANY` (theName VARCHAR(100)) " +
- " SELECT * FROM COMPANY WHERE NAME = theName";
-
- System.out.println("Creating procedures");
- try {
-
- s.execute(createGetAllCompanies);
- s.execute(createDeleteCustomer);
- s.execute(createGetNamedCompany);
- s.execute(createGetCustomerAndOrders);
-// s.execute(createGetNamedCustomers);
-//TODO - add this back after DB2 problem is resolved
- } catch (SQLException e) {
- throw new RuntimeException(e);
- }
- }
-
-
- //Overrides for table creation
- protected String getCreateCompany() {
- return "CREATE TABLE COMPANY (ID INT PRIMARY KEY NOT NULL AUTO_INCREMENT, NAME VARCHAR(30))";
- }
- protected String getCreateEmployee() {
- return "CREATE TABLE EMPLOYEE (ID INT PRIMARY KEY NOT NULL AUTO_INCREMENT, NAME VARCHAR(30), SN VARCHAR(10), MANAGER SMALLINT, DEPARTMENTID INT)";
- }
- protected String getCreateDepartment() {
- return "CREATE TABLE DEPARTMENT (ID INT PRIMARY KEY NOT NULL AUTO_INCREMENT, NAME VARCHAR(30), LOCATION VARCHAR(30), NUMBER VARCHAR(10), COMPANYID INT, EOTM INT)";
- }
- protected String getCreateTypeTest() {
- return "CREATE TABLE TYPETEST (ID INT PRIMARY KEY NOT NULL, ATIMESTAMP DATETIME, ADECIMAL DECIMAL(9,2), AFLOAT FLOAT)";
- }
-
-}
diff --git a/tags/java-M1-20060522/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/RelationshipData.java b/tags/java-M1-20060522/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/RelationshipData.java
deleted file mode 100644
index 330320656e..0000000000
--- a/tags/java-M1-20060522/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/RelationshipData.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/**
- *
- * Copyright 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.
- */
-package org.apache.tuscany.das.rdb.test.framework;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-
-public abstract class RelationshipData {
- protected Object[][] data;
- private int currentRow = -1;
- protected Connection connection;
-
-
- public RelationshipData(Connection c, Object[][] inputData) {
- this.connection = c;
- this.data = inputData;
- }
-
- public int size() {
- return data[0].length;
- }
-
- public int numberOfRows() {
- return data.length;
- }
-
- public boolean next() {
- ++currentRow;
- if ( currentRow < numberOfRows() )
- return true;
- else
- return false;
- }
-
-
- public void refresh() throws SQLException {
- updateRelationships();
- }
-
- protected abstract String getParentRetrievalStatement();
- protected abstract String getChildUpdateStatement();
-
-
- protected void updateRelationships() throws SQLException {
- // { MegaCorp, Advanced Technologies }
- // select company.id from company where company.name = ?
- PreparedStatement retrieveParent = connection.prepareStatement(getParentRetrievalStatement());
- // update department set department.companyid = ? where department.name = ?
- PreparedStatement updateChild = connection.prepareStatement(getChildUpdateStatement());
-
- while ( next() ) {
- retrieveParent.setObject(1, data[currentRow][0]);
- retrieveParent.execute();
- ResultSet rs = retrieveParent.getResultSet();
- rs.next();
- Object parentID = rs.getObject(1);
- retrieveParent.clearParameters();
-
- updateChild.setObject(1, parentID);
- updateChild.setObject(2, data[currentRow][1]);
- updateChild.execute();
- updateChild.clearParameters();
- }
- }
-}
diff --git a/tags/java-M1-20060522/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/TestData.java b/tags/java-M1-20060522/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/TestData.java
deleted file mode 100644
index 686433bfc8..0000000000
--- a/tags/java-M1-20060522/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/TestData.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/**
- *
- * Copyright 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.
- */
-package org.apache.tuscany.das.rdb.test.framework;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-
-public abstract class TestData {
-
- protected Object[][] data;
- private int currentRow = -1;
- protected Connection connection;
-
-
- public TestData(Connection c, Object[][] customerData) {
- this.connection = c;
- this.data = customerData;
- }
-
- public int size() {
- return data[0].length;
- }
-
- public int numberOfRows() {
- return data.length;
- }
-
- public boolean next() {
- ++currentRow;
- if ( currentRow < numberOfRows() )
- return true;
- else
- return false;
- }
-
- public abstract String getTableName();
-
-
- public Object getObject(int i) {
- return data[currentRow][i-1];
- }
-
- public void refresh() throws SQLException {
- deleteRowsFromTable();
- insertRows();
- }
-
- protected void deleteRowsFromTable() throws SQLException {
- PreparedStatement ps = connection.prepareStatement("delete from " + getTableName());
- ps.execute();
- }
-
- protected void insertRows() throws SQLException {
- StringBuffer sql = new StringBuffer();
- sql.append("insert into ");
- sql.append(getTableName());
- sql.append(" values (");
- for ( int i=1; i < size(); i++) {
- sql.append("?,");
- }
- sql.append("?)");
- PreparedStatement ps = connection.prepareStatement(sql.toString());
-
- while ( next() ) {
- for ( int i=1; i <= size(); i++ ) {
- ps.setObject(i, getObject(i));
- }
- ps.execute();
- ps.clearParameters();
- }
- }
-}
diff --git a/tags/java-M1-20060522/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/TestDataWithExplicitColumns.java b/tags/java-M1-20060522/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/TestDataWithExplicitColumns.java
deleted file mode 100644
index 8ded99af9b..0000000000
--- a/tags/java-M1-20060522/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/TestDataWithExplicitColumns.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/**
- *
- * Copyright 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.
- */
-package org.apache.tuscany.das.rdb.test.framework;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-
-import org.apache.tuscany.das.rdb.util.DebugUtil;
-
-
-public abstract class TestDataWithExplicitColumns extends TestData {
-
- protected String[] columns;
- protected int[] sqlTypes;
-
- private static boolean debug = false;
-
- public TestDataWithExplicitColumns(Connection c, Object[][] data,
- String[] columns, int[] sqlTypes) {
- super(c, data);
- this.columns = columns;
- this.sqlTypes = sqlTypes;
- }
-
- private String getColumn(int i) {
- return columns[i - 1];
- }
-
- private int getSqlType(int i) {
- return (sqlTypes[i - 1]);
- }
-
- // Create an insert statement of the following form ...
- // "INSERT INTO table_name (column1, column2,...) VALUES (value1, value2,....)"
- // This is necessary for tables with a generated column since the PK value is not provided
- protected void insertRows() throws SQLException {
- StringBuffer sql = new StringBuffer();
- sql.append("insert into ");
- sql.append(getTableName());
-
- sql.append(" (");
- for (int i = 1; i <= size(); i++) {
- sql.append(getColumn(i));
- if ( i < size() )
- sql.append(',');
- }
- sql.append(" )");
-
- sql.append(" values (");
- for (int i = 1; i < size(); i++) {
- sql.append("?,");
- }
- sql.append("?)");
-
- DebugUtil.debugln(getClass(), debug, sql.toString());
- PreparedStatement ps = connection.prepareStatement(sql.toString());
-
- while (next()) {
- for (int i = 1; i <= size(); i++) {
- ps.setObject(i, getObject(i), getSqlType(i));
- }
- ps.execute();
- ps.clearParameters();
- }
- }
-
-}