diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-11 23:11:48 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-11 23:11:48 +0000 |
commit | ece4fd35da7b7fc76264776f81705e6b5b52d3e0 (patch) | |
tree | 962794e2a2b1ab91a02c41e4927a527cade83959 /sca-java-1.x/branches/java-post-M1/das/rdb/src/test | |
parent | 76e9f96ca7f494088fe3af5a46ad0d153e961008 (diff) |
Moving 1.x branches
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835140 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-1.x/branches/java-post-M1/das/rdb/src/test')
105 files changed, 7775 insertions, 0 deletions
diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/AliasTests.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/AliasTests.java new file mode 100644 index 0000000000..9ae8ab71c8 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/AliasTests.java @@ -0,0 +1,136 @@ +/* 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; + +import org.apache.tuscany.das.rdb.Command; +import org.apache.tuscany.das.rdb.DAS; +import org.apache.tuscany.das.rdb.test.data.BookData; +import org.apache.tuscany.das.rdb.test.framework.DasTest; + +import commonj.sdo.DataObject; + +public class AliasTests extends DasTest{ + + protected void setUp() throws Exception { + + super.setUp(); + new BookData(getAutoConnection()).refresh(); + } + + /** + * Tests the use of column aliasing. The property name change is found in the BooksConfig.xml file + * Otherwise similar to testTableAlias + * + * @throws Exception + */ + public void testColumnAlias() throws Exception{ + + DAS das = DAS.FACTORY.createDAS( getConfig("BooksConfigWithAlias.xml") , getConnection()); + + Command select = das.getCommand( "get all books" ); + //select.setConnection( getConnection() ); + + DataObject root = select.executeQuery(); + + DataObject book = root.getDataObject("Book[2]"); + book.set( "Writer", "Dr. Seuss"); + + das.applyChanges( root ); + + select = das.getCommand( "get Cat in the Hat" ); + + + root = select.executeQuery(); + // Ensure the change actually updated + assertEquals( "Dr. Seuss", root.getString( "Book[1]/Writer" ) ); + } + + /** + * Tests to ensure that columns are being properly read when using an Alias, just a bunch of simple + * creating, renaming, and deleting of entries while using an alias. + */ + public void testColumnData() throws Exception { + + DAS das = DAS.FACTORY.createDAS( getConfig("BooksConfigWithAlias.xml") , getConnection()); + + Command select = das.getCommand( "get book by ID" ); + select.setParameter(1, new Integer(1)); + + //*******Verifys a column entry is readable + DataObject root = select.executeQuery(); + assertEquals("Fyodor Dostoevsky", root.getString( "Book[1]/Writer" ) ); + + DataObject bookToChange = root.getDataObject("Book[1]"); + bookToChange.set("Writer", "Fyodor Dostoevskii"); // His last name COULD be spelt like that too! + + das.applyChanges( root ); + + //*******Verifys correct information in entry after a column data is changed + select = das.getCommand( "get all books" ); + //select.setConnection(getConnection()); + + root = select.executeQuery(); + assertEquals("Fyodor Dostoevskii", root.getString( "Book[1]/Writer" ) ); + + bookToChange = root.getDataObject("Book[1]"); + bookToChange.delete(); + + das.applyChanges( root ); + + //*******Verifys correct in table, after entry is deleted + select = das.getCommand( "get all books" ); + //select.setConnection(getConnection()); + + root = select.executeQuery(); + assertEquals( 1, root.getList("Book").size() ); + assertEquals( "Doctor Seuss", root.getString( "Book[1]/Writer") ); + } + + /** + * Test to check if updating a table works when using Aliasing + * Previously this was test_4 in ExceptionTests. + */ + public void testTableAlias() throws Exception { + + // Create Table config programmatically + //ConfigHelper helper = new ConfigHelper(); + //helper.addTable("BOOK", "Book"); + //helper.addPrimaryKey("BOOK.BOOK_ID"); + + DAS das = DAS.FACTORY.createDAS( getConfig("BooksConfigWithAlias.xml"), getConnection() ); + Command select = das.getCommand( "get book by ID" ); + select.setParameter(1, new Integer(1)); + + DataObject root = select.executeQuery(); + + + DataObject newBook = root.createDataObject("Book"); + newBook.setString("NAME", "Ant Colonies of the Old World"); + newBook.setInt("BOOK_ID", 1001); + root.getList("Book").add(newBook); + + + das.applyChanges( root ); + + + root = select.executeQuery(); + + //Verify + select.setParameter(1, new Integer(1001)); + root = select.executeQuery(); + + assertEquals("Ant Colonies of the Old World", root.getString("Book[1]/NAME")); + } +}
\ No newline at end of file diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/BestPracticeTests.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/BestPracticeTests.java new file mode 100644 index 0000000000..8d9d2ada77 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/BestPracticeTests.java @@ -0,0 +1,143 @@ +/** + * + * 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; + +import java.util.List; + +import org.apache.tuscany.das.rdb.Command; +import org.apache.tuscany.das.rdb.DAS; +import org.apache.tuscany.das.rdb.test.data.CompanyData; +import org.apache.tuscany.das.rdb.test.data.CompanyDeptData; +import org.apache.tuscany.das.rdb.test.data.DepEmpData; +import org.apache.tuscany.das.rdb.test.data.DepartmentData; +import org.apache.tuscany.das.rdb.test.data.EmployeeData; +import org.apache.tuscany.das.rdb.test.framework.DasTest; + +import commonj.sdo.DataObject; + +public class BestPracticeTests extends DasTest { + + protected void setUp() throws Exception { + super.setUp(); + + new CompanyData(getAutoConnection()).refresh(); + new DepartmentData(getAutoConnection()).refresh(); + new EmployeeData(getAutoConnection()).refresh(); + new CompanyDeptData(getAutoConnection()).refresh(); + new DepEmpData(getAutoConnection()).refresh(); + + } + + //Read list of companies + public void testReadCompanies() throws Exception { + + DAS das = DAS.FACTORY.createDAS(getConfig("CompanyConfig.xml"), getConnection()); + Command read = das.getCommand("all companies"); + DataObject root = read.executeQuery(); + assertEquals(3, root.getList("COMPANY").size()); + + } + + //Read list of companies + public void testReadCompaniesWithDepartments() throws Exception { + + DAS das = DAS.FACTORY.createDAS(getConfig("CompanyConfig.xml"), getConnection()); + Command read = das.getCommand("all companies and departments"); + DataObject root = read.executeQuery(); + DataObject firstCompany = root.getDataObject("COMPANY[1]"); + List departments = firstCompany.getList("departments"); + assertEquals(0, departments.size()); + + } + + public void testddDepartmentToFirstCompany() throws Exception { + + DAS das = DAS.FACTORY.createDAS(getConfig("CompanyConfig.xml"), getConnection()); + Command read = das.getCommand("all companies and departments"); + DataObject root = read.executeQuery(); + DataObject firstCustomer = root.getDataObject("COMPANY[1]"); + int deptCount = firstCustomer.getList("departments").size(); + + DataObject newDepartment = root.createDataObject("DEPARTMENT"); + firstCustomer.getList("departments").add(newDepartment); + + das.applyChanges(root); + + //verify + root = read.executeQuery(); + firstCustomer = root.getDataObject("COMPANY[1]"); + assertEquals (deptCount + 1, firstCustomer.getList("departments").size()); + } + + /** + * Test ability to correctly flush heirarchy of objects that have generated + * keys + */ + public void testFlushCreateHeirarchy() throws Exception { + + DAS das = DAS.FACTORY.createDAS(getConfig("CompanyConfig.xml"), getConnection()); + Command select = das.getCommand("all companies and departments"); + DataObject root = select.executeQuery(); + + // Create a new Company + DataObject company = root.createDataObject("COMPANY"); + company.setString("NAME", "Do-rite Pest Control"); + + // Create a new Department + //Do not set ID or CompanyID since these are generated + DataObject department = root.createDataObject("DEPARTMENT"); + department.setString("NAME", "Do-rite Pest Control"); + department.setString("LOCATION", "The boonies"); + department.setString("NUMBER", "101"); + + // Associate the new department with the new company + company.getList("departments").add(department); + + // Get apply command + das.applyChanges(root); + + // Save the id + Integer id = (Integer) company.get("ID"); + + // Verify the change + + select = das.getCommand("company by id with departments"); + select.setParameter(1, id); + root = select.executeQuery(); + assertEquals("Do-rite Pest Control", root.getDataObject("COMPANY[1]") + .getString("NAME")); + + } + + /** + * Test ability to get an empty graph with the Types/Properties intact + */ + public void testGetEmptyGraph() throws Exception { + + DAS das = DAS.FACTORY.createDAS(getConfig("CompanyConfig.xml"), getConnection()); + + Command select = das.getCommand("company by id with departments"); + Integer idOfNoExistingCompany = new Integer(-1); + select.setParameter(1, idOfNoExistingCompany); + DataObject root = select.executeQuery(); + + //Will fail if there is no property named "COMPANY" + assertEquals(0, root.getList("COMPANY").size()); + + } + +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/CUDGeneration.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/CUDGeneration.java new file mode 100644 index 0000000000..c7545723ad --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/CUDGeneration.java @@ -0,0 +1,111 @@ +/** + * + * 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; + +import org.apache.tuscany.das.rdb.Command; +import org.apache.tuscany.das.rdb.DAS; +import org.apache.tuscany.das.rdb.test.data.CustomerData; +import org.apache.tuscany.das.rdb.test.data.OrderData; +import org.apache.tuscany.das.rdb.test.framework.DasTest; + +import commonj.sdo.DataObject; + +public class CUDGeneration extends DasTest { + + protected void setUp() throws Exception { + super.setUp(); + + new CustomerData(getAutoConnection()).refresh(); + new OrderData(getAutoConnection()).refresh(); + } + + /** + * This tests provides invalid SQL and should fail on Apply.execute. If not + * then the engine is generating CUD and overlooking the provided + * statements. + */ + public void testCUDGeneration1() throws Exception { + DAS das = DAS.FACTORY.createDAS(getConfig("basicCustomerMappingWithInvalidCUD.xml"), getConnection()); + + // Read customer with particular ID + Command select = das.createCommand("Select * from CUSTOMER where ID = 1"); + DataObject root = select.executeQuery(); + + DataObject customer = (DataObject) root.get("CUSTOMER[1]"); + + // Modify customer + customer.set("LASTNAME", "Pavick"); + + + // Flush changes + try { + das.applyChanges(root); + fail("Should fail with invalid SQL. Provided CUD not used!!"); + } catch (RuntimeException e) { + // Everything OK + } + + } + + public void testInsertCUDGeneration() throws Exception { + DAS das = DAS.FACTORY.createDAS(getConnection()); + + Command select = das.createCommand("Select * from CUSTOMER where ID = 1"); + DataObject root = select.executeQuery(); + + DataObject customer = root.createDataObject("CUSTOMER"); + customer.setInt("ID", 720); + customer.set("LASTNAME", "foobar"); + customer.set("ADDRESS", "asdfasdf"); + + das.applyChanges(root); + + select = das.createCommand("select * from CUSTOMER where ID = 720"); + root = select.executeQuery(); + + assertEquals(1, root.getList("CUSTOMER").size()); + } + + public void testReadModifyApply() throws Exception { + + DAS das = DAS.FACTORY.createDAS(getConfig("1xM_mapping_no_cud.xml"), getConnection()); + + // Build the select command to read a specific customer and related + // orders + Command select = das + .createCommand( + "SELECT * FROM CUSTOMER LEFT JOIN ANORDER ON CUSTOMER.ID = ANORDER.CUSTOMER_ID where CUSTOMER.ID = ?"); + + // Parameterize the command + select.setParameter(1, new Integer(1)); + + // Get the graph + DataObject root = select.executeQuery(); + + // Modify a customer + DataObject customer = (DataObject) root.get("Customer[1]"); + customer.set("LASTNAME", "Pavick"); + + // Modify an order + DataObject order = (DataObject) customer.get("orders[1]"); + order.setString("PRODUCT", "Kitchen Sink 001"); + + das.applyChanges(root); + + } + +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/CommandGroupTests.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/CommandGroupTests.java new file mode 100644 index 0000000000..029816686a --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/CommandGroupTests.java @@ -0,0 +1,176 @@ +/** + * + * 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; + +/* + * This test + * + */ + +import org.apache.tuscany.das.rdb.Command; +import org.apache.tuscany.das.rdb.DAS; +import org.apache.tuscany.das.rdb.config.Config; +import org.apache.tuscany.das.rdb.test.data.CustomerData; +import org.apache.tuscany.das.rdb.test.data.OrderData; +import org.apache.tuscany.das.rdb.test.framework.DasTest; +import org.apache.tuscany.das.rdb.util.ConfigUtil; + +import commonj.sdo.DataObject; + +/** + * + * This tests use of the XML Config file. Tests will utilize the + * customer-orders-orderdetails tables. The plan is for the config file to have + * a section that applies to all commands and another that applies to specific + * commands. + * + * The config file will be used to initialize a command factory that will then + * return named commands. + * + * There will be two read commands: + * + * 1) Return all customers 2) Return a specific customer (by ID) and related + * orders and order details + * + * A test will demonstrate the creation of the factory and then reuse of + * commands created from the same config data file + * + */ +public class CommandGroupTests extends DasTest { + + protected void setUp() throws Exception { + super.setUp(); + + new CustomerData(getAutoConnection()).refresh(); + new OrderData(getAutoConnection()).refresh(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + /** + * Read + */ + public void testRead() throws Exception { + + DAS das = DAS.FACTORY.createDAS(getConfig("CustomersOrdersConfig.xml"), getConnection()); + + Command read = das.getCommand("all customers"); + DataObject root = read.executeQuery(); + + assertEquals(5, root.getList("CUSTOMER").size()); + + } + + /** + * Read + */ + public void testReadUsingConfigInput() throws Exception { + Config config = ConfigUtil.loadConfig(getConfig("CustomersOrdersConfig.xml")); + DAS das = DAS.FACTORY.createDAS(config, getConnection()); + + Command read = das.getCommand("all customers"); + DataObject root = read.executeQuery(); + + assertEquals(5, root.getList("CUSTOMER").size()); + + } + /** + * Read an order using parm marker + */ + public void testReadWithParmmarker() throws Exception { + + DAS das = DAS.FACTORY.createDAS(getConfig("CustOrdersConnectionProps.xml"), getConnection()); + + Command read = das.getCommand("order by id with ?"); + read.setParameter(1, new Integer(1)); + DataObject root = read.executeQuery(); + + assertEquals("recombobulator", root.getString("ANORDER[1]/PRODUCT")); + + } + + /** + * Specify connection properties in config + */ + public void testReadWithConnectionProperties() throws Exception { + + DAS das = DAS.FACTORY.createDAS(getConfig("CustOrdersConnectionProps.xml"), getConnection()); + + Command read = das.getCommand("all customers"); + DataObject root = read.executeQuery(); + + assertEquals(5, root.getList("CUSTOMER").size()); + + } + + /** + * Specify connection properties in config. Add explicit update command + */ + public void testUpdate() throws Exception { + + DAS das = DAS.FACTORY.createDAS(getConfig("CustOrdersConnectionProps.xml"), getConnection()); + + Command read = das.getCommand("all customers"); + DataObject root = read.executeQuery(); + // Verify precondition + assertFalse(root.get("CUSTOMER[1]/LASTNAME").equals("Pavick")); + int id = root.getInt("CUSTOMER[1]/ID"); + + Command update = das.getCommand("update customer"); + update.setParameter(1, new Integer(id)); + update.execute(); + + // Verify update - reuse select command + root = read.executeQuery(); + assertEquals("Pavick", root.get("CUSTOMER[1]/LASTNAME")); + + } + + /** + * Read all customers, select a specific customer. Then read that customer + * and related orders. Modify an order and flush changes back + */ + public void testRead2() throws Exception { + + // Create the group and set common connection + DAS das = DAS.FACTORY.createDAS(getConfig("CustomersOrdersConfig.xml"), getConnection()); + + // Read all customers and remember the first one + Command read = das.getCommand("all customers"); + DataObject root = read.executeQuery(); + Integer id = (Integer) root.get("CUSTOMER[1]/ID"); + + // Read the specific Customer from above and its related orders + Command custOrders = das.getCommand("customer and orders"); + custOrders.setParameter(1, id); + root = custOrders.executeQuery(); + + // Modify the first order and flush this change back to the database + root.setString("CUSTOMER[1]/orders[1]/PRODUCT", "Defibrillator"); + Integer orderId = (Integer) root.get("CUSTOMER[1]/orders[1]/ID"); + das.applyChanges(root); + + // Verify + Command orderByID = das.getCommand("order by id"); + orderByID.setParameter(1, orderId); + assertEquals("Defibrillator", root.getString("ANORDER[1]/PRODUCT")); + + } + +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/CompanyTests.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/CompanyTests.java new file mode 100644 index 0000000000..9ac492d2bb --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/CompanyTests.java @@ -0,0 +1,101 @@ +/** + * + * 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; + +import org.apache.tuscany.das.rdb.Command; +import org.apache.tuscany.das.rdb.DAS; +import org.apache.tuscany.das.rdb.test.company.CompanyFactory; +import org.apache.tuscany.das.rdb.test.company.CompanyType; +import org.apache.tuscany.das.rdb.test.company.DepartmentType; +import org.apache.tuscany.das.rdb.test.company.EmployeeType; +import org.apache.tuscany.das.rdb.test.data.CompanyData; +import org.apache.tuscany.das.rdb.test.data.CompanyDeptData; +import org.apache.tuscany.das.rdb.test.data.DepEmpData; +import org.apache.tuscany.das.rdb.test.data.DepartmentData; +import org.apache.tuscany.das.rdb.test.data.EmployeeData; +import org.apache.tuscany.das.rdb.test.framework.DasTest; +import org.apache.tuscany.sdo.util.SDOUtil; + +import commonj.sdo.DataObject; + +public class CompanyTests extends DasTest { + + protected void setUp() throws Exception { + super.setUp(); + + new CompanyData(getAutoConnection()).refresh(); + new DepartmentData(getAutoConnection()).refresh(); + new EmployeeData(getAutoConnection()).refresh(); + new CompanyDeptData(getAutoConnection()).refresh(); + new DepEmpData(getAutoConnection()).refresh(); + + } + + public void testSimple() throws Exception { + + DAS das = DAS.FACTORY.createDAS(getConfig("companyMapping.xml"), getConnection()); + + // Build the select command + Command selectCommand = das.createCommand("select COMPANY.NAME, " + + "EMPLOYEE.NAME, EMPLOYEE.SN, EMPLOYEE.MANAGER, " + + "DEPARTMENT.NAME, DEPARTMENT.LOCATION, DEPARTMENT.NUMBER from COMPANY, DEPARTMENT, EMPLOYEE " + + "where COMPANY.ID=DEPARTMENT.COMPANYID and DEPARTMENT.ID=EMPLOYEE.DEPARTMENTID"); + + // Get the graph + DataObject root = selectCommand.executeQuery(); + + // Get a company + DataObject company = (DataObject) root.getList("CompanyType").get(0); + assertEquals("MegaCorp", company.get("NAME")); + + // Get a department + DataObject department = (DataObject) company.getList("departments").get(0); + assertEquals("Advanced Technologies", department.get("NAME")); + + DataObject employee = (DataObject) department.getList("employees").get(0); + assertEquals("John Jones", employee.get("NAME")); + } + + public void testSimpleStatic() throws Exception { + + DAS das = DAS.FACTORY.createDAS(getConfig("companyMappingWithConverters.xml"), getConnection()); + SDOUtil.registerStaticTypes(CompanyFactory.class); + // Build the select command + Command selectCommand = das.createCommand("select COMPANY.NAME, " + + "EMPLOYEE.NAME, EMPLOYEE.SN, EMPLOYEE.MANAGER, " + + "DEPARTMENT.NAME, DEPARTMENT.LOCATION, DEPARTMENT.NUMBER from COMPANY, DEPARTMENT, EMPLOYEE " + + "where COMPANY.ID=DEPARTMENT.COMPANYID and DEPARTMENT.ID=EMPLOYEE.DEPARTMENTID"); + + + // Get the graph + DataObject root = selectCommand.executeQuery(); + + + CompanyType company = (CompanyType) root.getList("CompanyType").get(0); + + assertEquals("MegaCorp", company.getName()); + + // Get a department + DepartmentType department = (DepartmentType) company.getDepartments().get(0); + assertEquals("Advanced Technologies", department.getName()); + + EmployeeType employee = (EmployeeType) department.getEmployees().get(0); + + assertEquals("John Jones", employee.getName()); + } + +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/CompoundKeyTests.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/CompoundKeyTests.java new file mode 100644 index 0000000000..450933928e --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/CompoundKeyTests.java @@ -0,0 +1,95 @@ +/** + * + * 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; + +import org.apache.tuscany.das.rdb.Command; +import org.apache.tuscany.das.rdb.DAS; +import org.apache.tuscany.das.rdb.test.data.OrderData; +import org.apache.tuscany.das.rdb.test.data.OrderDetailsData; +import org.apache.tuscany.das.rdb.test.framework.DasTest; + +import commonj.sdo.DataObject; + +/** + * Tests for Compound Keys + */ +public class CompoundKeyTests extends DasTest { + + protected void setUp() throws Exception { + super.setUp(); + + new OrderDetailsData(getAutoConnection()).refresh(); + new OrderData(getAutoConnection()).refresh(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public void testRead() throws Exception { + DAS das = DAS.FACTORY.createDAS(getConnection()); + Command getOrderDetails = das + .createCommand("Select * from ORDERDETAILS where ORDERID = ? AND PRODUCTID = ?"); + + + getOrderDetails.setParameter(1, new Integer(1)); + getOrderDetails.setParameter(2, new Integer(1)); + + DataObject root = getOrderDetails.executeQuery(); + + DataObject orderDetail = (DataObject) root.get("ORDERDETAILS[1]"); + assertEquals(1.1f, orderDetail.getFloat("PRICE"), 0.01); + + } + + public void testReadModifyWrite2() throws Exception { + DAS das = DAS.FACTORY.createDAS(getConfig("OrdersOrderDetailsConfig.xml"), getConnection()); + Command getOrderDetails = das + .createCommand("Select * from ORDERDETAILS where ORDERID = 1 AND PRODUCTID = 1"); + + DataObject root = getOrderDetails.executeQuery(); + + DataObject orderDetails = (DataObject) root.get("ORDERDETAILS[1]"); + assertEquals(1.1f, orderDetails.getFloat("PRICE"), 0.01); + + // Modify + orderDetails.setFloat("PRICE", 0f); + + // Build apply changes command + + das.applyChanges(root); + + // Verify + root = getOrderDetails.executeQuery(); + orderDetails = root.getDataObject("ORDERDETAILS[1]"); + assertEquals(0f, orderDetails.getFloat("PRICE"), 0.01); + + } + + public void testReadOrdersAndDetails2() throws Exception { + DAS das = DAS.FACTORY.createDAS(getConfig("OrdersOrderDetailsConfig.xml"), getConnection()); + Command read = das + .createCommand("SELECT * FROM ANORDER LEFT JOIN ORDERDETAILS ON ANORDER.ID = ORDERDETAILS.ORDERID ORDER BY ANORDER.ID"); + + DataObject root = read.executeQuery(); + + DataObject firstOrder = root.getDataObject("ANORDER[1]"); + assertEquals(1, firstOrder.getInt("ID")); + assertEquals(2, firstOrder.getList("ORDERDETAILS").size()); + + } +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/ConverterTests.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/ConverterTests.java new file mode 100644 index 0000000000..fe7c87a0da --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/ConverterTests.java @@ -0,0 +1,102 @@ +/** + * + * 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; + +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +import org.apache.tuscany.das.rdb.Command; +import org.apache.tuscany.das.rdb.DAS; +import org.apache.tuscany.das.rdb.test.data.CustomerData; +import org.apache.tuscany.das.rdb.test.framework.DasTest; + +import commonj.sdo.DataObject; + +/** + * Tests the Converter framwork + */ +public class ConverterTests extends DasTest { + + + protected void setUp() throws Exception { + super.setUp(); + new CustomerData(getAutoConnection()).refresh(); + } + + + protected void tearDown() throws Exception { + super.tearDown(); + } + + private static DateFormat myformat = new SimpleDateFormat("yyyy.MM.dd"); + + private static Date kbday; + private static Date tbday; + + static { + try { + kbday = myformat.parse("1957.09.27"); + tbday = myformat.parse("1966.12.20"); + } catch (ParseException e) { + throw new RuntimeException(e); + } + } + + + + /** + * This tests the use of an arbitrary converter. The column converted is a VARCAHAR. + * ResultSetShape is used to specify that the property will be a SDODataTypes.DATE. + * + * So this example uses a converter that transforms a string column into a date property + * and conversely, a date property back to a string for the underlying column. + * + * The converter returns 1957.09.27 if the column value is "Williams" and 1966.12.20 + * if the value is "Pavick" + * + * On write, the converter returns "Pavick" if the property value is 1966.12.20 + * and "Williams" if the property value is 1957.09.27 + * + */ + public void testArbitraryConverter() throws Exception { + DAS das = DAS.FACTORY.createDAS(getConfig("CustomerConfigWithConverter.xml"), getConnection()); + + //Create and initialize command to read customers + Command read = das.getCommand("testArbitraryConverter"); + + //Read + DataObject root = read.executeQuery(); + + //Verify + assertEquals(kbday, root.getDate("CUSTOMER[1]/LASTNAME")); + + //Modify + root.setDate("CUSTOMER[1]/LASTNAME", tbday); + + das.applyChanges(root); + + //Read + root = read.executeQuery(); + + //Verify + assertEquals(tbday, root.getDate("CUSTOMER[1]/LASTNAME")); + + } + +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/CorrectedDefectTests.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/CorrectedDefectTests.java new file mode 100644 index 0000000000..492e70352c --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/CorrectedDefectTests.java @@ -0,0 +1,307 @@ +/** + * + * 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; + +/* + * These tests attempt to duplicate customer reported errors and then to verify + * any necessary fix. + * + */ + +import java.util.Iterator; +import java.util.Random; + +import org.apache.tuscany.das.rdb.Command; +import org.apache.tuscany.das.rdb.ConfigHelper; +import org.apache.tuscany.das.rdb.DAS; +import org.apache.tuscany.das.rdb.test.data.CompanyData; +import org.apache.tuscany.das.rdb.test.data.CompanyDeptData; +import org.apache.tuscany.das.rdb.test.data.CustomerData; +import org.apache.tuscany.das.rdb.test.data.DepartmentData; +import org.apache.tuscany.das.rdb.test.data.OrderData; +import org.apache.tuscany.das.rdb.test.framework.DasTest; + +import commonj.sdo.DataObject; + +public class CorrectedDefectTests extends DasTest { + + protected void setUp() throws Exception { + super.setUp(); + new CustomerData(getAutoConnection()).refresh(); + new OrderData(getAutoConnection()).refresh(); + + new CompanyData(getAutoConnection()).refresh(); + new DepartmentData(getAutoConnection()).refresh(); + new CompanyDeptData(getAutoConnection()).refresh(); + + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + /** + * Dilton's bug for adding new child data object + */ + public void testAddNewOrder() throws Exception { + DAS das = DAS.FACTORY.createDAS(getConfig("CustomersOrdersConfig.xml"), getConnection()); + // Read some customers and related orders + Command select = das.createCommand( + "SELECT * FROM CUSTOMER LEFT JOIN ANORDER ON CUSTOMER.ID = ANORDER.CUSTOMER_ID"); + + DataObject root = select.executeQuery(); + + DataObject cust = root.getDataObject("CUSTOMER[1]"); + + // Save ID and Order Count + int custID = cust.getInt("ID"); + int custOrderCount = cust.getList("orders").size(); + + // Create a new Order and add to customer1 + DataObject order = root.createDataObject("ANORDER"); + + order.set("ID", new Integer(99)); + order.set("PRODUCT", "The 99th product"); + order.set("QUANTITY", new Integer(99)); + cust.getList("orders").add(order); + + assertEquals(custOrderCount + 1, cust.getList("orders").size()); + + // Build apply changes command + das.applyChanges(root); + + // verify cust1 relationship updates + select = das + .createCommand("SELECT * FROM CUSTOMER LEFT JOIN ANORDER ON CUSTOMER.ID = ANORDER.CUSTOMER_ID where CUSTOMER.ID = ?"); + + select.setParameter(1, new Integer(custID)); + root = select.executeQuery(); + + assertEquals(custOrderCount + 1, root.getList("CUSTOMER[1]/orders").size()); + + } + + public void testDiltonsInsertWorkaround() throws Exception { + + // String sql = "insert into conmgt.serverstatus (statusid, + // managedserverid, timestamp) values (316405209, 316405209, '2005-11-23 + // 19:29:52.636')"; + // String sql = "insert into conmgt.serverstatus (managedserverid, + // timestamp) values (316405209, '2005-11-23 19:29:52.636')"; + String sql = "insert into conmgt.serverstatus (managedserverid, timestamp) values (?, ?)"; + + DAS das = DAS.FACTORY.createDAS(getConnection()); + Command insert = das.createCommand(sql); + insert.setParameter(1, new Integer(316405209)); + insert.setParameter(2, "2005-11-23 19:29:52.636"); + insert.execute(); + + // Verify + Command select = das.createCommand("Select * from conmgt.serverstatus"); + DataObject root = select.executeQuery(); + assertEquals(1, root.getList("SERVERSTATUS").size()); + + } + + public void testWASDefect330118() throws Exception { + + // Create the group and set common connection + DAS das = DAS.FACTORY + .createDAS(getConfig("CustomersOrdersConfig.xml"), getConnection()); + + // Read all customers and add one + Command read = das.getCommand("all customers"); + DataObject root = read.executeQuery(); + int numCustomers = root.getList("CUSTOMER").size(); + + DataObject newCust = root.createDataObject("CUSTOMER"); + newCust.set("ID", new Integer(100)); + newCust.set("ADDRESS", "5528 Wells Fargo Drive"); + newCust.set("LASTNAME", "Gerkin"); + + // Now delete this new customer + newCust.delete(); + + das.applyChanges(root); + + // Verify + root = read.executeQuery(); + assertEquals(numCustomers, root.getList("CUSTOMER").size()); + + } + + /** + * Should be able to explicitly set a parameter to null. But, should require + * that the parameter type is set. + */ + public void testDiltonsNullParameterBug1() throws Exception { + DAS das = DAS.FACTORY.createDAS(getConnection()); + Command insert = das.createCommand("insert into CUSTOMER values (?, ?, ?)"); + insert.setParameter(1, new Integer(10)); + insert.setParameter(2, null); + insert.setParameter(3, "5528 Wells Fargo Dr"); + insert.execute(); + + // Verify + Command select = das.createCommand("Select * from CUSTOMER where ID = 10"); + DataObject root = select.executeQuery(); + assertEquals(1, root.getList("CUSTOMER").size()); + assertEquals("5528 Wells Fargo Dr", root.get("CUSTOMER[1]/ADDRESS")); + + } + + /** + * Error by not setting a parameter + */ + public void testDiltonsNullParameterBug2() throws Exception { + DAS das = DAS.FACTORY.createDAS(getConnection()); + Command insert = das.createCommand("insert into CUSTOMER values (?, ?, ?)"); + insert.setParameter(1, new Integer(10)); + // insert.setParameterValue("LASTNAME", null); + insert.setParameter(3, "5528 Wells Fargo Dr"); + + try { + insert.execute(); + fail(); + } catch (RuntimeException e) { + // Expected since "LASTNAME" parameter not set + } + } + + /** + * Set parameter to empty string + */ + public void testDiltonsNullParameterBug3() throws Exception { + DAS das = DAS.FACTORY.createDAS(getConnection()); + Command insert = das.createCommand("insert into CUSTOMER values (?, ?, ?)"); + insert.setParameter(1, new Integer(10)); + insert.setParameter(2, ""); + insert.setParameter(3, "5528 Wells Fargo Dr"); + insert.execute(); + + // Verify + Command select = das.createCommand("Select * from CUSTOMER where ID = 10"); + DataObject root = select.executeQuery(); + assertEquals(1, root.getList("CUSTOMER").size()); + assertEquals("5528 Wells Fargo Dr", root.get("CUSTOMER[1]/ADDRESS")); + + } + + public void testUpdateChildThatHasGeneratedKey() throws Exception { + + DAS das = DAS.FACTORY.createDAS(getConfig("CompanyConfig.xml"), getConnection()); + + // Read a specific company based on the known ID + Command readCust = das.getCommand("all companies and departments"); + DataObject root = readCust.executeQuery(); + DataObject lastCustomer = root.getDataObject("COMPANY[3]"); + Iterator i = lastCustomer.getList("departments").iterator(); + Random generator = new Random(); + int random = generator.nextInt(1000) + 1; + DataObject department; + while (i.hasNext()) { + department = (DataObject) i.next(); + // System.out.println("Modifying department: " + + // department.getString("NAME")); + department.setString("NAME", "Dept-" + random); + random = random + 1; + } + + das.applyChanges(root); + } + + /** + * Yin Chen reports ... "In the class Statement, method: public int + * executeUpdate(Parameters parameters) - its tossing out RuntimeException + * when the value of the parameter is null. " + * + * His example build a update statement and sets one parameter value to be + * null. I will try to duplicate with an insert since that is simpler + * + */ + public void testYingChen12162005() throws Exception { + DAS das = DAS.FACTORY.createDAS(getConnection()); + Command insert = das + .createCommand("insert into CUSTOMER values (?, ?, ?)"); + insert.setParameter(1, new Integer(10)); + insert.setParameter(2, "Williams"); + insert.setParameter(3, null); + insert.execute(); + + // Verify + Command select = das.createCommand("Select * from CUSTOMER where ID = 10"); + DataObject root = select.executeQuery(); + assertEquals(1, root.getList("CUSTOMER").size()); + assertNull(root.get("CUSTOMER[1]/ADDRESS")); + + } + + /** + * Formely tests concerning Tuscany-433. The error causing these tests was cleared up when + * the method for handling parameters was changed. + */ + public void testReadModifyApply() + throws Exception + { + + + // Provide updatecommand programmatically via config + ConfigHelper helper = new ConfigHelper(); + helper.addUpdateStatement("update CUSTOMER set LASTNAME = ? where ID = ?", "CUSTOMER", "LASTNAME ID"); + + DAS das = DAS.FACTORY.createDAS(helper.getConfig(), getConnection()); + + //Read customer 1 + Command select = das.createCommand( "Select * from CUSTOMER where ID = 1" ); + DataObject root = select.executeQuery(); + + DataObject customer = (DataObject) root.get( "CUSTOMER[1]" ); + + //Modify customer + customer.set( "LASTNAME", "Pavick" ); + + das.applyChanges( root ); + + //Verify changes + root = select.executeQuery(); + assertEquals( "Pavick", root.getString( "CUSTOMER[1]/LASTNAME" ) ); + + } + + public void testReadModifyApply1() + throws Exception + { + DAS das = DAS.FACTORY.createDAS(getConfig("basicCustomerMappingWithCUD2.xml"), getConnection()); + //Read customer 1 + Command select = das.createCommand( "Select * from CUSTOMER where ID = 1" ); + DataObject root = select.executeQuery(); + + DataObject customer = (DataObject) root.get( "CUSTOMER[1]" ); + + //Modify customer + customer.set( "LASTNAME", "Pavick" ); + + //Build apply changes command + das.applyChanges( root ); + + //Verify changes + root = select.executeQuery(); + assertEquals( "Pavick", root.getString( "CUSTOMER[1]/LASTNAME" ) ); + + } + +}
\ No newline at end of file diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/CrudWithChangeHistory.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/CrudWithChangeHistory.java new file mode 100644 index 0000000000..71b6da3f52 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/CrudWithChangeHistory.java @@ -0,0 +1,316 @@ +/** + * + * 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; + +/* + * This provdes the simplest examples that make use of the change history. The + * assumptions are: + * + * Single type Change history utilized Dynamic DataObjects + * + * + */ + +import java.util.Iterator; + +import org.apache.tuscany.das.rdb.Command; +import org.apache.tuscany.das.rdb.ConfigHelper; +import org.apache.tuscany.das.rdb.DAS; +import org.apache.tuscany.das.rdb.test.data.CustomerData; +import org.apache.tuscany.das.rdb.test.data.OrderDetailsData; +import org.apache.tuscany.das.rdb.test.framework.DasTest; + +import commonj.sdo.DataObject; + +public class CrudWithChangeHistory extends DasTest { + + protected void setUp() throws Exception { + super.setUp(); + new CustomerData(getAutoConnection()).refresh(); + new OrderDetailsData(getAutoConnection()).refresh(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + /** + * Read and modify a customer. Provide needed Create/Update/Delete + * statements programatically + */ + public void testReadModifyApply() throws Exception { + + // Provide updatecommand programmatically via config + ConfigHelper helper = new ConfigHelper(); + helper.addUpdateStatement("update CUSTOMER set LASTNAME = ?, ADDRESS = ? where ID = ?", + "CUSTOMER", "LASTNAME ADDRESS ID"); + + DAS das = DAS.FACTORY.createDAS(helper.getConfig(), getConnection()); + // Read customer 1 + Command select = das.createCommand("Select * from CUSTOMER where ID = 1"); + DataObject root = select.executeQuery(); + + DataObject customer = (DataObject) root.get("CUSTOMER[1]"); + + // Modify customer + customer.set("LASTNAME", "Pavick"); + + // Build apply changes command + das.applyChanges(root); + + // Verify changes + root = select.executeQuery(); + assertEquals("Pavick", root.getString("CUSTOMER[1]/LASTNAME")); + + } + + /** + * Read and modify a customer. Provide needed Create/Update/Delete + * statements via xml file + */ + public void testReadModifyApply1() throws Exception { + + DAS das = DAS.FACTORY.createDAS(getConfig("basicCustomerMappingWithCUD.xml"), getConnection()); + // Read customer 1 + Command select = das.createCommand("Select * from CUSTOMER where ID = 1"); + DataObject root = select.executeQuery(); + + DataObject customer = (DataObject) root.get("CUSTOMER[1]"); + + // Modify customer + customer.set("LASTNAME", "Pavick"); + + // Build apply changes command + das.applyChanges(root); + + // Verify changes + root = select.executeQuery(); + assertEquals("Pavick", root.getString("CUSTOMER[1]/LASTNAME")); + + } + + /** + * Same as previous but: Utilizes generated CUD statements Key info provided + * programatically + */ + public void testReadModifyApply2() throws Exception { + + DAS das = DAS.FACTORY.createDAS(getConnection()); + // Read customer with particular ID + Command select = das.createCommand("Select * from CUSTOMER where ID = 1"); + DataObject root = select.executeQuery(); + + DataObject customer = root.getDataObject("CUSTOMER[1]"); + + // Modify customer + customer.set("LASTNAME", "Pavick"); + + // Build apply changes command + das.applyChanges(root); + + // Verify the change + root = select.executeQuery(); + assertEquals("Pavick", root.getDataObject("CUSTOMER[1]").getString("LASTNAME")); + + } + + /** + * Builds on previous but: 1. Key info provided via XML file + */ + public void testReadModifyApply3() throws Exception { + DAS das = DAS.FACTORY.createDAS(getConfig("basicCustomerMapping.xml"), getConnection()); + // Read customer with particular ID + Command select = das.createCommand("Select * from CUSTOMER where ID = 1"); + DataObject root = select.executeQuery(); + + DataObject customer = (DataObject) root.get("CUSTOMER[1]"); + + // Modify customer + customer.set("LASTNAME", "Pavick"); + + // Build apply changes command + das.applyChanges(root); + + // Verify the change + root = select.executeQuery(); + assertEquals("Pavick", root.getDataObject("CUSTOMER[1]").getString("LASTNAME")); + + } + + /** + * Test ability to handle multiple changes to the graph including + * Creates/Updates/Deletes Employs generated CUD + */ + public void testReadModifyDeleteInsertApply() throws Exception { + + DAS das = DAS.FACTORY.createDAS(getConfig("basicCustomerMapping.xml"), getConnection()); + // Read some customers + Command select = das.createCommand("Select * from CUSTOMER where LASTNAME = 'Williams'"); + DataObject root = select.executeQuery(); + + DataObject cust1 = (DataObject) root.getList("CUSTOMER").get(0); + DataObject cust2 = (DataObject) root.getList("CUSTOMER").get(1); + DataObject cust3 = (DataObject) root.getList("CUSTOMER").get(2); + + // Modify a customer + cust1.set("LASTNAME", "Pavick"); + int cust1ID = cust1.getInt("ID"); + + // Save IDs before delete + int cust2ID = cust2.getInt("ID"); + int cust3ID = cust3.getInt("ID"); + // Delete a couple + cust2.delete(); + cust3.delete(); + + // Create a new customer + DataObject cust4 = root.createDataObject("CUSTOMER"); + cust4.set("ID", new Integer(100)); + cust4.set("ADDRESS", "5528 Wells Fargo Drive"); + cust4.set("LASTNAME", "Gerkin"); + + // Build apply changes command + das.applyChanges(root); + + // Verify deletes + select = das.createCommand("Select * from CUSTOMER where ID = ?"); + select.setParameter(1, new Integer(cust2ID)); + root = select.executeQuery(); + assertTrue(root.getList("CUSTOMER").isEmpty()); + // reparameterize same command + select.setParameter(1, new Integer(cust3ID)); + root = select.executeQuery(); + assertTrue(root.getList("CUSTOMER").isEmpty()); + + // verify insert + select.setParameter(1, new Integer(100)); + root = select.executeQuery(); + assertEquals(1, root.getList("CUSTOMER").size()); + assertEquals("5528 Wells Fargo Drive", root.getString("CUSTOMER[1]/ADDRESS")); + assertEquals("Gerkin", root.getString("CUSTOMER[1]/LASTNAME")); + + // verify update + select.setParameter(1, new Integer(cust1ID)); + root = select.executeQuery(); + assertEquals("Pavick", root.getString("CUSTOMER[1]/LASTNAME")); + + } + + public void testReadModifyApplyWithAssumedID() throws Exception { + + DAS das = DAS.FACTORY.createDAS(getConnection()); + // Read customer with particular ID + Command select = das.createCommand("Select * from CUSTOMER"); + DataObject root = select.executeQuery(); + + DataObject customer = root.getDataObject("CUSTOMER[1]"); + + // Modify customer + customer.set("LASTNAME", "Pavick"); + + DataObject customerForDelete = root.getDataObject("CUSTOMER[2]"); + String deletedLastName = customerForDelete.getString("LASTNAME"); + customerForDelete.delete(); + + DataObject newCustomer = root.createDataObject("CUSTOMER"); + newCustomer.set("LASTNAME", "NewCustomer"); + newCustomer.setInt("ID", 9000); + + // Build apply changes command + das.applyChanges(root); + + // Verify the change + root = select.executeQuery(); + assertEquals("Pavick", getCustomerByLastName(root, "Pavick").getString("LASTNAME")); + assertEquals("NewCustomer", getCustomerByLastName(root, "NewCustomer").getString("LASTNAME")); + assertNull(getCustomerByLastName(root, deletedLastName)); + + } + + public void testReadModifyApplyWithAssumedIDFailure() throws Exception { + DAS das = DAS.FACTORY.createDAS(getConnection()); + Command select = das.createCommand("Select * from ORDERDETAILS"); + + DataObject root = select.executeQuery(); + + DataObject od = root.getDataObject("ORDERDETAILS[1]"); + + // Modify customer + od.setInt("PRODUCTID", 72); + + // Flush changes -- This should fail because Order Details does not have + // a column that + // we can assume to be an ID + try { + das.applyChanges(root); + } catch (RuntimeException ex) { + assertTrue(ex.getMessage().contains("changed in the DataGraph but is not present in the Config")); + } + + } + + public void testReadModifyApplyWithAssumedIDFailure2() throws Exception { + DAS das = DAS.FACTORY.createDAS(getConnection()); + Command select = das.createCommand("Select * from ORDERDETAILS"); + DataObject root = select.executeQuery(); + + DataObject od = root.getDataObject("ORDERDETAILS[1]"); + od.delete(); + + // Flush changes -- This should fail because Order Details does not have + // a column that + // we can assume to be an ID + try { + das.applyChanges(root); + } catch (RuntimeException ex) { + assertTrue(ex.getMessage().contains("changed in the DataGraph but is not present in the Config")); + } + + } + + public void testReadModifyApplyWithAssumedIDFailure3() throws Exception { + DAS das = DAS.FACTORY.createDAS(getConnection()); + Command select = das.createCommand("Select * from ORDERDETAILS"); + DataObject root = select.executeQuery(); + + DataObject od = root.createDataObject("ORDERDETAILS"); + + // Modify customer + od.setInt("PRODUCTID", 72); + od.setInt("ORDERID", 500); + + // Flush changes -- This should fail because Order Details does not have + // a column that + // we can assume to be an ID + try { + das.applyChanges(root); + } catch (RuntimeException ex) { + assertTrue(ex.getMessage().contains("changed in the DataGraph but is not present in the Config")); + } + + } + + private DataObject getCustomerByLastName(DataObject root, String name) { + Iterator i = root.getList("CUSTOMER").iterator(); + while (i.hasNext()) { + DataObject obj = (DataObject) i.next(); + if (name.equals(obj.getString("LASTNAME"))) + return obj; + } + return null; + } +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/DefectTests.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/DefectTests.java new file mode 100644 index 0000000000..4f8982a140 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/DefectTests.java @@ -0,0 +1,106 @@ +/** + * + * 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; + +/* + * These tests attempt to duplicate customer reported errors and then to verify + * any necessary fix. + * + */ + +import java.util.Iterator; +import java.util.Random; + +import org.apache.tuscany.das.rdb.Command; +import org.apache.tuscany.das.rdb.ConfigHelper; +import org.apache.tuscany.das.rdb.DAS; +import org.apache.tuscany.das.rdb.test.data.CompanyData; +import org.apache.tuscany.das.rdb.test.data.CompanyDeptData; +import org.apache.tuscany.das.rdb.test.data.CustomerData; +import org.apache.tuscany.das.rdb.test.data.DepEmpData; +import org.apache.tuscany.das.rdb.test.data.DepartmentData; +import org.apache.tuscany.das.rdb.test.data.EmployeeData; +import org.apache.tuscany.das.rdb.test.data.OrderData; +import org.apache.tuscany.das.rdb.test.framework.DasTest; + +import commonj.sdo.DataObject; + +public class DefectTests extends DasTest { + + protected void setUp() throws Exception { + super.setUp(); + new CustomerData(getAutoConnection()).refresh(); + new OrderData(getAutoConnection()).refresh(); + + new CompanyData(getAutoConnection()).refresh(); + new DepartmentData(getAutoConnection()).refresh(); + new EmployeeData(getAutoConnection()).refresh(); + new CompanyDeptData(getAutoConnection()).refresh(); + new DepEmpData(getAutoConnection()).refresh(); + + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + /** + * Read a specific customer + */ + public void testDiltonsInsert() throws Exception { + + // String sql = "insert into conmgt.serverstatus (statusid, + // managedserverid, timestamp) values (316405209, 316405209, '2005-11-23 + // 19:29:52.636')"; + String sql = "insert into conmgt.serverstatus (managedserverid, timestamp) values (316405209, '2005-11-23 19:29:52.636')"; + DAS das = DAS.FACTORY.createDAS(getConnection()); + Command insert = das.createCommand(sql); + insert.execute(); + + // Verify + Command select = das + .createCommand("Select * from conmgt.serverstatus where statusid = 316405209"); + DataObject root = select.executeQuery(); + assertEquals(1, root.getList("conmgt.serverstatus").size()); + + } + + + public void testUpdateChildThatHasGeneratedKey() throws Exception { + + DAS das = DAS.FACTORY.createDAS(getConfig("CompanyConfig.xml")); + + //Read a specific company based on the known ID + Command readCust = das.getCommand("all companies and departments"); + DataObject root = readCust.executeQuery(); + DataObject lastCustomer = root.getDataObject("COMPANY[3]"); + Iterator i = lastCustomer.getList("departments").iterator(); + Random generator = new Random(); + int random = generator.nextInt(1000) + 1; + DataObject department; + while (i.hasNext()) { + department = (DataObject)i.next(); + System.out.println("Modifying department: " + department.getString("NAME")); + department.setString("NAME", "Dept-" + random); + random = random + 1; + } + + das.applyChanges(root); + + } + +}
\ No newline at end of file diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/ExceptionTests.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/ExceptionTests.java new file mode 100644 index 0000000000..677cfecae9 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/ExceptionTests.java @@ -0,0 +1,137 @@ +/** + * + * 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; + +import java.sql.Connection; + +import org.apache.tuscany.das.rdb.Command; +import org.apache.tuscany.das.rdb.DAS; +import org.apache.tuscany.das.rdb.test.customer.CustomerFactory; +import org.apache.tuscany.das.rdb.test.data.BookData; +import org.apache.tuscany.das.rdb.test.data.CustomerData; +import org.apache.tuscany.das.rdb.test.data.OrderData; +import org.apache.tuscany.das.rdb.test.data.OrderDetailsData; +import org.apache.tuscany.das.rdb.test.framework.DasTest; +import org.apache.tuscany.sdo.util.SDOUtil; + +public class ExceptionTests extends DasTest { + + public ExceptionTests() { + super(); + } + + protected void setUp() throws Exception { + super.setUp(); + + new CustomerData(getAutoConnection()).refresh(); + new OrderData(getAutoConnection()).refresh(); + new BookData(getAutoConnection()).refresh(); + new OrderDetailsData(getAutoConnection()).refresh(); + + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public void testMissingConnection() throws Exception { + DAS das = DAS.FACTORY.createDAS((Connection)null); + + try { + Command readCustomers = das.createCommand("select * from CUSTOMER where ID = 1"); + readCustomers.executeQuery(); + fail("RuntimeException should be thrown"); + } catch (RuntimeException ex) { + assertEquals("No connection has been provided and no data source has been specified", ex.getMessage()); + } + + } + + public void testUnregisteredTypes() throws Exception { + DAS das = DAS.FACTORY.createDAS(getConfig("staticInvalid.xml"), getConnection()); + Command readCustomers = das.createCommand("select * from CUSTOMER where ID = 1"); + + try { + readCustomers.executeQuery(); + + fail("Exception should be thrown"); + } catch (RuntimeException ex) { + assertEquals("SDO Types have not been registered for URI invalidURI", ex.getMessage()); + } + } + + public void testMissingMapping() throws Exception { + SDOUtil.registerStaticTypes(CustomerFactory.class); + DAS das = DAS.FACTORY.createDAS(getConfig("staticCustomer.xml"), getConnection()); + Command readCustomers = das.createCommand("select * from CUSTOMER where ID = 1"); + + try { + readCustomers.executeQuery(); + + fail("Exception should be thrown"); + } catch (RuntimeException ex) { + assertEquals("An SDO Type with name CUSTOMER was not found", ex.getMessage()); + } + + } + + /** + * Test ability to describe problem when a user passes an empty stream + */ + public void testEmptyStream() throws Exception { + try { + DAS.FACTORY.createDAS(getConfig("NonExistingFile.xml")); + fail("Error should be thrown"); + } catch (RuntimeException e) { + assertEquals( + "Cannot load configuration from a null InputStream. Possibly caused by an incorrect config xml file name", + e.getMessage()); + } + } + + /** + * Test ability to describe problem when a user passes an empty stream + */ + public void testEmptyStream2() throws Exception { + try { + DAS.FACTORY.createDAS(getConfig("NonExistingFile.xml")); + fail("Error should be thrown"); + } catch (RuntimeException e) { + assertEquals( + "Cannot load configuration from a null InputStream. Possibly caused by an incorrect config xml file name", + e.getMessage()); + } + } + + + public void testReadOrdersAndDetails2() throws Exception { + + DAS das = DAS.FACTORY.createDAS(getConfig("InvalidConfig1.xml"), getConnection()); + Command read = das + .createCommand( + "SELECT * FROM ANORDER LEFT JOIN ORDERDETAILS ON ANORDER.ID = ORDERDETAILS.ORDERID ORDER BY ANORDER.ID"); + + try { + read.executeQuery(); + } catch ( Exception ex ) { + assertEquals("The parent table (xxx) in relationship ORDERDETAILS was not found.", ex.getMessage()); + } + + } + + +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/GeneratedCommandTests.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/GeneratedCommandTests.java new file mode 100644 index 0000000000..278c4de1ee --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/GeneratedCommandTests.java @@ -0,0 +1,92 @@ +/** + * + * 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; + +import java.util.List; + +import org.apache.tuscany.das.rdb.test.commands.ReadCustomersByLastnameCommand; +import org.apache.tuscany.das.rdb.test.commands.ReadCustomersCommand; +import org.apache.tuscany.das.rdb.test.commands.ReadCustomersStaticTypesCommand; +import org.apache.tuscany.das.rdb.test.commands.ReadCustomersWithShapeCommand; +import org.apache.tuscany.das.rdb.test.commands.SimpleReadCustomersWithShapeCommand; +import org.apache.tuscany.das.rdb.test.customer.Customer; +import org.apache.tuscany.das.rdb.test.data.CustomerData; +import org.apache.tuscany.das.rdb.test.framework.DasTest; + +import commonj.sdo.DataObject; + +public class GeneratedCommandTests extends DasTest { + + protected void setUp() throws Exception { + super.setUp(); + + new CustomerData(getAutoConnection()).refresh(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public void testReadCustomers() throws Exception { + ReadCustomersCommand cmd = new ReadCustomersCommand(); + cmd.setConnection(getConnection()); + + DataObject root = cmd.executeQuery(); + assertEquals(5, root.getList("CUSTOMER").size()); + } + + public void testReadSomeCustomers() throws Exception { + ReadCustomersByLastnameCommand cmd = new ReadCustomersByLastnameCommand(); + cmd.setConnection(getConnection()); + cmd.setParameter(1, "Williams"); + + DataObject root = cmd.executeQuery(); + assertEquals(4, root.getList("CUSTOMER").size()); + + } + + public void testReadCustomersStaticTypes() throws Exception { + ReadCustomersStaticTypesCommand cmd = new ReadCustomersStaticTypesCommand(); + cmd.setConnection(getConnection()); + cmd.setParameter(1, "Williams"); + + DataObject root = cmd.executeQuery(); + + List customers = root.getList("Customer"); + assertEquals(4, customers.size()); + + Customer cust1 = (Customer) customers.get(0); + assertEquals("Williams", cust1.getLastName()); + + } + + public void testSimpleReadCustomersWithShape() throws Exception { + SimpleReadCustomersWithShapeCommand cmd = new SimpleReadCustomersWithShapeCommand(); + cmd.setConnection(getConnection()); + DataObject root = cmd.executeQuery(); + assertEquals(5, root.getList("CUSTOMER").size()); + } + + public void testReadCustomersOrdersWithShape() throws Exception { + ReadCustomersWithShapeCommand cmd = new ReadCustomersWithShapeCommand(); + cmd.setConnection(getConnection()); + + DataObject root = cmd.executeQuery(); + assertEquals(5, root.getList("CUSTOMER").size()); + } + +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/GeneratedId.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/GeneratedId.java new file mode 100644 index 0000000000..4ecb166a10 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/GeneratedId.java @@ -0,0 +1,262 @@ +/** + * + * 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; + +/* + * Generated IDs + * + * + */ + +import org.apache.tuscany.das.rdb.Command; +import org.apache.tuscany.das.rdb.DAS; +import org.apache.tuscany.das.rdb.test.data.CompanyData; +import org.apache.tuscany.das.rdb.test.data.DepartmentData; +import org.apache.tuscany.das.rdb.test.framework.DasTest; + +import commonj.sdo.DataObject; + +public class GeneratedId extends DasTest { + + protected void setUp() throws Exception { + super.setUp(); + + new CompanyData(getAutoConnection()).refresh(); + new DepartmentData(getAutoConnection()).refresh(); + + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + // Test insert into row with generated ID + public void testInsert() throws Exception { + + DAS das = DAS.FACTORY.createDAS(getConnection()); + Command insert = das.createCommand("insert into COMPANY (NAME) values (?)"); + insert.setParameter(1, "AAA Rental"); + insert.execute(); + + // Verify insert + // Verify + Command select = das.createCommand("Select ID, NAME from COMPANY"); + DataObject root = select.executeQuery(); + + assertEquals(4, root.getList("COMPANY").size()); + assertTrue(root.getInt("COMPANY[1]/ID") > 0); + + } + + // Test back to back insertions with the same command + public void testInsert2() throws Exception { + + DAS das = DAS.FACTORY.createDAS(getConnection()); + Command insert = das.createCommand("insert into COMPANY (NAME) values (?)"); + insert.setParameter(1, "AAA Rental"); + insert.execute(); + + // insert another using same command + insert.setParameter(1, "BBB Rental"); + insert.execute(); + + // Verify insert + // Verify + Command select = das.createCommand("Select ID, NAME from COMPANY"); + DataObject root = select.executeQuery(); + + assertEquals(5, root.getList("COMPANY").size()); + + } + + // Test ability to retrieve and utilize the generated key + public void testInsert3() throws Exception { + DAS das = DAS.FACTORY.createDAS(getConnection()); + Command insert = das.createCommand("insert into COMPANY (NAME) values (?)"); + insert.setParameter(1, "AAA Rental"); + insert.execute(); +// Integer key = (Integer) insert.getParameterValue("generated_key"); + Integer key = (Integer) insert.getGeneratedKey(); + + // Verify insert + Command select = das.createCommand("Select ID, NAME from COMPANY where ID = ?"); + select.setParameter(1, key); + DataObject root = select.executeQuery(); + assertEquals(key, root.get("COMPANY[1]/ID")); + + } + + // Test ability to propogate generated values back to owning data objects + public void testPropagateIds() throws Exception { + + DAS das = DAS.FACTORY.createDAS(getConfig("CompanyConfig.xml"), getConnection()); + Command select = das.getCommand("all companies"); + DataObject root = select.executeQuery(); + + // Create a new Company + DataObject company = root.createDataObject("COMPANY"); + company.setString("NAME", "Do-rite Pest Control"); + + // verify pre-condition (id is not there until after flush) + assertNull(company.get("ID")); + + // Flush changes + das.applyChanges(root); + + // Save the id + Integer id = (Integer) company.get("ID"); + + // Verify the change + select = das.createCommand("Select * from COMPANY where ID = ?"); + select.setParameter(1, id); + root = select.executeQuery(); + assertEquals("Do-rite Pest Control", root.getDataObject("COMPANY[1]").getString("NAME")); + + } + + /** + * Same as above but metadata provided by XML config file + */ + public void testPropagateIdsXML() throws Exception { + DAS das = DAS.FACTORY.createDAS(getConfig("basicCompanyMapping.xml"), getConnection()); + Command select = das.createCommand("Select * from COMPANY"); + DataObject root = select.executeQuery(); + + // Create a new Company + DataObject company = root.createDataObject("COMPANY"); + company.setString("NAME", "Do-rite Pest Control"); + + + // verify pre-condition (id is not there until after flush) + assertNull(company.get("ID")); + + // Flush changes + das.applyChanges(root); + + // Save the id + Integer id = (Integer) company.get("ID"); + + // Verify the change + select = das.createCommand("Select * from COMPANY where ID = ?"); + select.setParameter(1, id); + root = select.executeQuery(); + assertEquals("Do-rite Pest Control", root.getDataObject("COMPANY[1]").getString("NAME")); + + } + + /** + * Test ability to correctly flush heirarchy of objects that have generated + * keys + */ + public void testFlushCreateHeirarchy() throws Exception { + + DAS das = DAS.FACTORY.createDAS(getConfig("basicCompanyDepartmentMapping.xml"), getConnection()); + String selectCompanys = "SELECT * FROM COMPANY LEFT JOIN DEPARTMENT ON COMPANY.ID = DEPARTMENT.COMPANYID"; + + Command select = das.createCommand(selectCompanys); + DataObject root = select.executeQuery(); + + // Create a new Company + DataObject company = root.createDataObject("COMPANY"); + company.setString("NAME", "Do-rite Pest Control"); + + // Create a new Department + // Do not set ID or CompanyID since these are generated + // ID INT, NAME VARCHAR(30), LOCATION VARCHAR(30), NUMBER VARCHAR(10), + // COMPANYID INT, EOTM INT + DataObject department = root.createDataObject("DEPARTMENT"); + department.setString("NAME", "Do-rite Pest Control"); + department.setString("LOCATION", "The boonies"); + department.setString("NUMBER", "101"); + + // Associate the new department with the new company + company.getList("departments").add(department); + + das.applyChanges(root); + + // Save the id + Integer id = (Integer) company.get("ID"); + + // Verify the change + String selectString = "SELECT * FROM COMPANY LEFT JOIN DEPARTMENT ON COMPANY.ID = DEPARTMENT.COMPANYID WHERE COMPANY.ID = ?"; + + select = das.createCommand(selectString); + select.setParameter(1, id); + root = select.executeQuery(); + assertEquals("Do-rite Pest Control", root.getDataObject("COMPANY[1]").getString("NAME")); + + } + + /** + * Test ability to correctly flush heirarchy of objects that have generated + * keys even when a created object has legal but NULL property values + */ + public void testFlushCreateHeirarchy2() throws Exception { + + String selectCompanys = "SELECT * FROM COMPANY LEFT JOIN DEPARTMENT ON COMPANY.ID = DEPARTMENT.COMPANYID"; + + DAS das = DAS.FACTORY.createDAS(getConfig("basicCompanyDepartmentMapping.xml"), getConnection()); + Command select = das.createCommand(selectCompanys); + DataObject root = select.executeQuery(); + + // Create a new Company + DataObject company = root.createDataObject("COMPANY"); + company.setString("NAME", "Do-rite Pest Control"); + + // Create a new Department + // Do not set ID or CompanyID since these are generated + // ID INT, NAME VARCHAR(30), LOCATION VARCHAR(30), NUMBER VARCHAR(10), + // COMPANYID INT, EOTM INT + DataObject department = root.createDataObject("DEPARTMENT"); + department.setString("NAME", "Do-rite Pest Control"); + // Do not set this property to force storing NULL to DB + // department.setString("LOCATION", "The boonies"); + department.setString("NUMBER", "101"); + + // Associate the new department with the new company + company.getList("departments").add(department); + + das.applyChanges(root); + + // Save the id + Integer id = (Integer) company.get("ID"); + + // Verify the change + String selectString = "SELECT * FROM COMPANY LEFT JOIN DEPARTMENT ON COMPANY.ID = DEPARTMENT.COMPANYID WHERE COMPANY.ID = ?"; + + select = das.createCommand(selectString); + select.setParameter(1, id); + root = select.executeQuery(); + assertEquals("Do-rite Pest Control", root.getDataObject("COMPANY[1]").getString("NAME")); + + } + + // Test that error is thrown when no key has been generated (as in a select) + public void testRead() throws Exception { + DAS das = DAS.FACTORY.createDAS(getConnection()); + Command select = das.createCommand("Select * from COMPANY"); + select.executeQuery(); + + try { + select.getGeneratedKey(); + fail("Should throw exception"); + } catch (RuntimeException e) { + assertEquals("This method is only valid for insert commands", e.getMessage()); + } + } + +}
\ No newline at end of file diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/GraphMergeTests.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/GraphMergeTests.java new file mode 100644 index 0000000000..e1acf327f3 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/GraphMergeTests.java @@ -0,0 +1,150 @@ +/** + * + * 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; + +import java.util.ArrayList; + +import org.apache.tuscany.das.rdb.Command; +import org.apache.tuscany.das.rdb.DAS; +import org.apache.tuscany.das.rdb.merge.impl.GraphMerger; +import org.apache.tuscany.das.rdb.test.data.CustomerData; +import org.apache.tuscany.das.rdb.test.data.OrderData; +import org.apache.tuscany.das.rdb.test.framework.DasTest; + +import commonj.sdo.DataObject; + +public class GraphMergeTests extends DasTest { + + protected void setUp() throws Exception { + super.setUp(); + + new CustomerData(getAutoConnection()).refresh(); + new OrderData(getAutoConnection()).refresh(); + + } + + + public void testSingleTableMerge() throws Exception { + DAS das = DAS.FACTORY.createDAS(getConnection()); + Command select = das + .createCommand("Select ID, LASTNAME, ADDRESS from CUSTOMER where ID <= ?"); + select.setParameter(1, "3"); + DataObject graph1 = select.executeQuery(); + assertEquals(3, graph1.getList("CUSTOMER").size()); + + select.setParameter(1, "5"); + DataObject graph2 = select.executeQuery(); + assertEquals(5, graph2.getList("CUSTOMER").size()); + + GraphMerger merger = new GraphMerger(); + merger.addPrimaryKey("CUSTOMER.ID"); + DataObject mergedGraph = merger.merge(graph1, graph2); + + assertEquals(5, mergedGraph.getList("CUSTOMER").size()); + } + + public void testSingleTableMergeThreeGraphs() throws Exception { + DAS das = DAS.FACTORY.createDAS(getConnection()); + Command select = das + .createCommand("Select ID, LASTNAME, ADDRESS from CUSTOMER where ID <= ?"); + select.setParameter(1, "3"); + DataObject graph1 = select.executeQuery(); + assertEquals(3, graph1.getList("CUSTOMER").size()); + + select.setParameter(1, "4"); + DataObject graph2 = select.executeQuery(); + assertEquals(4, graph2.getList("CUSTOMER").size()); + + select.setParameter(1, "5"); + DataObject graph3 = select.executeQuery(); + assertEquals(5, graph3.getList("CUSTOMER").size()); + + GraphMerger merger = new GraphMerger(); + merger.addPrimaryKey("CUSTOMER.ID"); + ArrayList graphs = new ArrayList(); + graphs.add(graph1); + graphs.add(graph2); + graphs.add(graph3); + DataObject mergedGraph = merger.merge(graphs); + + assertEquals(5, mergedGraph.getList("CUSTOMER").size()); + + } + + + public void testMultiTableMerge2() throws Exception { + DAS das = DAS.FACTORY.createDAS(getConfig("CustomersOrdersConfig.xml"), getConnection()); + //Read some customers and related orders + Command select = das.createCommand( + "SELECT * FROM CUSTOMER LEFT JOIN ANORDER ON CUSTOMER.ID = ANORDER.CUSTOMER_ID where CUSTOMER.ID = ?"); + + select.setParameter(1, new Integer(1)); + DataObject graph1 = select.executeQuery(); + + DataObject customer = (DataObject)graph1.getList("CUSTOMER").get(0); + assertEquals(2, customer.getList("orders").size()); + + select.setParameter(1, new Integer(2)); + DataObject graph2 = select.executeQuery(); + DataObject customer2 = (DataObject)graph2.getList("CUSTOMER").get(0); + assertEquals(1, graph2.getList("CUSTOMER").size()); + assertEquals(1, customer2.getList("orders").size()); + assertEquals(2, customer2.getInt("ID")); + + GraphMerger merger = new GraphMerger(); + merger.addPrimaryKey("CUSTOMER.ID"); + merger.addPrimaryKey("ANORDER.ID"); + DataObject mergedGraph = merger.merge(graph1, graph2); + + assertEquals(3, mergedGraph.getList("ANORDER").size()); + assertEquals(2, mergedGraph.getList("CUSTOMER").size()); + + DataObject mergedCustomer = (DataObject) mergedGraph.getList("CUSTOMER").get(1); + assertEquals(2, mergedCustomer.getInt("ID")); + assertEquals(1, mergedCustomer.getList("orders").size()); + DataObject mergedOrder = (DataObject) mergedCustomer.getList("orders").get(0); + assertEquals(4, mergedOrder.getInt("ID")); + + } + + public void testMultiTableAppendSingleTable2() throws Exception { + DAS das = DAS.FACTORY.createDAS(getConfig("CustomersOrdersConfig.xml"), getConnection()); + //Read some customers and related orders + Command select = das.createCommand( + "SELECT * FROM CUSTOMER LEFT JOIN ANORDER ON CUSTOMER.ID = ANORDER.CUSTOMER_ID where CUSTOMER.ID = ?"); + + select.setParameter(1, new Integer(1)); + DataObject graph1 = select.executeQuery(); + + DataObject customer = (DataObject)graph1.getList("CUSTOMER").get(0); + assertEquals(2, customer.getList("orders").size()); + + DAS das2 = DAS.FACTORY.createDAS(getConnection()); + Command select2 = das2.createCommand("select * from ANORDER"); + DataObject graph2 = select2.executeQuery(); + assertEquals(4, graph2.getList("ANORDER").size()); + + GraphMerger merger = new GraphMerger(); + merger.addPrimaryKey("CUSTOMER.ID"); + merger.addPrimaryKey("ANORDER.ID"); + DataObject mergedGraph = merger.merge(graph1, graph2); + assertEquals(4, mergedGraph.getList("ANORDER").size()); + assertEquals(1, mergedGraph.getList("CUSTOMER").size()); + } + + +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/NameMappingTests.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/NameMappingTests.java new file mode 100644 index 0000000000..fed25abdb9 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/NameMappingTests.java @@ -0,0 +1,65 @@ +/** + * + * 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; + +/* + * + * + */ + +import org.apache.tuscany.das.rdb.Command; +import org.apache.tuscany.das.rdb.DAS; +import org.apache.tuscany.das.rdb.test.data.CustomerData; +import org.apache.tuscany.das.rdb.test.data.OrderData; +import org.apache.tuscany.das.rdb.test.framework.DasTest; + +import commonj.sdo.DataObject; + + +public class NameMappingTests extends DasTest { + + protected void setUp() throws Exception { + super.setUp(); + + new CustomerData(getAutoConnection()).refresh(); + new OrderData(getAutoConnection()).refresh(); + + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + /** + * Test ability to assign DataObject type and propertyaliases with xml file + */ + public void testRead() throws Exception { + + DAS das = DAS.FACTORY.createDAS(getConfig("customerMapping.xml"), getConnection()); + // Read a customer + Command select = das.createCommand( + "SELECT * FROM CUSTOMER WHERE CUSTOMER.ID = 1"); + + DataObject root = select.executeQuery(); + DataObject customer = root.getDataObject("Customer[1]"); + assertEquals(1, customer.getInt("id")); + assertEquals("1212 foobar lane", customer.getString("address")); + assertEquals("Williams", customer.getString("lastname")); + + } + +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/OCCTests.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/OCCTests.java new file mode 100644 index 0000000000..5ff387ed8b --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/OCCTests.java @@ -0,0 +1,102 @@ +/** + * + * 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; + +import org.apache.tuscany.das.rdb.Command; +import org.apache.tuscany.das.rdb.DAS; +import org.apache.tuscany.das.rdb.test.data.BookData; +import org.apache.tuscany.das.rdb.test.framework.DasTest; + +import commonj.sdo.DataObject; + +public class OCCTests extends DasTest { + protected void setUp() throws Exception { + super.setUp(); + + new BookData(getAutoConnection()).refresh(); + } + + + public void testSimpleOCC() throws Exception { + + DAS das = DAS.FACTORY.createDAS(getConfig("BooksConfig.xml"), getConnection()); + //Read a book instance + Command select = das.getCommand("select book 1"); + DataObject root = select.executeQuery(); + DataObject book = root.getDataObject("BOOK[1]"); + //Change a field to mark the instance 'dirty' + book.setInt("QUANTITY", 2); + + // Explicitly change OCC column in database to force collision + Command update = das.getCommand("update book 1"); + update.setParameter(1, new Integer(100)); + update.execute(); + + //Try to apply changes and catch the expected OCC Exception + try { + das.applyChanges(root); + fail("An OCCException should be thrown"); + } catch (RuntimeException ex) { + if ( !ex.getMessage().equals("OCC Exception") ) + throw ex; + } + } + + public void testManagedOCC() throws Exception { + DAS das = DAS.FACTORY.createDAS(getConfig("ManagedBooksConfig.xml"), getConnection()); + Command select = das.getCommand("select book 1"); + DataObject root = select.executeQuery(); + DataObject book = root.getDataObject("BOOK[1]"); + //Change a field to mark the instance 'dirty' + book.setInt("QUANTITY", 2); + int occValue = book.getInt("OCC"); + das.applyChanges(root); + + root = select.executeQuery(); + book = root.getDataObject("BOOK[1]"); + assertEquals(occValue + 1, book.getInt("OCC")); + } + + public void testManagedOCCFailure() throws Exception { + DAS das = DAS.FACTORY.createDAS(getConfig("ManagedBooksConfig.xml"), getConnection()); + //Read a book instance + Command select = das.getCommand("select book 1"); + DataObject root = select.executeQuery(); + DataObject book = root.getDataObject("BOOK[1]"); + //Change a field to mark the instance 'dirty' + book.setInt("QUANTITY", 2); + + + DAS das2 = DAS.FACTORY.createDAS(getConfig("ManagedBooksConfig.xml"), getConnection()); + //Read a book instance + Command select2= das2.getCommand("select book 1"); + DataObject root2 = select2.executeQuery(); + DataObject book2 = root2.getDataObject("BOOK[1]"); + //Change a field to mark the instance 'dirty' + book2.setInt("QUANTITY", 5); + das2.applyChanges(root2); + + //Try to apply changes and catch the expecetd OCC Exception + try { + das.applyChanges(root); + fail("An OCCException should be thrown"); + } catch (RuntimeException ex) { + if ( !ex.getMessage().equals("OCC Exception") ) + throw ex; + } + } +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/OneToOneRelationshipTests.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/OneToOneRelationshipTests.java new file mode 100644 index 0000000000..3039f4778e --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/OneToOneRelationshipTests.java @@ -0,0 +1,155 @@ +/** + * + * 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; + +import org.apache.tuscany.das.rdb.Command; +import org.apache.tuscany.das.rdb.DAS; +import org.apache.tuscany.das.rdb.test.data.CompanyData; +import org.apache.tuscany.das.rdb.test.data.CompanyEmpData; +import org.apache.tuscany.das.rdb.test.data.EmployeeData; +import org.apache.tuscany.das.rdb.test.framework.DasTest; + +import commonj.sdo.DataObject; + +public class OneToOneRelationshipTests extends DasTest { + + protected void setUp() throws Exception { + super.setUp(); + new CompanyData(getAutoConnection()).refresh(); + new EmployeeData(getAutoConnection()).refresh(); + new CompanyEmpData(getAutoConnection()).refresh(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + + /** + * Read Company and traverse to EOTM + */ + public void test1() throws Exception { + + DAS das = DAS.FACTORY + .createDAS(getConfig("CompanyEmployeeConfig.xml"), getConnection()); + + Command read = das.getCommand("get companies with employee of the month"); + DataObject root = read.executeQuery(); + DataObject employee = root.getDataObject("COMPANY[1]/company->employee_opposite"); + + assertEquals("Mary Smith", employee.getString("NAME")); + } + + + /** + * Read Employee and traverse to Company + */ + public void test2() throws Exception { + + DAS das = DAS.FACTORY + .createDAS(getConfig("CompanyEmployeeConfig.xml"), getConnection()); + + Command read = das.getCommand("get named employee with company"); + read.setParameter(1, "Mary Smith"); + DataObject root = read.executeQuery(); + DataObject company = root.getDataObject("EMPLOYEE[1]/company->employee"); + + assertEquals("ACME Publishing", company.getString("NAME")); + } + + + /** + * Un-assign employee O' month + */ + public void test3() throws Exception { + + DAS das = DAS.FACTORY + .createDAS(getConfig("CompanyEmployeeConfig.xml"), getConnection()); + + Command read = das.getCommand("get companies with employee of the month"); + DataObject root = read.executeQuery(); + DataObject company = root.getDataObject("COMPANY[1]"); + company.setDataObject("company->employee_opposite", null); + assertNull(company.getDataObject("company->employee_opposite")); + + //Flush changes + das.applyChanges(root); + + //Verify + root = read.executeQuery(); + company = root.getDataObject("COMPANY[1]"); + assertNull(company.getDataObject("company->employee_opposite")); + } + + /** + * Delete employee O' month + */ + public void test4() throws Exception { + + DAS das = DAS.FACTORY + .createDAS(getConfig("CompanyEmployeeConfig.xml"), getConnection()); + + Command read = das.getCommand("get companies with employee of the month"); + DataObject root = read.executeQuery(); + DataObject company = root.getDataObject("COMPANY[1]"); + DataObject employee = company.getDataObject("company->employee_opposite"); + employee.delete(); + assertNull(company.getDataObject("company->employee_opposite")); + + //Flush changes + das.applyChanges(root); + + //Verify + root = read.executeQuery(); + company = root.getDataObject("COMPANY[1]"); + assertNull(company.getDataObject("company->employee_opposite")); + } + + /** + * Add new employee O' month + */ + public void test5() throws Exception { + + DAS das = DAS.FACTORY + .createDAS(getConfig("CompanyEmployeeConfig.xml"), getConnection()); + + Command read = das.getCommand("get companies with employee of the month"); + DataObject root = read.executeQuery(); + DataObject company = root.getDataObject("COMPANY[1]"); + + //Create a new employee + DataObject employee = root.createDataObject("EMPLOYEE"); + employee.setString ("NAME", "Joe Hotshot"); + + //Assigne a EOTM + //Strangely this statement results in "Could not find relationships" error + //although "company.setDataObject("company->employee_opposite", null);" dos not + company.setDataObject("company->employee_opposite", employee); + + //Flush changes + das.applyChanges(root); + + //Verify + root = read.executeQuery(); + company = root.getDataObject("COMPANY[1]"); + + employee = root.getDataObject("COMPANY[1]/company->employee_opposite"); + + assertEquals("Joe Hotshot", employee.getString("NAME")); + + } +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/OperationOrderingTests.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/OperationOrderingTests.java new file mode 100644 index 0000000000..7c2d15efe7 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/OperationOrderingTests.java @@ -0,0 +1,78 @@ +/** + * + * 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; + +import org.apache.tuscany.das.rdb.Command; +import org.apache.tuscany.das.rdb.DAS; +import org.apache.tuscany.das.rdb.test.data.CityData; +import org.apache.tuscany.das.rdb.test.data.StateData; +import org.apache.tuscany.das.rdb.test.framework.DasTest; + +import commonj.sdo.DataObject; + +public class OperationOrderingTests extends DasTest { + + protected void setUp() throws Exception { + super.setUp(); + + CityData city = new CityData(getAutoConnection()); + StateData state = new StateData(getAutoConnection()); + + city.doDeletes(); + state.doDeletes(); + state.doInserts(); + city.doInserts(); + + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public OperationOrderingTests() { + super(); + } + + public void testInsert() throws Exception { + DAS das = DAS.FACTORY.createDAS(getConfig("cityStates.xml"), getConnection()); + Command select = das + .createCommand( + "Select * from STATES inner join CITIES on STATES.ID = CITIES.STATE_ID"); + DataObject root = select.executeQuery(); + + int numberOfStates = root.getList("STATES").size(); + int numberOfCities = root.getList("CITIES").size(); + + DataObject atlanta = root.createDataObject("CITIES"); + atlanta.setString("NAME", "Atlanta"); + atlanta.setInt("ID", 6); + + // Create a new Company + DataObject georgia = root.createDataObject("STATES"); + georgia.setInt("ID", 4); + georgia.setString("NAME", "GA"); + + georgia.getList("cities").add(atlanta); + + das.applyChanges(root); + + root = select.executeQuery(); + assertEquals(numberOfCities + 1, root.getList("CITIES").size()); + assertEquals(numberOfStates + 1, root.getList("STATES").size()); + } + +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/Paging.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/Paging.java new file mode 100644 index 0000000000..3358344f71 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/Paging.java @@ -0,0 +1,105 @@ +/** + * + * 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; + + +import java.sql.SQLException; + +import org.apache.tuscany.das.rdb.Command; +import org.apache.tuscany.das.rdb.DAS; +import org.apache.tuscany.das.rdb.Pager; +import org.apache.tuscany.das.rdb.impl.PagerImpl; +import org.apache.tuscany.das.rdb.test.data.CustomerData; +import org.apache.tuscany.das.rdb.test.framework.DasTest; + +import commonj.sdo.DataObject; + + + +public class Paging extends DasTest { + + protected void setUp() throws Exception { + super.setUp(); + new CustomerData(getAutoConnection()).refresh(); + } + + public void testPaging() throws SQLException { + DAS das = DAS.FACTORY.createDAS(getConnection()); + //Build command to read all customers + Command custCommand = das.createCommand("select * from CUSTOMER order by ID"); + + //Create a pager with the command + Pager pager = new PagerImpl(custCommand, 2); + + //Get and work with first page + DataObject root = pager.next(); + DataObject customer1 = root.getDataObject("CUSTOMER[1]"); + DataObject customer2 = root.getDataObject("CUSTOMER[2]"); + assertEquals(1, customer1.getInt("ID")); + assertEquals(2, customer2.getInt("ID")); + + //Get and work with the second page + root = pager.next(); + customer1 = root.getDataObject("CUSTOMER[1]"); + customer2 = root.getDataObject("CUSTOMER[2]"); + assertEquals(3, customer1.getInt("ID")); + assertEquals(4, customer2.getInt("ID")); + + // First page again + root = pager.previous(); + customer1 = root.getDataObject("CUSTOMER[1]"); + customer2 = root.getDataObject("CUSTOMER[2]"); + assertEquals(1, customer1.getInt("ID")); + assertEquals(2, customer2.getInt("ID")); + + } + + + public void testRandomPage() throws SQLException { + DAS das = DAS.FACTORY.createDAS(getConnection()); + //Build the select command + Command select = das + .createCommand("select * from CUSTOMER order by ID"); + + //Create a pager + Pager pager = new PagerImpl(select, 2); + + //Get the first page + DataObject root = pager.getPage(1); + DataObject customer1 = root.getDataObject("CUSTOMER[1]"); + DataObject customer2 = root.getDataObject("CUSTOMER[2]"); + assertEquals(1, customer1.getInt("ID")); + assertEquals(2, customer2.getInt("ID")); + + //Get the second page + root = pager.getPage(2); + customer1 = root.getDataObject("CUSTOMER[1]"); + customer2 = root.getDataObject("CUSTOMER[2]"); + assertEquals(3, customer1.getInt("ID")); + assertEquals(4, customer2.getInt("ID")); + + + // Get the first page again + root = pager.getPage(1); + customer1 = root.getDataObject("CUSTOMER[1]"); + customer2 = root.getDataObject("CUSTOMER[2]"); + assertEquals(1, customer1.getInt("ID")); + assertEquals(2, customer2.getInt("ID")); + } + + +}
\ No newline at end of file diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/PartialUpdateTests.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/PartialUpdateTests.java new file mode 100644 index 0000000000..84e2813c22 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/PartialUpdateTests.java @@ -0,0 +1,97 @@ +/** + * + * 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; + +import java.sql.SQLException; + +import org.apache.tuscany.das.rdb.Command; +import org.apache.tuscany.das.rdb.DAS; +import org.apache.tuscany.das.rdb.test.data.CustomerData; +import org.apache.tuscany.das.rdb.test.framework.DasTest; + +import commonj.sdo.DataObject; + +public class PartialUpdateTests extends DasTest { + + protected void setUp() throws Exception { + super.setUp(); + new CustomerData(getAutoConnection()).refresh(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public PartialUpdateTests() { + super(); + } + + public void testPartialUpdate() throws SQLException { + DAS das = DAS.FACTORY.createDAS(getConnection()); + Command readCustomers = das.createCommand("select * from CUSTOMER where ID = 1"); + + // Read + DataObject root = readCustomers.executeQuery(); + + DataObject customer = root.getDataObject("CUSTOMER[1]"); + // Verify + assertEquals(1, customer.getInt("ID")); + + Command update = das.createCommand("update CUSTOMER set LASTNAME = 'modified' where ID = 1"); + update.execute(); + + customer.setString("ADDRESS", "main street"); + + das.applyChanges(root); + + root = readCustomers.executeQuery(); + + // If partial update was not used, LASTNAME would not be 'modified' + customer = root.getDataObject("CUSTOMER[1]"); + assertEquals(1, customer.getInt("ID")); + assertEquals("modified", customer.getString("LASTNAME")); + assertEquals("main street", customer.getString("ADDRESS")); + } + + public void testPartialInsert() throws SQLException { + DAS das = DAS.FACTORY.createDAS(getConnection()); + Command readCustomers = das.createCommand("select * from CUSTOMER where ID = 1"); + + // Read + DataObject root = readCustomers.executeQuery(); + + // Create a new customer + DataObject newCust = root.createDataObject("CUSTOMER"); + newCust.set("ID", new Integer(100)); + newCust.set("ADDRESS", "5528 Wells Fargo Drive"); + // Purposely do not set lastname to let it default to 'Garfugengheist' + // newCust.set("LASTNAME", "Gerkin" ); + + das.applyChanges(root); + + Command readNewCust = das.createCommand("select * from CUSTOMER where ID = 100"); + root = readNewCust.executeQuery(); + + // If partial insert was not used, LASTNAME would not be + // 'Garfugengheist' + newCust = root.getDataObject("CUSTOMER[1]"); + assertEquals(100, newCust.getInt("ID")); + assertEquals("Garfugengheist", newCust.getString("LASTNAME")); + assertEquals("5528 Wells Fargo Drive", newCust.getString("ADDRESS")); + + } +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/PassiveConnectionTests.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/PassiveConnectionTests.java new file mode 100644 index 0000000000..a9fdaa1467 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/PassiveConnectionTests.java @@ -0,0 +1,92 @@ +/** + * + * 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; + +/* + * Test capability to participate in an extenrlly managed transaction. The + * client is managing the transaction boundary so the DAS will not issue + * commit/rollback + * + */ + +import org.apache.tuscany.das.rdb.Command; +import org.apache.tuscany.das.rdb.DAS; +import org.apache.tuscany.das.rdb.test.data.CustomerData; +import org.apache.tuscany.das.rdb.test.framework.DasTest; + +import commonj.sdo.DataObject; + +public class PassiveConnectionTests extends DasTest { + + protected void setUp() throws Exception { + super.setUp(); + new CustomerData(getAutoConnection()).refresh(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + /** + * Read and modify a customer. Uses a "passive" connection + */ + public void testReadModifyApply() throws Exception { + + // Create and initialize a DAS connection and initialize for externally + // managed transaction boundaries + java.sql.Connection c = getConnection(); + + DAS das = DAS.FACTORY.createDAS(getConfig("passiveConnection.xml"), c); + // Read customer 1 + Command select = das.getCommand("get a customer"); + DataObject root = select.executeQuery(); + + DataObject customer = (DataObject) root.get("CUSTOMER[1]"); + + String lastName = customer.getString("LASTNAME"); + + // Modify customer + customer.set("LASTNAME", "Pavick"); + + try { + das.applyChanges(root); + + throw new Exception("Test Exception"); + + // Since the DAS is not managing tx boundaries, I must + } catch (Exception e) { + // assert here to make sure we didn't run into some hidden error + assertEquals("Test Exception", e.getMessage()); + // Roll back the transaction + c.rollback(); + } + + // Verify that the changes did not go through + root = select.executeQuery(); + assertEquals(lastName, root.getString("CUSTOMER[1]/LASTNAME")); + + // Try again + customer = (DataObject) root.get("CUSTOMER[1]"); + customer.set("LASTNAME", "Pavick"); + das.applyChanges(root); + c.commit(); + + root = select.executeQuery(); + assertEquals("Pavick", root.getString("CUSTOMER[1]/LASTNAME")); + } + +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/ProgrammaticConfigTests.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/ProgrammaticConfigTests.java new file mode 100644 index 0000000000..b61f871614 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/ProgrammaticConfigTests.java @@ -0,0 +1,146 @@ +/** + * + * 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; + +import org.apache.tuscany.das.rdb.Command; +import org.apache.tuscany.das.rdb.ConfigHelper; +import org.apache.tuscany.das.rdb.DAS; +import org.apache.tuscany.das.rdb.test.data.BookData; +import org.apache.tuscany.das.rdb.test.data.CustomerData; +import org.apache.tuscany.das.rdb.test.data.OrderData; +import org.apache.tuscany.das.rdb.test.framework.DasTest; + +import commonj.sdo.DataObject; + +/** + * Tests the Converter framwork + */ +public class ProgrammaticConfigTests extends DasTest { + + protected void setUp() throws Exception { + super.setUp(); + new BookData(getAutoConnection()).refresh(); + new CustomerData(getAutoConnection()).refresh(); + new OrderData(getAutoConnection()).refresh(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + /** + * Simple read followed by a write. This should fail since there is no + * config associaed with the applychanges command + */ + public void test_1() throws Exception { + DAS das = DAS.FACTORY.createDAS(getConnection()); + // Read a book instance + Command select = das.createCommand("SELECT * FROM BOOK WHERE BOOK_ID = 1"); + DataObject root = select.executeQuery(); + DataObject book = root.getDataObject("BOOK[1]"); + // Change a field to mark the instance 'dirty' + book.setInt("QUANTITY", 2); + + try { + das.applyChanges(root); + fail("An exception should be thrown since here is no config to identify the primary key"); + } catch (RuntimeException ex) { + // Expected + } + } + + /** + * Simple read followed by a write. Config instance is generated + * programmatically using the ConfigHelper. + */ + public void test_2() throws Exception { + // Create config programmatically + ConfigHelper helper = new ConfigHelper(); + helper.addPrimaryKey("BOOK.BOOK_ID"); + DAS das = DAS.FACTORY.createDAS(helper.getConfig(), getConnection()); + + // Read a book instance + Command select = das.createCommand("SELECT * FROM BOOK WHERE BOOK_ID = 1"); + DataObject root = select.executeQuery(); + DataObject book = root.getDataObject("BOOK[1]"); + // Change a field to mark the instance 'dirty' + book.setInt("QUANTITY", 2); + + // Flush the change + + das.applyChanges(root); + + // Verify + root = select.executeQuery(); + book = root.getDataObject("BOOK[1]"); + assertEquals(2, book.getInt("QUANTITY")); + } + + + /** + * Test ability to read a compound graph + */ + public void test_3() throws Exception { + + String statement = "SELECT * FROM CUSTOMER LEFT JOIN ANORDER ON CUSTOMER.ID = ANORDER.CUSTOMER_ID WHERE CUSTOMER.ID = 1"; + + // Read some customers and related orders + // Create relationship config programmatically + ConfigHelper helper = new ConfigHelper(); + helper.addRelationship("CUSTOMER.ID", "ANORDER.CUSTOMER_ID"); + DAS das = DAS.FACTORY.createDAS(helper.getConfig(), getConnection()); + Command select = das.createCommand(statement); + + DataObject root = select.executeQuery(); + DataObject customer = root.getDataObject("CUSTOMER[1]"); + + assertEquals(2, customer.getList("ANORDER").size()); + + } + + /** + * Programatically create table config with "property" name + */ + public void test_4() throws Exception { + + String statement = "SELECT * FROM BOOK WHERE BOOK.BOOK_ID = ?"; + + // Create Table config programmatically + ConfigHelper helper = new ConfigHelper(); + helper.addTable("BOOK", "Book"); + helper.addPrimaryKey("Book.BOOK_ID"); + + DAS das = DAS.FACTORY.createDAS(helper.getConfig(), getConnection()); + Command select = das.createCommand(statement); + select.setParameter(1, new Integer(1)); + + DataObject root = select.executeQuery(); + + DataObject newBook = root.createDataObject("Book"); + newBook.setString("NAME", "Ant Colonies of the Old World"); + newBook.setInt("BOOK_ID", 1001); + root.getList("Book").add(newBook); + + das.applyChanges(root); + + //Verify + select.setParameter(1, new Integer(1001)); + root = select.executeQuery(); + assertEquals("Ant Colonies of the Old World", root.getString("Book[1]/NAME")); + + } +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/ReadDBSchemaTests.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/ReadDBSchemaTests.java new file mode 100644 index 0000000000..5a0be1d6da --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/ReadDBSchemaTests.java @@ -0,0 +1,62 @@ +/** + * + * 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; + +/* + * Test the ability to query Database schema(metadata) information using regular DAS APIs + * This is speciic to DB2 + * + */ + +import org.apache.tuscany.das.rdb.Command; +import org.apache.tuscany.das.rdb.DAS; +import org.apache.tuscany.das.rdb.test.framework.DasTest; + +import commonj.sdo.DataObject; + + +public class ReadDBSchemaTests extends DasTest { + + + protected void setUp() throws Exception { + super.setUp(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + + + public void testReadTableInfo() throws Exception { + DAS das = DAS.FACTORY.createDAS(getConnection()); + Command select = das.createCommand("SELECT * from SYSIBM.SYSTABLES WHERE TYPE = 'T'"); + DataObject root = select.executeQuery(); + + DataObject table = (DataObject)root.get("SYSTABLES[1]"); + + assertEquals('T', table.getChar("TYPE")); + + } + + + + //Utilities + + + +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/RecursiveTests.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/RecursiveTests.java new file mode 100644 index 0000000000..e851a4d925 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/RecursiveTests.java @@ -0,0 +1,69 @@ +/** + * + * 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; + +import java.util.Iterator; + +import org.apache.tuscany.das.rdb.Command; +import org.apache.tuscany.das.rdb.DAS; +import org.apache.tuscany.das.rdb.test.data.PartData; +import org.apache.tuscany.das.rdb.test.framework.DasTest; + +import commonj.sdo.DataObject; + +public class RecursiveTests extends DasTest { + + protected void setUp() throws Exception { + super.setUp(); + new PartData(getAutoConnection()).refresh(); + } + + public void testReadEngineParts() throws Exception { + + DAS das = DAS.FACTORY.createDAS(getConfig("PartsConfig.xml"), getConnection()); + //Table definition + //CREATE TABLE PART (ID INT PRIMARY KEY NOT NULL, NAME VARCHAR(50), QUANTITY INT, PARENT_ID INT ); + + + Command select = das.getCommand("readEngineParts"); + + // Need to set the key explicitly. The aggregate of columns not working + // because of null values + DataObject root = select.executeQuery(); + + assertEquals(5, root.getList("PART").size()); + // printList(root.getList("PART")); + DataObject engine = root.getDataObject("PART.0"); + assertEquals("Engine", engine.getString("NAME")); + + assertEquals(3, engine.getList("subparts").size()); + + DataObject piston = null; + Iterator i = engine.getList("subparts").iterator(); + while ( i.hasNext() ) { + DataObject obj = (DataObject)i.next(); + if ( obj.getString("NAME").equals("Piston")) + piston = obj; + } + + assertEquals("Piston", piston.getString("NAME")); + assertEquals(1, piston.getList("subparts").size()); + assertEquals("Piston Ring", piston.getDataObject("subparts.0").getString("NAME")); + + } + +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/RelationshipTests.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/RelationshipTests.java new file mode 100644 index 0000000000..679bdabd38 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/RelationshipTests.java @@ -0,0 +1,109 @@ +/** + * + * 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; + +/* + * + * + */ + +import org.apache.tuscany.das.rdb.Command; +import org.apache.tuscany.das.rdb.DAS; +import org.apache.tuscany.das.rdb.test.data.CustomerData; +import org.apache.tuscany.das.rdb.test.data.OrderData; +import org.apache.tuscany.das.rdb.test.framework.DasTest; + +import commonj.sdo.DataObject; + +public class RelationshipTests extends DasTest { + + protected void setUp() throws Exception { + super.setUp(); + + new CustomerData(getAutoConnection()).refresh(); + new OrderData(getAutoConnection()).refresh(); + + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + /** + * Test ability to read a compound graph + */ + public void testRead() throws Exception { + + String statement = "SELECT * FROM CUSTOMER LEFT JOIN ANORDER ON CUSTOMER.ID = ANORDER.CUSTOMER_ID WHERE CUSTOMER.ID = 1"; + + DAS das = DAS.FACTORY.createDAS(getConfig("customerOrderRelationshipMapping.xml"), getConnection()); + // Read some customers and related orders + Command select = das.createCommand(statement); + + DataObject root = select.executeQuery(); + DataObject customer = root.getDataObject("CUSTOMER[1]"); + + assertEquals(2, customer.getList("orders").size()); + + } + + /** + * Same as above except uses xml file for relationhip and key information. + * Employs CUD generation. + */ + public void testRelationshipModification2() throws Exception { + + DAS das = DAS.FACTORY.createDAS(getConfig("basicCustomerOrderMapping.xml"), getConnection()); + // Read some customers and related orders + Command select = das + .createCommand("SELECT * FROM CUSTOMER LEFT JOIN ANORDER ON CUSTOMER.ID = ANORDER.CUSTOMER_ID"); + + DataObject root = select.executeQuery(); + + DataObject cust1 = root.getDataObject("CUSTOMER[1]"); + DataObject cust2 = root.getDataObject("CUSTOMER[2]"); + + // Save IDs + Integer cust1ID = (Integer) cust1.get("ID"); + Integer cust2ID = (Integer) cust2.get("ID"); + // save order count + Integer cust1OrderCount = new Integer(cust1.getList("orders").size()); + Integer cust2OrderCount = new Integer(cust2.getList("orders").size()); + + // Move an order to cust1 from cust2 + DataObject order = (DataObject) cust2.getList("orders").get(0); + cust1.getList("orders").add(order); + + // Flush changes + das.applyChanges(root); + + // verify cust1 relationship updates + select = das + .createCommand("SELECT * FROM CUSTOMER LEFT JOIN ANORDER ON CUSTOMER.ID = ANORDER.CUSTOMER_ID where CUSTOMER.ID = ?"); + select.setParameter(1, cust1ID); + + root = select.executeQuery(); + assertEquals(cust1OrderCount.intValue() + 1, root.getList("CUSTOMER[1]/orders").size()); + + // verify cust2 relationship updates + select.setParameter(1, cust2ID); + root = select.executeQuery(); + assertEquals(cust2OrderCount.intValue() - 1, root.getList("CUSTOMER[1]/orders").size()); + + } + +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/ResultSetShapeTests.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/ResultSetShapeTests.java new file mode 100644 index 0000000000..bf10e0f379 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/ResultSetShapeTests.java @@ -0,0 +1,91 @@ +/** + * + * 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; + +import org.apache.tuscany.das.rdb.Command; +import org.apache.tuscany.das.rdb.DAS; +import org.apache.tuscany.das.rdb.test.data.CustomerData; +import org.apache.tuscany.das.rdb.test.framework.DasTest; + +import commonj.sdo.DataObject; + +/** + * Test ability to specify format(shape) of the ResultSet. This is necessary + * when the JDBC driver in use does not provide adequate support for + * ResultSetMetadata. Also, we expect that specifying the result set shape will + * increase performance. + * + */ +public class ResultSetShapeTests extends DasTest { + + protected void setUp() throws Exception { + super.setUp(); + new CustomerData(getAutoConnection()).refresh(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + /** + * Read a specific customer + */ + public void testReadSingle() throws Exception { + + DAS das = DAS.FACTORY.createDAS(getConfig("CustomerConfigWithIDConverter.xml"),getConnection()); + // Create and initialize command to read customers + Command readCustomers = das.getCommand("literal"); + + // Read + DataObject root = readCustomers.executeQuery(); + + // Verify + assertEquals(5, root.getList("CUSTOMER").size()); + assertEquals(99, root.getInt("CUSTOMER[1]/ID")); + assertEquals("Roosevelt", root.getString("CUSTOMER[1]/LASTNAME")); + assertEquals("1600 Pennsylvania Avenue", root.getString("CUSTOMER[1]/ADDRESS")); + + } + + /** + * Read a specific customer This duplicates the previous tests but does not + * provide the shape info. Since the select will not return valid metadata, + * this test is expected to fail + */ + public void testReadSingleVerifyShapeUse() throws Exception { + + // Using literals in the select forces invalid resultset metadata + String sqlString = "Select 99, 'Roosevelt', '1600 Pennsylvania Avenue' from customer"; + + DAS das = DAS.FACTORY.createDAS(getConnection()); + // Create and initialize command to read customers + Command readCustomers = das.createCommand(sqlString); + + // Read + DataObject root = readCustomers.executeQuery(); + + // Verify + try { + assertEquals(5, root.getList("CUSTOMER").size()); + fail("Should fail since there will be no feature named CUSTOMER"); + } catch (IllegalArgumentException e) { + // OK + } + + } + +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/SerializationTests.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/SerializationTests.java new file mode 100644 index 0000000000..0089e6b569 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/SerializationTests.java @@ -0,0 +1,90 @@ +/** + * + * 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; + +/* + * This class provides tests for all supported "types". The current plan is to + * use the Data type definitions provided in the SDO 2 specification. We must + * test the ability to use all of these types as well as different mapping from + * thse types to types used in the database. For example, a SDO Data Type + * "STRING", might be staored as a "TIMESTAMP" in DB2. + * + */ + +import org.apache.tuscany.das.rdb.test.data.TypesData; +import org.apache.tuscany.das.rdb.test.framework.DasTest; + +public class SerializationTests extends DasTest { + + protected void setUp() throws Exception { + super.setUp(); + new TypesData(getAutoConnection()).refresh(); + } + + /** + * Read various types. + */ + + +public void testReadandSerialize() throws Exception { + /** Currently failing because of TUSCANY-22 + Command select = Command.FACTORY + .createCommand("Select * from TYPETEST where ID = 1"); + select.setConnection(getConnection()); + DataObject root = select.executeQuery(); + + DataObject obj = root.getDataObject("TYPETEST[1]"); + + assertTrue(obj.isSet("ID")); + assertTrue(obj.isSet("ATIMESTAMP")); + assertTrue(obj.isSet("ADECIMAL")); + assertTrue(obj.isSet("AFLOAT")); + + //Java serilaization to file + FileOutputStream fos = null; + ObjectOutputStream out = null; + try { + fos = new FileOutputStream("serializedGraph.xml"); + out = new ObjectOutputStream(fos); + out.writeObject(root); + out.flush(); + } finally { + out.close(); + fos.close(); + } + + //Reconstruct the graph + FileInputStream fis = null; + ObjectInputStream in = null; + DataObject root2; + try { + fis = new FileInputStream("serializedGraph.xml"); + in = new ObjectInputStream(fis); + root2 = (DataObject) in.readObject(); + } finally { + in.close(); + fis.close(); + } + + assertEquals(1, root.getInt("TYPETEST[1]/ID")); + assertEquals(TypesData.getTimestamp(), (java.sql.Timestamp)root.get("TYPETEST[1]/ATIMESTAMP")); + assertEquals(1234567.89f, root2.getFloat("TYPETEST[1]/ADECIMAL"), .001); + assertEquals(1234567.89f, root2.getFloat("TYPETEST[1]/AFLOAT"), .001); + + */ + } +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/SimplestCrud.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/SimplestCrud.java new file mode 100644 index 0000000000..0f6ce5c2c8 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/SimplestCrud.java @@ -0,0 +1,235 @@ +/** + * + * 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; + +/* + * These are the simplest possible uses of the JDBC DAS. In this mode, the + * programming model is not much more than JDBC + * + * The assumptions for these tests are: + * + * Single type + * Client explicitly Read/Create/Update/Delete commands + * No O/R mapping metadata + * SDO change history is not used + * Dynamic DataObjects + * No specified graph model + * + * + */ + +import org.apache.tuscany.das.rdb.Command; +import org.apache.tuscany.das.rdb.DAS; +import org.apache.tuscany.das.rdb.test.data.CustomerData; +import org.apache.tuscany.das.rdb.test.framework.DasTest; + +import commonj.sdo.DataObject; + + +public class SimplestCrud extends DasTest { + + protected void setUp() throws Exception { + super.setUp(); + new CustomerData(getAutoConnection()).refresh(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + /** + * Read a specific customer + */ + public void testReadSingle() throws Exception { + + //Create and initialize command to read customers + DAS das = DAS.FACTORY.createDAS(getConnection()); + Command readCustomers = das.createCommand("select * from CUSTOMER where ID = 1"); + + //Read + DataObject root = readCustomers.executeQuery(); + + //Verify + assertEquals(1, root.getInt("CUSTOMER[1]/ID")); + } + + /** + * Read a specific customer + */ + public void testReadSingle2() throws Exception { + + DAS das = DAS.FACTORY.createDAS(getConnection()); + //Create and initialize command to read customers + Command readCustomers = das.createCommand("select * from CUSTOMER where ID = 1"); + + //Read + DataObject root = readCustomers.executeQuery(); + + //Verify + assertEquals(1, root.getInt("CUSTOMER[1]/ID")); + } + + /** + * Read a specific customer + * Same as above but tests tolerance of white space in provided SQL + */ + public void testReadSingleWithWhiteSpace() throws Exception { + DAS das = DAS.FACTORY.createDAS(getConnection()); + //Create and initialize command to read customers + Command readCustomers = das.createCommand(" select * from CUSTOMER where ID = 1"); + + //Read + DataObject root = readCustomers.executeQuery(); + + //Verify + assertEquals(1, root.getInt("CUSTOMER[1]/ID")); + } + + /** + * Read all customers with a specific last name + */ + public void testReadMultiple() throws Exception { + + DAS das = DAS.FACTORY.createDAS(getConnection()); + //Create and initialize command to read customers + Command readCustomers = das.createCommand("select * from CUSTOMER where LASTNAME = 'Williams'"); + + //Read + DataObject root = readCustomers.executeQuery(); + + //Verify + assertEquals(4, root.getList("CUSTOMER").size()); + } + + /** + * Read all customers with a specific last name + * LASTNAME value is provided via a parameter + */ + public void testReadMultipleWithParameters() throws Exception { + DAS das = DAS.FACTORY.createDAS(getConnection()); + //Create and initialize command to read customers + Command readCustomers = das.createCommand("select * from CUSTOMER where LASTNAME = ?"); + + //Parameterize the command + readCustomers.setParameter(1, "Williams"); + DataObject root = readCustomers.executeQuery(); + + //Verify + assertEquals(4, root.getList("CUSTOMER").size()); + } + + public void testInsert() throws Exception { + DAS das = DAS.FACTORY.createDAS(getConnection()); + Command insert = das.createCommand("insert into CUSTOMER values (10, 'Williams', '5528 Wells Fargo Dr')"); + insert.execute(); + + //Verify + Command select = das.createCommand("Select * from CUSTOMER where ID = 10"); + DataObject root = select.executeQuery(); + assertEquals(1, root.getList("CUSTOMER").size()); + assertEquals("5528 Wells Fargo Dr", root.get("CUSTOMER[1]/ADDRESS")); + + } + + public void testInsertWithParameters() throws Exception { + DAS das = DAS.FACTORY.createDAS(getConnection()); + Command insert = das.createCommand("insert into CUSTOMER values (?, ?, ?)"); + insert.setParameter(1, new Integer(10)); + insert.setParameter(2, "Williams"); + insert.setParameter(3, "5528 Wells Fargo Dr"); + insert.execute(); + + //Verify + Command select = das.createCommand("Select * from CUSTOMER where ID = 10"); + DataObject root = select.executeQuery(); + assertEquals(1, root.getList("CUSTOMER").size()); + assertEquals("5528 Wells Fargo Dr", root.get("CUSTOMER[1]/ADDRESS")); + + } + + + public void testDelete() throws Exception { + DAS das = DAS.FACTORY.createDAS(getConnection()); + //Verify pre-condition + Command select = das.createCommand("Select * from CUSTOMER where ID = 1"); + DataObject root = select.executeQuery(); + assertEquals(1, root.getList("CUSTOMER").size()); + + //Create and execute the delete command + Command delete = das.createCommand("delete from CUSTOMER where ID = 1"); + delete.execute(); + + //Verify delete by reusing the original select command + root = select.executeQuery(); + assertEquals(0, root.getList("CUSTOMER").size()); + + } + + + public void testUpdate() throws Exception { + DAS das = DAS.FACTORY.createDAS(getConnection()); + //Verify pre-condition + Command select = das.createCommand("Select * from CUSTOMER where ID = 1"); + DataObject root = select.executeQuery(); + assertFalse(root.get("CUSTOMER[1]/LASTNAME").equals("Pavick")); + + Command update = das.createCommand("update CUSTOMER set LASTNAME = 'Pavick' where ID = 1"); + update.execute(); + + //Verify update - reuse select command + root = select.executeQuery(); + assertEquals("Pavick", root.get("CUSTOMER[1]/LASTNAME")); + + } + + public void testUpdateWithParameters() throws Exception { + DAS das = DAS.FACTORY.createDAS(getConnection()); + //Verify pre-condition + Command select = das.createCommand("Select * from CUSTOMER where ID = 1"); + DataObject root = select.executeQuery(); + assertFalse(root.get("CUSTOMER[1]/LASTNAME").equals("Pavick")); + + Command update = das.createCommand("update CUSTOMER set LASTNAME = ? where ID = ?"); + update.setParameter(1, "Pavick"); + update.setParameter(2, new Integer(1)); + update.execute(); + + //Verify update - reuse select command + root = select.executeQuery(); + assertEquals("Pavick", root.get("CUSTOMER[1]/LASTNAME")); + + } + + public void testUpdateWithParmarkers() throws Exception { + DAS das = DAS.FACTORY.createDAS(getConnection()); + //Verify pre-condition + Command select = das.createCommand("Select * from CUSTOMER where ID = 1"); + DataObject root = select.executeQuery(); + assertFalse(root.get("CUSTOMER[1]/LASTNAME").equals("Pavick")); + + Command update = das.createCommand("update CUSTOMER set LASTNAME = ? where ID = ?"); + update.setParameter(1, "Pavick"); + update.setParameter(2, new Integer(1)); + update.execute(); + + //Verify update - reuse select command + root = select.executeQuery(); + assertEquals("Pavick", root.get("CUSTOMER[1]/LASTNAME")); + + } + +}
\ No newline at end of file diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/StoredProcs.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/StoredProcs.java new file mode 100644 index 0000000000..4f8dbbe60c --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/StoredProcs.java @@ -0,0 +1,186 @@ +/** + * + * 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; + + +import org.apache.tuscany.das.rdb.Command; +import org.apache.tuscany.das.rdb.DAS; +import org.apache.tuscany.das.rdb.test.data.CompanyData; +import org.apache.tuscany.das.rdb.test.data.CustomerData; +import org.apache.tuscany.das.rdb.test.data.OrderData; +import org.apache.tuscany.das.rdb.test.framework.DasTest; + +import commonj.sdo.DataObject; + + +public class StoredProcs extends DasTest { + + protected void setUp() throws Exception { + super.setUp(); + + new CompanyData(getAutoConnection()).refresh(); + new CustomerData(getAutoConnection()).refresh(); + new OrderData(getAutoConnection()).refresh(); + + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + // Call a simple stored proc to read all companies + public void testGetCompanies() throws Exception { + DAS das = DAS.FACTORY.createDAS(getConnection()); + Command read = das.createCommand("{call GETALLCOMPANIES()}"); + DataObject root = read.executeQuery(); + + //Verify + assertEquals(3, root.getList("COMPANY").size()); + assertTrue(root.getInt("COMPANY[1]/ID") > 0); + + } + + public void testGetNamedCompany() throws Exception { + DAS das = DAS.FACTORY.createDAS(getConnection()); + Command read = das.createCommand("{call GETNAMEDCOMPANY(?)}"); + + read.setParameter(1, "MegaCorp"); + DataObject root = read.executeQuery(); + + assertEquals("MegaCorp", root.getString("COMPANY[1]/NAME")); + + } + + public void testGetNamedCompanyByName() throws Exception { + DAS das = DAS.FACTORY.createDAS(getConnection()); + Command read = das + .createCommand("{call GETNAMEDCOMPANY(?)}"); + + read.setParameter(1, "MegaCorp"); + DataObject root = read.executeQuery(); + + assertEquals("MegaCorp", root.getString("COMPANY[1]/NAME")); + } + + + // Retreive heirarchy using a stored proc ... new programming model + public void testGetCustomersAndOrder() throws Exception { + DAS das = DAS.FACTORY.createDAS(getConfig("CustomersOrdersConfig.xml"), getConnection()); + Command read = das.createCommand("{call getCustomerAndOrders(?)}"); + read.setParameter(1, new Integer(1)); + + DataObject root = read.executeQuery(); + + DataObject customer = (DataObject) root.getList("CUSTOMER").get(0); + assertEquals(2, customer.getList("orders").size()); + + } + + /** + * Call a stored proc requiring an in parameter and producing an out + * parameter and a resultset + * + * This stored proc takes a lastname argument and returns a graph of + * customers with that last name. The number of read customers is returned + * in the out parameter + */ + public void testGetNamedCustomers() throws Exception { + DAS das = DAS.FACTORY.createDAS(getConfig("storedProcTest.xml"), getConnection()); + Command read = das.getCommand("getNamedCustomers"); + read.setParameter(1, "Williams"); + DataObject root = read.executeQuery(); + + Integer customersRead = (Integer) read.getParameter(2); + + assertEquals(4, customersRead.intValue()); + assertEquals(customersRead.intValue(), root.getList("CUSTOMER").size()); + + } + + //TODO - Resolve issue with programmatic creation of GETNAMEDCUSTOMERS on DB2 and + //re-enable this test + + + // Simplest possible SP write + public void testDelete() throws Exception { + DAS das = DAS.FACTORY.createDAS(getConnection()); + Command delete = das.createCommand("{call DELETECUSTOMER(?)}"); + delete.setParameter(1, new Integer(1)); + delete.execute(); + + // Verify DELETE + Command select = das.createCommand("Select * from CUSTOMER where ID = 1"); + DataObject root = select.executeQuery(); + assertTrue(root.getList("CUSTOMER").isEmpty()); + + } + +/* // For debug + public void testRawCall() throws Exception { + + Connection c = getConnection(); + CallableStatement cs = c.prepareCall("{call GETNAMEDCUSTOMERS(?,?)}"); + ParameterMetaData pm = cs.getParameterMetaData(); + int count = pm.getParameterCount(); + for (int i = 1; i <= count; i++) { + int mode = pm.getParameterMode(i); + if (mode == ParameterMetaData.parameterModeOut + || mode == ParameterMetaData.parameterModeInOut) + cs.registerOutParameter(i, pm.getParameterType(i)); + } + cs.setString(1, "Williams"); + // cs.registerOutParameter(2,java.sql.Types.INTEGER); + boolean isResultSet = cs.execute(); + System.out.println("Has a result set => " + isResultSet); + ResultSet rs = cs.getResultSet(); + + if (isResultSet) { + System.out.println("Results are: "); + while (rs.next()) { + System.out.println(rs.getObject(2)); + } + } + System.out.println("Count is =>" + cs.getObject(2)); + c.commit(); + } + + // For debug + public void testRawCall2() throws Exception { + + Connection c = getConnection(); + CallableStatement cs = c.prepareCall("{call getCustomerAndOrders(?)}"); + cs.setObject(1, new Integer(1)); + boolean isResultSet = cs.execute(); + System.out.println("call getCustomerAndOrders(?) has a result set => " + + isResultSet); + ResultSet rs = cs.getResultSet(); + + write(rs); + c.commit(); + } + + public void testGetAllOrders() throws Exception { + + System.out.println("all orders"); + Connection c = getConnection(); + PreparedStatement s = c.prepareStatement("select * from anorder"); + write (s.executeQuery()); + c.commit(); + + }*/ + +}
\ No newline at end of file diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/TopDown.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/TopDown.java new file mode 100644 index 0000000000..49f093c36d --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/TopDown.java @@ -0,0 +1,73 @@ +/** + * + * 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; + +import java.io.IOException; +import java.sql.SQLException; + +import org.apache.tuscany.das.rdb.Command; +import org.apache.tuscany.das.rdb.DAS; +import org.apache.tuscany.das.rdb.test.customer.AnOrder; +import org.apache.tuscany.das.rdb.test.customer.Customer; +import org.apache.tuscany.das.rdb.test.customer.CustomerFactory; +import org.apache.tuscany.das.rdb.test.data.CustomerData; +import org.apache.tuscany.das.rdb.test.data.OrderData; +import org.apache.tuscany.das.rdb.test.framework.DasTest; +import org.apache.tuscany.sdo.util.SDOUtil; + +import commonj.sdo.DataObject; + +public class TopDown extends DasTest { + + protected void setUp() throws Exception { + super.setUp(); + + new CustomerData(getAutoConnection()).refresh(); + new OrderData(getAutoConnection()).refresh(); + + } + + // Uses dynamic SDOs but user provides the model + public void testUserProvidedModelDynamic() throws SQLException, IOException { + + DAS das = DAS.FACTORY.createDAS(getConfig("staticCustomerOrder.xml"), getConnection()); + + Command select = das.getCommand("Customer and Orders"); + + SDOUtil.registerStaticTypes(CustomerFactory.class); + + // Parameterize the command + select.setParameter(1, new Integer(1)); + + // Get the graph - DataGraphRoot is from the typed package + DataObject root = select.executeQuery(); + + // Modify a customer + Customer customer = (Customer)root.getDataObject("Customer[1]"); + customer.setLastName("Pavick"); + + // Modify an order + AnOrder order = (AnOrder) customer.getOrders().get(0); + order.setProduct("Kitchen Sink 001"); + + // Flush changes + das.applyChanges((DataObject) root); + + } + + +}
\ No newline at end of file diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/TypeTests.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/TypeTests.java new file mode 100644 index 0000000000..33d8fed6fb --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/TypeTests.java @@ -0,0 +1,91 @@ +/** + * + * 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; + +/* + * This class provides tests for all supported "types". The current plan is to use the Data + * type definitions provided in the SDO 2 specification. We must test the ability to use + * all of these types as well as different mapping from thse types to types used in the + * database. For example, a SDO Data Type "STRING", might be staored as a "TIMESTAMP" in DB2. + * + */ + +import org.apache.tuscany.das.rdb.Command; +import org.apache.tuscany.das.rdb.DAS; +import org.apache.tuscany.das.rdb.test.data.TypesData; +import org.apache.tuscany.das.rdb.test.framework.DasTest; + +import commonj.sdo.DataObject; + + +public class TypeTests extends DasTest { + + + protected void setUp() throws Exception { + super.setUp(); + new TypesData(getAutoConnection()).refresh(); + } + + /** + * Read various types. + */ + public void testRead() throws Exception { + DAS das = DAS.FACTORY.createDAS(getConnection()); + //Read customer 1 + Command select = das.createCommand("Select * from TYPETEST where ID = 1"); + DataObject root = select.executeQuery(); + + DataObject types = (DataObject)root.get("TYPETEST[1]"); + + java.sql.Timestamp ts = (java.sql.Timestamp)types.get("ATIMESTAMP"); + assertEquals(ts, TypesData.getTimestamp()); + + float decimal = types.getFloat("ADECIMAL"); + assertEquals(1234567.89f, decimal, .0001); + + } + + + /** + * Write various types. + * TODO - Need to rethink the Timestamp write. My current thinking id that writes of non-SDO2 defined types + * require a converter + */ +/* public void testWrite() throws Exception { + + //Read customer 1 + Command select = Command.FACTORY.createCommand("Select * from TYPETEST where ID = 1"); + select.setConnection(getConnection()); + DataObject root = select.executeQuery(); + + DataObject types = (DataObject)root.get("TYPETEST[1]"); + Date now = new Date(); + types.set("ATIMESTAMP", now); + + ApplyChangesCommand apply = Command.FACTORY.createApplyChangesCommand(); + apply.setConnection(getConnection()); + apply.addPrimaryKey("TYPETEST.ID"); + apply.execute(root); + + //Verify + root = select.executeQuery(); + java.sql.Timestamp ts = (java.sql.Timestamp)types.get("ATIMESTAMP"); + assertEquals(now, ts); + + }*/ + +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/commands/ReadCustomersByLastnameCommand.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/commands/ReadCustomersByLastnameCommand.java new file mode 100644 index 0000000000..21a7427ace --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/commands/ReadCustomersByLastnameCommand.java @@ -0,0 +1,54 @@ +/** + * + * 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.commands; + +import org.apache.tuscany.das.rdb.config.Column; +import org.apache.tuscany.das.rdb.config.Config; +import org.apache.tuscany.das.rdb.config.ConfigFactory; +import org.apache.tuscany.das.rdb.config.Table; +import org.apache.tuscany.das.rdb.config.impl.ConfigFactoryImpl; +import org.apache.tuscany.das.rdb.impl.ReadCommandImpl; + + +public class ReadCustomersByLastnameCommand extends ReadCommandImpl { + + private static final String sqlString = "select * from CUSTOMER where LASTNAME = ?"; + private static final Config mapping; + + static { + ConfigFactory factory = ConfigFactoryImpl.eINSTANCE; + mapping = factory.createConfig(); + Table t = factory.createTable(); + Column id = factory.createColumn(); + id.setColumnName("ID"); + id.setPrimaryKey(true); + Column lastname = factory.createColumn(); + lastname.setColumnName("LASTNAME"); + Column address = factory.createColumn(); + address.setColumnName("ADDRESS"); + + t.getColumn().add(id); + t.getColumn().add(lastname); + t.getColumn().add(address); + t.setTableName("CUSTOMER"); + mapping.getTable().add(t); + } + + public ReadCustomersByLastnameCommand() { + super(sqlString, mapping, null); + } +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/commands/ReadCustomersCommand.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/commands/ReadCustomersCommand.java new file mode 100644 index 0000000000..2b58e29aa1 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/commands/ReadCustomersCommand.java @@ -0,0 +1,55 @@ +/** +* +* 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.commands; + +import org.apache.tuscany.das.rdb.config.Column; +import org.apache.tuscany.das.rdb.config.Config; +import org.apache.tuscany.das.rdb.config.ConfigFactory; +import org.apache.tuscany.das.rdb.config.Table; +import org.apache.tuscany.das.rdb.config.impl.ConfigFactoryImpl; +import org.apache.tuscany.das.rdb.impl.ReadCommandImpl; + + +public class ReadCustomersCommand extends ReadCommandImpl { + + private static final String sqlString = "select * from CUSTOMER"; + private static final Config mapping; + + static { + ConfigFactory factory = ConfigFactoryImpl.eINSTANCE; + mapping = factory.createConfig(); + Table t = factory.createTable(); + Column id = factory.createColumn(); + id.setColumnName("ID"); + id.setPrimaryKey(true); + Column lastname = factory.createColumn(); + lastname.setColumnName("LASTNAME"); + Column address = factory.createColumn(); + address.setColumnName("ADDRESS"); + + t.getColumn().add(id); + t.getColumn().add(lastname); + t.getColumn().add(address); + t.setTableName("CUSTOMER"); + mapping.getTable().add(t); + } + + public ReadCustomersCommand() { + super(sqlString, mapping, null); + } + +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/commands/ReadCustomersStaticTypesCommand.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/commands/ReadCustomersStaticTypesCommand.java new file mode 100644 index 0000000000..be678bbce6 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/commands/ReadCustomersStaticTypesCommand.java @@ -0,0 +1,60 @@ +/** +* +* 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.commands; + +import org.apache.tuscany.das.rdb.config.Column; +import org.apache.tuscany.das.rdb.config.Config; +import org.apache.tuscany.das.rdb.config.ConfigFactory; +import org.apache.tuscany.das.rdb.config.Table; +import org.apache.tuscany.das.rdb.config.impl.ConfigFactoryImpl; +import org.apache.tuscany.das.rdb.impl.ReadCommandImpl; + + +public class ReadCustomersStaticTypesCommand extends ReadCommandImpl { + + private static final String sqlString = "Select ID, LASTNAME, ADDRESS from CUSTOMER where LASTNAME = ?"; + private static final Config mapping; + + static { + ConfigFactory factory = ConfigFactoryImpl.eINSTANCE; + mapping = factory.createConfig(); + Table t = factory.createTable(); + Column id = factory.createColumn(); + id.setColumnName("ID"); + id.setPrimaryKey(true); + Column lastname = factory.createColumn(); + lastname.setColumnName("LASTNAME"); + Column address = factory.createColumn(); + address.setColumnName("ADDRESS"); + + t.getColumn().add(id); + t.getColumn().add(lastname); + t.getColumn().add(address); + t.setTableName("CUSTOMER"); + t.setTypeName("Customer"); + mapping.getTable().add(t); + + mapping.setDataObjectModel("http:///org.apache.tuscany.das.rdb.test/customer.xsd"); + } + + public ReadCustomersStaticTypesCommand() { + super(sqlString, mapping, null); + } + + + +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/commands/ReadCustomersWithShapeCommand.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/commands/ReadCustomersWithShapeCommand.java new file mode 100644 index 0000000000..6566544c39 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/commands/ReadCustomersWithShapeCommand.java @@ -0,0 +1,58 @@ +/** + * + * 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.commands; + +import java.util.ArrayList; + +import org.apache.tuscany.das.rdb.config.ConfigFactory; +import org.apache.tuscany.das.rdb.config.ResultDescriptor; +import org.apache.tuscany.das.rdb.config.impl.ConfigFactoryImpl; +import org.apache.tuscany.das.rdb.impl.ReadCommandImpl; + +public class ReadCustomersWithShapeCommand extends ReadCommandImpl { +// This sql string ensures that we won't have resultset metadata + static String sqlString = "select * from customer union select * from customer"; + static ArrayList descriptor = new ArrayList(); + + static { + ConfigFactory factory = ConfigFactoryImpl.eINSTANCE; + + ResultDescriptor desc1 = factory.createResultDescriptor(); + desc1.setColumnName("ID"); + desc1.setColumnType("commonj.sdo.Int"); + desc1.setTableName("CUSTOMER"); + + ResultDescriptor desc2 = factory.createResultDescriptor(); + desc2.setColumnName("LASTNAME"); + desc2.setColumnType("commonj.sdo.String"); + desc2.setTableName("CUSTOMER"); + + ResultDescriptor desc3 = factory.createResultDescriptor(); + desc3.setColumnName("ADDRESS"); + desc3.setColumnType("commonj.sdo.String"); + desc3.setTableName("CUSTOMER"); + + descriptor.add(desc1); + descriptor.add(desc2); + descriptor.add(desc3); + + } + public ReadCustomersWithShapeCommand() { + super(sqlString, null, descriptor); + } + +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/commands/SimpleReadCustomersWithShapeCommand.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/commands/SimpleReadCustomersWithShapeCommand.java new file mode 100644 index 0000000000..ac9dba6aa9 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/commands/SimpleReadCustomersWithShapeCommand.java @@ -0,0 +1,79 @@ +/** +* +* 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.commands; + +import java.util.ArrayList; + +import org.apache.tuscany.das.rdb.config.Column; +import org.apache.tuscany.das.rdb.config.Config; +import org.apache.tuscany.das.rdb.config.ConfigFactory; +import org.apache.tuscany.das.rdb.config.ResultDescriptor; +import org.apache.tuscany.das.rdb.config.Table; +import org.apache.tuscany.das.rdb.config.impl.ConfigFactoryImpl; +import org.apache.tuscany.das.rdb.impl.ReadCommandImpl; + +public class SimpleReadCustomersWithShapeCommand extends ReadCommandImpl { + + // This sql string ensures that we won't have resultset metadata + private static final String sqlString = "Select * from customer union select * from customer"; + private static final ArrayList descriptor = new ArrayList(); + + private static final Config config; + + static { + ConfigFactory factory = ConfigFactoryImpl.eINSTANCE; + config = factory.createConfig(); + Table t = factory.createTable(); + Column id = factory.createColumn(); + id.setColumnName("ID"); + id.setPrimaryKey(true); + Column lastname = factory.createColumn(); + lastname.setColumnName("LASTNAME"); + Column address = factory.createColumn(); + address.setColumnName("ADDRESS"); + + t.getColumn().add(id); + t.getColumn().add(lastname); + t.getColumn().add(address); + t.setTableName("CUSTOMER"); + config.getTable().add(t); + + ResultDescriptor desc1 = factory.createResultDescriptor(); + desc1.setColumnName("ID"); + desc1.setColumnType("commonj.sdo.Int"); + desc1.setTableName("CUSTOMER"); + + ResultDescriptor desc2 = factory.createResultDescriptor(); + desc2.setColumnName("LASTNAME"); + desc2.setColumnType("commonj.sdo.String"); + desc2.setTableName("CUSTOMER"); + + ResultDescriptor desc3 = factory.createResultDescriptor(); + desc3.setColumnName("ADDRESS"); + desc3.setColumnType("commonj.sdo.String"); + desc3.setTableName("CUSTOMER"); + + descriptor.add(desc1); + descriptor.add(desc2); + descriptor.add(desc3); + } + + public SimpleReadCustomersWithShapeCommand() { + super(sqlString, config, descriptor); + } + +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/BookData.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/BookData.java new file mode 100644 index 0000000000..e696c8dd6b --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/BookData.java @@ -0,0 +1,45 @@ +/** + * + * 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.data; + +import java.sql.Connection; +import java.sql.Types; + +import org.apache.tuscany.das.rdb.test.framework.TestDataWithExplicitColumns; + + +public class BookData extends TestDataWithExplicitColumns { + + //CREATE TABLE BOOK (ID INT PRIMARY KEY NOT NULL, NAME VARCHAR(50), AUTHOR VARCHAR(30), QUANTITY INT, OCC INTEGER) + + private static int[] bookTypes = {Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.INTEGER}; + + private static Object[][] bookData = { + { new Integer(1), "The Brothers Karamazov", "Fyodor Dostoevsky", new Integer(5), new Integer(17) }, + { new Integer(2), "Cat in the Hat", "Doctor Seuss", new Integer(10), new Integer(1) }}; + + private static String[] bookColumns = { "BOOK_ID", "NAME", "AUTHOR", "QUANTITY", "OCC"}; + + public BookData(Connection connection) { + super(connection, bookData, bookColumns, bookTypes); + } + + public String getTableName() { + return "BOOK"; + } + +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/CityData.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/CityData.java new file mode 100644 index 0000000000..0ebbd6c5af --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/CityData.java @@ -0,0 +1,54 @@ +/** + * + * 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.data; + +import java.sql.Connection; +import java.sql.SQLException; + +import org.apache.tuscany.das.rdb.test.framework.TestData; + + +public class CityData extends TestData { + + private static Object[][] cityData = { + {new Integer(1), "Lizard Lick", "1"}, + {new Integer(2), "Morrisville", "1"}, + {new Integer(3), "Breckenridge", "2"}, + {new Integer(4), "Barstow", "3"}, + {new Integer(5), "Sacramento", "3"} + + }; + + public CityData(Connection c) { + super(c, cityData); + } + + public String getTableName() { + return "CITIES"; + } + + public void doDeletes() throws SQLException { + deleteRowsFromTable(); + + } + + public void doInserts() throws SQLException { + insertRows(); + + } + +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/CompanyData.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/CompanyData.java new file mode 100644 index 0000000000..9c49004ba5 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/CompanyData.java @@ -0,0 +1,45 @@ +/** + * + * 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.data; + +import java.sql.Connection; +import java.sql.Types; + +import org.apache.tuscany.das.rdb.test.framework.TestDataWithExplicitColumns; + + +public class CompanyData extends TestDataWithExplicitColumns { + + //CREATE TABLE COMPANY (ID INT PRIMARY KEY NOT NULL GENERATED ALWAYS AS IDENTITY ,NAME VARCHAR(30)) + + private static int[] columnTypes = {Types.VARCHAR}; + + private static Object[][] companyData = { { "ACME Publishing" }, + { "Do-rite plumbing" }, + { "MegaCorp" } }; + + private static String[] companyColumns = { "NAME" }; + + public CompanyData(Connection connection) { + super(connection, companyData, companyColumns, columnTypes); + } + + public String getTableName() { + return "COMPANY"; + } + +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/CompanyDeptData.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/CompanyDeptData.java new file mode 100644 index 0000000000..66d0c25369 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/CompanyDeptData.java @@ -0,0 +1,42 @@ +/** + * + * 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.data; + +import java.sql.Connection; + +import org.apache.tuscany.das.rdb.test.framework.RelationshipData; + + +public class CompanyDeptData extends RelationshipData { + + public static Object[][] data = { + {"MegaCorp", "Advanced Technologies"} + }; + + public CompanyDeptData(Connection c) { + super(c, data); + } + + protected String getParentRetrievalStatement() { + return "select id from company where name = ?"; + } + + protected String getChildUpdateStatement() { + return "update department set companyid = ? where department.name = ?"; + } + +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/CompanyEmpData.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/CompanyEmpData.java new file mode 100644 index 0000000000..300bf57260 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/CompanyEmpData.java @@ -0,0 +1,44 @@ + +/** + * + * 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.data; + +import java.sql.Connection; + +import org.apache.tuscany.das.rdb.test.framework.RelationshipData; + + +public class CompanyEmpData extends RelationshipData { + + public static Object[][] data = { + {"Mary Smith", "ACME Publishing" }, + {"Jane Doe", "Do-rite plumbing"}, + {"Al Smith", "MegaCorp"}}; + + public CompanyEmpData(Connection c) { + super(c, data); + } + + protected String getParentRetrievalStatement() { + return "select employee.id from employee where employee.name = ?"; + } + + protected String getChildUpdateStatement() { + return "update company set company.eotmid = ? where company.name = ?"; + } + +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/CustomerData.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/CustomerData.java new file mode 100644 index 0000000000..149bcfc71b --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/CustomerData.java @@ -0,0 +1,45 @@ +/** + * + * 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.data; + +import java.sql.Connection; + +import org.apache.tuscany.das.rdb.test.framework.TestData; + + +public class CustomerData extends TestData { + + private static Object[][] customerData = { + {new Integer(1), "Williams", "1212 foobar lane"}, + {new Integer(2), "Daniel", "156 Brentfield Loop"}, + {new Integer(3), "Williams", "456 penny lane"}, + {new Integer(4), "Williams", "5000 pineville"}, + {new Integer(5), "Williams", "100000 firefly lane"} + }; + + public CustomerData(Connection connection) { + super(connection, customerData); + } + + + public String getTableName() { + return "CUSTOMER"; + } + + + +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/DepEmpData.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/DepEmpData.java new file mode 100644 index 0000000000..fbd9cf7cab --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/DepEmpData.java @@ -0,0 +1,45 @@ +/** + * + * 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.data; + +import java.sql.Connection; + +import org.apache.tuscany.das.rdb.test.framework.RelationshipData; + + +public class DepEmpData extends RelationshipData { + + private static Object[][] data = { + {"Advanced Technologies", "John Jones"}, + {"Advanced Technologies", "Jane Doe"}, + {"Advanced Technologies", "Al Smith"} + }; + + + public DepEmpData(Connection c) { + super(c, data); + } + + protected String getParentRetrievalStatement() { + return "select department.id from department where department.name = ?"; + } + + protected String getChildUpdateStatement() { + return "update employee set employee.departmentid = ? where employee.name = ?"; + } + +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/DepartmentData.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/DepartmentData.java new file mode 100644 index 0000000000..d3c10affdd --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/DepartmentData.java @@ -0,0 +1,41 @@ +/** + * + * 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.data; + +import java.sql.Connection; +import java.sql.Types; + +import org.apache.tuscany.das.rdb.test.framework.TestDataWithExplicitColumns; + + +public class DepartmentData extends TestDataWithExplicitColumns { + + private static int[] columnTypes = {Types.VARCHAR, Types.VARCHAR, Types.VARCHAR}; + + private static Object[][] deptData = { { "Advanced Technologies", "NY", "123" } }; + + private static String[] deptColumns = { "NAME", "LOCATION", "NUMBER" }; + + public DepartmentData(Connection connection) { + super(connection, deptData, deptColumns, columnTypes); + } + + public String getTableName() { + return "DEPARTMENT"; + } + +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/EmployeeData.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/EmployeeData.java new file mode 100644 index 0000000000..f9dffc9360 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/EmployeeData.java @@ -0,0 +1,45 @@ +/** + * + * 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.data; + +import java.sql.Connection; +import java.sql.Types; + +import org.apache.tuscany.das.rdb.test.framework.TestDataWithExplicitColumns; + + +public class EmployeeData extends TestDataWithExplicitColumns { + + private static int[] columnTypes = {Types.VARCHAR, Types.VARCHAR, Types.SMALLINT}; + + private static Object[][] employeeData = { + { "John Jones", "E0001", new Boolean(false) }, + { "Mary Smith", "E0002", new Boolean(true)}, + { "Jane Doe", "E0003", new Boolean(false)}, + { "Al Smith", "E0004", new Boolean(true) } }; + + private static String[] employeeColumns = { "NAME", "SN", "MANAGER" }; + + public EmployeeData(Connection connection) { + super(connection, employeeData, employeeColumns, columnTypes); + } + + public String getTableName() { + return "EMPLOYEE"; + } + +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/OrderData.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/OrderData.java new file mode 100644 index 0000000000..e6a52204f8 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/OrderData.java @@ -0,0 +1,42 @@ +/** + * + * 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.data; + +import java.sql.Connection; + +import org.apache.tuscany.das.rdb.test.framework.TestData; + + +public class OrderData extends TestData { + + + public static Object[][] orderData = { + {new Integer(1), "recombobulator", new Integer(47), new Integer(1)}, + {new Integer(2), "wrench", new Integer(17), new Integer(3)}, + {new Integer(3), "pliers", new Integer(500), new Integer(1)}, + {new Integer(4), "Tooth Paste", new Integer(12), new Integer(2)} + }; + + public OrderData(Connection c) { + super(c, orderData); + } + + public String getTableName() { + return "ANORDER"; + } + +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/OrderDetailsData.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/OrderDetailsData.java new file mode 100644 index 0000000000..9193f7c6d5 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/OrderDetailsData.java @@ -0,0 +1,43 @@ +/** + * + * 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.data; + +import java.sql.Connection; + +import org.apache.tuscany.das.rdb.test.framework.TestData; + + +public class OrderDetailsData extends TestData { + + //CREATE TABLE ORDERDETAILS (ORDERID INT NOT NULL, PRODUCTID INT NOT NULL, PRICE FLOAT, PRIMARY KEY (ORDERID, PRODUCTID)) + + public static Object[][] orderDetailsData = { + {new Integer(1), new Integer(1), new Float(1.1)}, + {new Integer(1), new Integer(2), new Float(1.2)}, + {new Integer(2), new Integer(1), new Float(2.1)}, + {new Integer(2), new Integer(2), new Float(2.2)} + }; + + public OrderDetailsData(Connection c) { + super(c, orderDetailsData); + } + + public String getTableName() { + return "ORDERDETAILS"; + } + +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/PartData.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/PartData.java new file mode 100644 index 0000000000..dd78b1be35 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/PartData.java @@ -0,0 +1,52 @@ +/** + * + * 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.data; + +import java.sql.Connection; +import java.sql.Types; + +import org.apache.tuscany.das.rdb.test.framework.TestDataWithExplicitColumns; + + +public class PartData extends TestDataWithExplicitColumns { + + + //CREATE TABLE PART (ID INT PRIMARY KEY NOT NULL, NAME VARCHAR(50), QUANTITY INT, PARENT_ID INT ) + + private static String[] partColumns = { "ID" , "NAME", "QUANTITY", "PARENT_ID"}; + + private static int[] columnTypes = {Types.INTEGER, Types.VARCHAR, Types.INTEGER, Types.INTEGER}; + + private static Object[][] partData = { + {new Integer(1), "Engine", new Integer(1), null}, + {new Integer(2), "Block", new Integer(1), new Integer(1)}, + {new Integer(3), "Cam Shaft", new Integer(2), new Integer(1)}, + {new Integer(4), "Piston", new Integer(8), new Integer(1)}, + {new Integer(5), "Piston Ring", new Integer(2), new Integer(4)} + }; + + public PartData(Connection connection) { + super(connection, partData, partColumns, columnTypes); + } + + public String getTableName() { + return "PART"; + } + +} + + diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/StateData.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/StateData.java new file mode 100644 index 0000000000..0c6d41d096 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/StateData.java @@ -0,0 +1,51 @@ +/** + * + * 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.data; + +import java.sql.Connection; +import java.sql.SQLException; + +import org.apache.tuscany.das.rdb.test.framework.TestData; + + +public class StateData extends TestData { + + public StateData(Connection c) { + super(c, stateData); + } + + public String getTableName() { + return "STATES"; + } + + private static Object[][] stateData = { + {new Integer(1), "NC"}, + {new Integer(2), "CO"}, + {new Integer(3), "CA"} + }; + + public void doDeletes() throws SQLException { + deleteRowsFromTable(); + } + + public void doInserts() throws SQLException { + insertRows(); + + } + + +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/TypesData.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/TypesData.java new file mode 100644 index 0000000000..1097b07cc5 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/data/TypesData.java @@ -0,0 +1,64 @@ +/** + * + * 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.data; + +import java.sql.Connection; +import java.sql.Timestamp; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +import org.apache.tuscany.das.rdb.test.framework.TestData; + + +public class TypesData extends TestData { + + private static DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:ss:mm.SSS"); + private static Timestamp timestamp = getTimestamp(); + + private static Object[][] customerData = { + {new Integer(1), timestamp, new Float(1234567.89), new Float(1234567.89)} + }; + + public TypesData(Connection connection) { + super(connection, customerData); + } + + public String getTableName() { + return "TYPETEST"; + } + + + //Utilities + private static Date getDate() { + + try { + return dateFormat.parse("1966-12-20 00:00:00.0"); + } catch (ParseException e) { + throw new RuntimeException(e); + } + + } + + public static Timestamp getTimestamp() { + + return new Timestamp(getDate().getTime()); + + } + +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/DB2Setup.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/DB2Setup.java new file mode 100644 index 0000000000..75df028490 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/DB2Setup.java @@ -0,0 +1,35 @@ +/** + * + * 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/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/DasTest.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/DasTest.java new file mode 100644 index 0000000000..bd195866be --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/DasTest.java @@ -0,0 +1,152 @@ +/** + * + * 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; + + /** + * 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() { + +// 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/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/DatabaseSetup.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/DatabaseSetup.java new file mode 100644 index 0000000000..f0c5223cf0 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/DatabaseSetup.java @@ -0,0 +1,238 @@ +/** + * + * 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/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/DerbySetup.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/DerbySetup.java new file mode 100644 index 0000000000..082b1ec50a --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/DerbySetup.java @@ -0,0 +1,42 @@ +/** + * + * 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/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/JavaStoredProcs.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/JavaStoredProcs.java new file mode 100644 index 0000000000..cd314e0fce --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/JavaStoredProcs.java @@ -0,0 +1,79 @@ +/** + * + * 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/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/MySQLSetup.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/MySQLSetup.java new file mode 100644 index 0000000000..5cec322e70 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/MySQLSetup.java @@ -0,0 +1,95 @@ +/** + * + * 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/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/RelationshipData.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/RelationshipData.java new file mode 100644 index 0000000000..330320656e --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/RelationshipData.java @@ -0,0 +1,81 @@ +/** + * + * 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/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/TestData.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/TestData.java new file mode 100644 index 0000000000..686433bfc8 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/TestData.java @@ -0,0 +1,87 @@ +/** + * + * 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/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/TestDataWithExplicitColumns.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/TestDataWithExplicitColumns.java new file mode 100644 index 0000000000..8ded99af9b --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/TestDataWithExplicitColumns.java @@ -0,0 +1,82 @@ +/** + * + * 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(); + } + } + +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/mappings/IntegerToBooleanConverter.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/mappings/IntegerToBooleanConverter.java new file mode 100644 index 0000000000..e25d2c4c95 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/mappings/IntegerToBooleanConverter.java @@ -0,0 +1,40 @@ +/** + * + * 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.mappings; + +import org.apache.tuscany.das.rdb.Converter; + +public class IntegerToBooleanConverter implements Converter { + + public IntegerToBooleanConverter() { + super(); + } + + public Object getPropertyValue(Object columnData) { + Integer value = (Integer) columnData; + return value.intValue() == 0 ? Boolean.FALSE : Boolean.TRUE; + } + + public Object getColumnValue(Object propertyData) { + Boolean value = (Boolean) propertyData; + if ( value.booleanValue()) + return new Integer(1); + else + return new Integer(0); + } + +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/mappings/SillyDateStringConverter.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/mappings/SillyDateStringConverter.java new file mode 100644 index 0000000000..7c164bd675 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/mappings/SillyDateStringConverter.java @@ -0,0 +1,73 @@ +/** + * + * 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.mappings; + +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +import org.apache.tuscany.das.rdb.Converter; + + +public class SillyDateStringConverter implements Converter { + + public SillyDateStringConverter() { + super(); + } + + private static DateFormat myformat = new SimpleDateFormat("yyyy.MM.dd"); + + private static Date kbday; + + private static Date tbday; + + static { + try { + kbday = myformat.parse("1957.09.27"); + tbday = myformat.parse("1966.12.20"); + } catch (ParseException e) { + throw new RuntimeException(e); + } + } + + public Object getPropertyValue(Object columnData) { + + if (columnData.equals("Williams")) + return kbday; + + if (columnData.equals("Pavick")) + return tbday; + + throw new IllegalArgumentException(); + + } + + public Object getColumnValue(Object propertyData) { + + if (propertyData.equals(kbday)) + return "Williams"; + + if (propertyData.equals(tbday)) + return "Pavick"; + + throw new IllegalArgumentException(); + + } + + +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/mappings/StringToIntegerConverter.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/mappings/StringToIntegerConverter.java new file mode 100644 index 0000000000..8ff57aef6d --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/mappings/StringToIntegerConverter.java @@ -0,0 +1,37 @@ +/** + * + * 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.mappings; + +import org.apache.tuscany.das.rdb.Converter; + +public class StringToIntegerConverter implements Converter { + + public StringToIntegerConverter() { + super(); + } + + public Object getPropertyValue(Object columnData) { + // System.out.println("Converting object.. " + columnData); + + return new Integer(columnData.toString()); + } + + public Object getColumnValue(Object columnData) { + return columnData.toString(); + } + +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/mappings/StringToLongConverter.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/mappings/StringToLongConverter.java new file mode 100644 index 0000000000..74a5e2917f --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/mappings/StringToLongConverter.java @@ -0,0 +1,35 @@ +/** + * + * 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.mappings; + +import org.apache.tuscany.das.rdb.Converter; + +public class StringToLongConverter implements Converter { + + public StringToLongConverter() { + super(); + } + + public Object getPropertyValue(Object columnData) { + return new Long(columnData.toString()); + } + + public Object getColumnValue(Object columnData) { + return columnData.toString(); + } + +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/suites/AllCommonTests.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/suites/AllCommonTests.java new file mode 100644 index 0000000000..14849b8650 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/suites/AllCommonTests.java @@ -0,0 +1,100 @@ +/** + * + * 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.suites; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.apache.tuscany.das.rdb.test.AliasTests; +import org.apache.tuscany.das.rdb.test.BestPracticeTests; +import org.apache.tuscany.das.rdb.test.CUDGeneration; +import org.apache.tuscany.das.rdb.test.CommandGroupTests; +import org.apache.tuscany.das.rdb.test.CompanyTests; +import org.apache.tuscany.das.rdb.test.CompoundKeyTests; +import org.apache.tuscany.das.rdb.test.ConverterTests; +import org.apache.tuscany.das.rdb.test.CorrectedDefectTests; +import org.apache.tuscany.das.rdb.test.CrudWithChangeHistory; +import org.apache.tuscany.das.rdb.test.ExceptionTests; +import org.apache.tuscany.das.rdb.test.GeneratedCommandTests; +import org.apache.tuscany.das.rdb.test.GeneratedId; +import org.apache.tuscany.das.rdb.test.GraphMergeTests; +import org.apache.tuscany.das.rdb.test.NameMappingTests; +import org.apache.tuscany.das.rdb.test.OCCTests; +import org.apache.tuscany.das.rdb.test.OneToOneRelationshipTests; +import org.apache.tuscany.das.rdb.test.OperationOrderingTests; +import org.apache.tuscany.das.rdb.test.Paging; +import org.apache.tuscany.das.rdb.test.PartialUpdateTests; +import org.apache.tuscany.das.rdb.test.PassiveConnectionTests; +import org.apache.tuscany.das.rdb.test.ProgrammaticConfigTests; +import org.apache.tuscany.das.rdb.test.RecursiveTests; +import org.apache.tuscany.das.rdb.test.RelationshipTests; +import org.apache.tuscany.das.rdb.test.ResultSetShapeTests; +import org.apache.tuscany.das.rdb.test.SerializationTests; +import org.apache.tuscany.das.rdb.test.SimplestCrud; +import org.apache.tuscany.das.rdb.test.StoredProcs; +import org.apache.tuscany.das.rdb.test.TopDown; +import org.apache.tuscany.das.rdb.test.TypeTests; +import org.apache.tuscany.das.rdb.test.typed.SimplestStaticCrud; + +public class AllCommonTests { + + public static Test suite() { + TestSuite suite = new TestSuite("All platform-common DAS tests"); + //$JUnit-BEGIN$ + + suite.addTest(new TestSuite (SimplestCrud.class)); + suite.addTest(new TestSuite (CrudWithChangeHistory.class)); + suite.addTest(new TestSuite (SimplestStaticCrud.class)); + suite.addTest(new TestSuite (Paging.class)); + suite.addTest(new TestSuite (GeneratedId.class)); + + suite.addTest(new TestSuite (StoredProcs.class)); + suite.addTest(new TestSuite (CUDGeneration.class)); + suite.addTest(new TestSuite (TopDown.class)); + suite.addTest(new TestSuite (OCCTests.class)); + suite.addTest(new TestSuite (RecursiveTests.class)); + + suite.addTest(new TestSuite (GraphMergeTests.class)); + suite.addTest(new TestSuite (CompoundKeyTests.class)); + suite.addTest(new TestSuite (RelationshipTests.class)); + suite.addTest(new TestSuite (NameMappingTests.class)); + suite.addTest(new TestSuite (GeneratedCommandTests.class)); + + suite.addTest(new TestSuite (CompanyTests.class)); + suite.addTest(new TestSuite (ResultSetShapeTests.class)); + suite.addTest(new TestSuite (TypeTests.class)); + suite.addTest(new TestSuite (OperationOrderingTests.class)); + suite.addTest(new TestSuite (ConverterTests.class)); + + suite.addTest(new TestSuite (PartialUpdateTests.class)); + suite.addTest(new TestSuite (ExceptionTests.class)); + suite.addTest(new TestSuite (PassiveConnectionTests.class)); + suite.addTest(new TestSuite (SerializationTests.class)); + + suite.addTest(new TestSuite (CommandGroupTests.class)); + suite.addTest(new TestSuite (BestPracticeTests.class)); + suite.addTest(new TestSuite (CorrectedDefectTests.class)); + suite.addTest(new TestSuite (OneToOneRelationshipTests.class)); + + suite.addTest(new TestSuite (ProgrammaticConfigTests.class)); + suite.addTest(new TestSuite (AliasTests.class)); + + //$JUnit-END$ + return suite; + } + +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/suites/AllTestsDB2.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/suites/AllTestsDB2.java new file mode 100644 index 0000000000..6c102743a5 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/suites/AllTestsDB2.java @@ -0,0 +1,39 @@ +/** + * + * 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.suites; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.apache.tuscany.das.rdb.test.ReadDBSchemaTests; +import org.apache.tuscany.das.rdb.test.framework.DB2Setup; + +public class AllTestsDB2 { + + + public static Test suite() { + + TestSuite suite = new TestSuite(); + suite.addTest(AllCommonTests.suite()); + suite.addTest(new TestSuite (ReadDBSchemaTests.class)); + + TestSuite suite2 = new TestSuite("All DAS tests on DB2"); + suite2.addTest(new DB2Setup(suite)); + return suite2; + + } +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/suites/AllTestsDerby.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/suites/AllTestsDerby.java new file mode 100644 index 0000000000..c6ea850e76 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/suites/AllTestsDerby.java @@ -0,0 +1,34 @@ +/** + * + * 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.suites; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.apache.tuscany.das.rdb.test.framework.DerbySetup; + +public class AllTestsDerby extends TestSuite { + + + public static Test suite() { + + TestSuite suite = new TestSuite("All DAS tests on Derby"); + suite.addTest(new DerbySetup(AllCommonTests.suite())); + return suite; + + } +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/suites/AllTestsMySQL.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/suites/AllTestsMySQL.java new file mode 100644 index 0000000000..20cc727afb --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/suites/AllTestsMySQL.java @@ -0,0 +1,34 @@ +/** + * + * 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.suites; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.apache.tuscany.das.rdb.test.framework.MySQLSetup; + +public class AllTestsMySQL { + + + public static Test suite() { + + TestSuite suite = new TestSuite("All DAS tests on MySQL"); + suite.addTest(new MySQLSetup(AllCommonTests.suite())); + return suite; + + } +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/typed/SimplestStaticCrud.java b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/typed/SimplestStaticCrud.java new file mode 100644 index 0000000000..26dbffe8f7 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/typed/SimplestStaticCrud.java @@ -0,0 +1,56 @@ +/** + * + * 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.typed; + +import java.io.InputStream; +import java.util.Collection; + +import org.apache.tuscany.das.rdb.Command; +import org.apache.tuscany.das.rdb.DAS; +import org.apache.tuscany.das.rdb.test.customer.CustomerFactory; +import org.apache.tuscany.das.rdb.test.data.CustomerData; +import org.apache.tuscany.das.rdb.test.framework.DasTest; +import org.apache.tuscany.sdo.util.SDOUtil; + +import commonj.sdo.DataObject; + + +/** + */ +public class SimplestStaticCrud extends DasTest { + + protected void setUp() throws Exception { + super.setUp(); + new CustomerData(getAutoConnection()).refresh(); + } + + public void testRead() throws Exception { + InputStream mapping = getClass().getClassLoader().getResourceAsStream("basicStaticCustomer.xml"); + DAS das = DAS.FACTORY.createDAS(mapping, getConnection()); + SDOUtil.registerStaticTypes(CustomerFactory.class); + + Command select = das.createCommand("Select ID, LASTNAME, ADDRESS from CUSTOMER where LASTNAME = ?"); + select.setParameter(1, "Williams"); + + DataObject root = select.executeQuery(); + + Collection customers = root.getList("Customer"); + assertEquals(4, customers.size()); + } + + +} diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/1xM_mapping_no_cud.xml b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/1xM_mapping_no_cud.xml new file mode 100644 index 0000000000..e1fdc93078 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/1xM_mapping_no_cud.xml @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="ASCII"?> +<!-- + 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. + --> +<Config xsi:noNamespaceSchemaLocation="http:///org.apache.tuscany.das.rdb/config.xsd" +xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + + <Table tableName="CUSTOMER" typeName="Customer"> + <Column columnName="ID" propertyName="ID" primaryKey="true"/> + </Table> + + <Table tableName="ANORDER" typeName="AnOrder"> + <Column columnName="CUSTOMER_ID" propertyName="Customer_ID"/> + <Column columnName="ID" propertyName="ID" primaryKey="true"/> + </Table> + + <Relationship name="orders" primaryKeyTable="CUSTOMER" foreignKeyTable="ANORDER" many="true"> + <KeyPair primaryKeyColumn="ID" foreignKeyColumn="CUSTOMER_ID"/> + </Relationship> + +</Config> + diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/BooksConfig.xml b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/BooksConfig.xml new file mode 100644 index 0000000000..3f65e2beb9 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/BooksConfig.xml @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="ASCII"?> +<!-- + 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. + --> +<Config xsi:noNamespaceSchemaLocation="http:///org.apache.tuscany.das.rdb/config.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + + <Command name="select book 1" SQL="select * from BOOK where BOOK_ID = 1" kind="Select"/> + <Command name="update book 1" SQL="update BOOK set OCC = ? where BOOK_ID = 1" kind="Update"/> + + <Table tableName="BOOK"> + <Column columnName="BOOK_ID" primaryKey="true"/> + <Column columnName="OCC" collision="true"/> + </Table> + +</Config> diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/BooksConfigWithAlias.xml b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/BooksConfigWithAlias.xml new file mode 100644 index 0000000000..8eea4194d4 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/BooksConfigWithAlias.xml @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="ASCII"?> +<!-- + 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. + --> +<Config xsi:noNamespaceSchemaLocation="http:///org.apache.tuscany.das.rdb/config.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + + <Command name="get all books" SQL="SELECT * FROM BOOK" kind="Select"/> + + <Command name="get Cat in the Hat" SQL="SELECT * FROM BOOK WHERE NAME = 'Cat in the Hat'" kind="Select"/> + + <Command name="get book by ID" SQL="SELECT * FROM BOOK WHERE BOOK.BOOK_ID = ?" kind="Select"/> + + + + <Table tableName="BOOK" typeName="Book"> + <Column columnName="BOOK_ID" primaryKey="true"/> + <Column columnName="AUTHOR" propertyName="Writer"/> + <Column columnName="OCC" collision="true"/> + </Table> + +</Config> diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/CompanyConfig.xml b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/CompanyConfig.xml new file mode 100644 index 0000000000..425ff02df7 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/CompanyConfig.xml @@ -0,0 +1,40 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. + --> +<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> diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/CompanyEmployeeConfig.xml b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/CompanyEmployeeConfig.xml new file mode 100644 index 0000000000..8fd75441b1 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/CompanyEmployeeConfig.xml @@ -0,0 +1,51 @@ +<?xml version="1.0" encoding="ASCII"?> +<!-- + 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. + --> +<Config xsi:noNamespaceSchemaLocation="http:///org.apache.tuscany.das.rdb/config.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + + <Command name="get all companies" SQL="select * from COMPANY" kind = "Select"/> + + <Command name="get named employee" SQL="select * from EMPLOYEE where NAME= ?" kind = "Select"/> + + <Command name="get named employee with company" + SQL="select * from EMPLOYEE left outer join COMPANY on EMPLOYEE.ID = COMPANY.EOTMID where EMPLOYEE.NAME= ?" kind = "Select"/> + + <Command name="get employee by ID" SQL="select * from EMPLOYEE where ID= ?" kind = "Select"/> + + <Command name="get all employees" SQL="select * from EMPLOYEE" kind = "Select"/> + + <Command name="get companies with employee of the month" + SQL="select * from COMPANY left outer join EMPLOYEE on COMPANY.EOTMID = EMPLOYEE.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> + + <Table tableName="EMPLOYEE"> + <Column columnName="ID" primaryKey="true" generated="true"/> + </Table> + + <Relationship name="company->employee" primaryKeyTable="EMPLOYEE" foreignKeyTable="COMPANY" many="false" > + <KeyPair primaryKeyColumn="ID" foreignKeyColumn="EOTMID" /> + </Relationship> + +</Config> + diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/CustOrdersConnectionProps.xml b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/CustOrdersConnectionProps.xml new file mode 100644 index 0000000000..22de7ad66f --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/CustOrdersConnectionProps.xml @@ -0,0 +1,58 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. + --> +<Config xsi:noNamespaceSchemaLocation="http:///org.apache.tuscany.das.rdb/config.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + + <Command name="all customers" SQL="select * from CUSTOMER" kind="Select"/> + + <Command name="customer and orders" + SQL="select * from CUSTOMER left join ANORDER on CUSTOMER.ID = ANORDER.CUSTOMER_ID where CUSTOMER.ID = ?" + kind="Select"> +<!-- <Parameter name=":ID"/> --> + </Command> + + <Command name="customer and orders" + SQL="select * from CUSTOMER left join ANORDER on CUSTOMER.ID = ANORDER.CUSTOMER_ID where CUSTOMER.ID = ?" + kind="Select"> + <Parameter name=":ID"/> + </Command> + + <!-- Test usage of '?' rather than named parameter --> + <Command name="order by id with ?" SQL="select * from ANORDER where ANORDER.ID = ?" + kind="Select"> + <Parameter name=":ID"/> + </Command> + + <Command name="update customer" + SQL="update CUSTOMER set LASTNAME = 'Pavick' where ID = ?" + kind="Update"> + <Parameter name="ID"/> + </Command> + + <Table tableName="CUSTOMER"> + <Column columnName="ID" primaryKey="true"/> + </Table> + + <Table tableName="ANORDER"> + <Column columnName="ID" primaryKey="true"/> + </Table> + + <Relationship name="orders" primaryKeyTable="CUSTOMER" + foreignKeyTable="ANORDER" many="true"> + <KeyPair primaryKeyColumn="ID" foreignKeyColumn="CUSTOMER_ID"/> + </Relationship> + +</Config> diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/CustomerConfigWithConverter.xml b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/CustomerConfigWithConverter.xml new file mode 100644 index 0000000000..67941aef83 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/CustomerConfigWithConverter.xml @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="ASCII"?> +<!-- + 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. + --> +<Config xsi:noNamespaceSchemaLocation="http:///org.apache.tuscany.das.rdb/config.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + + + <Command name="testArbitraryConverter" SQL="Select * from CUSTOMER where ID = 1" kind="Select"> + <ResultDescriptor columnName="ID" tableName="CUSTOMER" columnType="commonj.sdo.IntObject"/> + <ResultDescriptor columnName="LASTNAME" tableName="CUSTOMER" columnType="commonj.sdo.Date"/> + <ResultDescriptor columnName="ADDRESS" tableName="CUSTOMER" columnType="commonj.sdo.String"/> + </Command> + + <Table tableName="CUSTOMER"> + <Column columnName="ID" primaryKey="true"/> + <Column columnName="LASTNAME" converterClassName="org.apache.tuscany.das.rdb.test.mappings.SillyDateStringConverter"/> + </Table> + +</Config> diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/CustomerConfigWithIDConverter.xml b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/CustomerConfigWithIDConverter.xml new file mode 100644 index 0000000000..10e17d94df --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/CustomerConfigWithIDConverter.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="ASCII"?> +<!-- + 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. + --> +<Config xsi:noNamespaceSchemaLocation="http:///org.apache.tuscany.das.rdb/config.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + + <Command name="literal" SQL="Select 99, 'Roosevelt', '1600 Pennsylvania Avenue' from customer" kind="Select"> + <ResultDescriptor columnName="ID" tableName="CUSTOMER" columnType="commonj.sdo.Long"/> + <ResultDescriptor columnName="LASTNAME" tableName="CUSTOMER" columnType="commonj.sdo.String"/> + <ResultDescriptor columnName="ADDRESS" tableName="CUSTOMER" columnType="commonj.sdo.String"/> + </Command> + + <Table tableName="CUSTOMER"> + <Column columnName="ID" converterClassName="org.apache.tuscany.das.rdb.test.mappings.StringToLongConverter"/> + </Table> + +</Config> diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/CustomersOrdersConfig.xml b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/CustomersOrdersConfig.xml new file mode 100644 index 0000000000..4ec809416d --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/CustomersOrdersConfig.xml @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="ASCII"?> +<!-- + 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. + --> +<Config xsi:noNamespaceSchemaLocation="http:///org.apache.tuscany.das.rdb/config.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + + <Command name="all customers" SQL="select * from CUSTOMER" kind="Select"/> + + <Command name="customer and orders" + SQL="select * from CUSTOMER left join ANORDER on CUSTOMER.ID = ANORDER.CUSTOMER_ID where CUSTOMER.ID = ?" + kind="Select"> + <Parameter name=":ID"/> + </Command> + + <Command name="order by id" SQL="select * from ANORDER where ANORDER.ID = ?" + kind="Select"> + <Parameter name=":ID"/> + </Command> + + <Table tableName="CUSTOMER"> + <Column columnName="ID" primaryKey="true"/> + </Table> + + <Table tableName="ANORDER"> + <Column columnName="ID" primaryKey="true"/> + </Table> + + <Relationship name="orders" primaryKeyTable="CUSTOMER" + foreignKeyTable="ANORDER" many="true"> + <KeyPair primaryKeyColumn="ID" foreignKeyColumn="CUSTOMER_ID"/> + </Relationship> + +</Config> diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/InvalidConfig1.xml b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/InvalidConfig1.xml new file mode 100644 index 0000000000..b68ef105c7 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/InvalidConfig1.xml @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="ASCII"?> +<!-- + 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. + --> +<Config xsi:noNamespaceSchemaLocation="http:///org.apache.tuscany.das.rdb/config.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + + <Table tableName="ORDERDETAILS"> + <Column columnName="ORDERID" primaryKey="true"/> + <Column columnName="PRODUCTID" primaryKey="true"/> + </Table> + + + <Relationship name="ORDERDETAILS" primaryKeyTable="xxx" + foreignKeyTable="ORDERDETAILS" many="true"> + <KeyPair primaryKeyColumn="ID" foreignKeyColumn="ORDERID"/> + </Relationship> + +</Config>
\ No newline at end of file diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/ManagedBooksConfig.xml b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/ManagedBooksConfig.xml new file mode 100644 index 0000000000..c8cd1a4421 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/ManagedBooksConfig.xml @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="ASCII"?> +<!-- + 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. + --> +<Config xsi:noNamespaceSchemaLocation="http:///org.apache.tuscany.das.rdb/config.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + + <Command name="select book 1" SQL="select * from BOOK where BOOK_ID = 1" kind="Select"/> + <Command name="update book 1" SQL="update BOOK set OCC = ? where BOOK_ID = 1" kind="Update"/> + + <Table tableName="BOOK"> + <Column columnName="BOOK_ID" primaryKey="true"/> + <Column columnName="OCC" collision="true" managed="true"/> + </Table> + +</Config> diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/OrdersOrderDetailsConfig.xml b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/OrdersOrderDetailsConfig.xml new file mode 100644 index 0000000000..7403e3e30d --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/OrdersOrderDetailsConfig.xml @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="ASCII"?> +<!-- + 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. + --> +<Config xsi:noNamespaceSchemaLocation="http:///org.apache.tuscany.das.rdb/config.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + + <Table tableName="ORDERDETAILS"> + <Column columnName="ORDERID" primaryKey="true"/> + <Column columnName="PRODUCTID" primaryKey="true"/> + </Table> + + <Table tableName="ANORDER"> + <Column columnName="ID" primaryKey="true"/> + </Table> + + <Relationship name="ORDERDETAILS" primaryKeyTable="ANORDER" + foreignKeyTable="ORDERDETAILS" many="true"> + <KeyPair primaryKeyColumn="ID" foreignKeyColumn="ORDERID"/> + </Relationship> + +</Config> diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/PartsConfig.xml b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/PartsConfig.xml new file mode 100644 index 0000000000..b51b111841 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/PartsConfig.xml @@ -0,0 +1,47 @@ +<?xml version="1.0" encoding="ASCII"?> +<!-- + 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. + --> +<Config xsi:noNamespaceSchemaLocation="http:///org.apache.tuscany.das.rdb/config.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + + <Command name="readEngineParts" kind="Select" SQL="SELECT P1.*, P2.*, P3.* FROM PART AS P1 + LEFT JOIN PART AS P2 ON P1.ID = P2.PARENT_ID + LEFT JOIN PART AS P3 on P2.ID = P3.PARENT_ID WHERE P1.ID = 1"> + <ResultDescriptor columnName="ID" columnType="commonj.sdo.IntObject" tableName="PART"/> + <ResultDescriptor columnName="NAME" columnType="commonj.sdo.String" tableName="PART"/> + <ResultDescriptor columnName="QUANTITY" columnType="commonj.sdo.IntObject" tableName="PART"/> + <ResultDescriptor columnName="PARENT_ID" columnType="commonj.sdo.IntObject" tableName="PART"/> + + <ResultDescriptor columnName="ID" columnType="commonj.sdo.IntObject" tableName="PART"/> + <ResultDescriptor columnName="NAME" columnType="commonj.sdo.String" tableName="PART"/> + <ResultDescriptor columnName="QUANTITY" columnType="commonj.sdo.IntObject" tableName="PART"/> + <ResultDescriptor columnName="PARENT_ID" columnType="commonj.sdo.IntObject" tableName="PART"/> + + <ResultDescriptor columnName="ID" columnType="commonj.sdo.IntObject" tableName="PART"/> + <ResultDescriptor columnName="NAME" columnType="commonj.sdo.String" tableName="PART"/> + <ResultDescriptor columnName="QUANTITY" columnType="commonj.sdo.IntObject" tableName="PART"/> + <ResultDescriptor columnName="PARENT_ID" columnType="commonj.sdo.IntObject" tableName="PART"/> + + </Command> + + <Table tableName="PART"> + <Column columnName="ID" primaryKey="true"/> + </Table> + + <Relationship name="subparts" primaryKeyTable="PART" foreignKeyTable="PART" many="true"> + <KeyPair primaryKeyColumn="ID" foreignKeyColumn="PARENT_ID"/> + </Relationship> + +</Config> diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/basicCompanyDepartmentMapping.xml b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/basicCompanyDepartmentMapping.xml new file mode 100644 index 0000000000..f6d760386b --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/basicCompanyDepartmentMapping.xml @@ -0,0 +1,36 @@ +<?xml version="1.0" encoding="ASCII"?> +<!-- + 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. + --> +<Config xsi:noNamespaceSchemaLocation="http:///org.apache.tuscany.das.rdb/config.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + + <Table tableName="COMPANY"> + <Column columnName="ID" primaryKey="true" generated="true"/> + <Column columnName="NAME"/> + </Table> + + <Table tableName="DEPARTMENT"> + <Column columnName="ID" primaryKey="true" generated="true"/> + <Column columnName="NAME"/> + <Column columnName="NUMBER"/> + <Column columnName="COMPANYID"/> + <Column columnName="EOTM"/> + </Table> + + <Relationship name="departments" primaryKeyTable="COMPANY" foreignKeyTable="DEPARTMENT" many="true"> + <KeyPair primaryKeyColumn="ID" foreignKeyColumn="COMPANYID"/> + </Relationship> + +</Config> diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/basicCompanyMapping.xml b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/basicCompanyMapping.xml new file mode 100644 index 0000000000..0455ad8445 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/basicCompanyMapping.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="ASCII"?> +<!-- + 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. + --> +<Config xsi:noNamespaceSchemaLocation="http:///org.apache.tuscany.das.rdb/config.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <Table tableName="COMPANY"> + <Column columnName="ID" primaryKey="true" generated="true"/> + <Column columnName="NAME"/> + </Table> +</Config> diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/basicCustomerMapping.xml b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/basicCustomerMapping.xml new file mode 100644 index 0000000000..1713026a62 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/basicCustomerMapping.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="ASCII"?> +<!-- + 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. + --> +<Config xsi:noNamespaceSchemaLocation="http:///org.apache.tuscany.das.rdb/config.xsd" +xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + + <Table tableName="CUSTOMER"> + <Column columnName="ID" primaryKey="true"/> + <Column columnName="LASTNAME"/> + <Column columnName="ADDRESS"/> + </Table> + +</Config> diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/basicCustomerMappingWithCUD.xml b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/basicCustomerMappingWithCUD.xml new file mode 100644 index 0000000000..8cb5137728 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/basicCustomerMappingWithCUD.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="ASCII"?> +<!-- + 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. + --> +<Config xsi:noNamespaceSchemaLocation="http:///org.apache.tuscany.das.rdb/config.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + + <Table tableName="CUSTOMER"> + <create sql="insert into customer values (?, ?, ?)" parameters="ID LASTNAME ADDRESS"/> + <update sql="update customer set lastname = ?, address = ? where ID = ?" parameters="LASTNAME ADDRESS ID"/> + <delete sql="delete from customer where ID = ?" parameters="ID"/> + </Table> + +</Config> diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/basicCustomerMappingWithCUD2.xml b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/basicCustomerMappingWithCUD2.xml new file mode 100644 index 0000000000..bc6b8c278b --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/basicCustomerMappingWithCUD2.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="ASCII"?> +<!-- + 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. + --> +<Config xsi:noNamespaceSchemaLocation="http:///org.apache.tuscany.das.rdb/config.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + + <Table tableName="CUSTOMER"> + <create sql="insert into customer values (?, ?, ?)" parameters="ID LASTNAME ADDRESS"/> + <update sql="update customer set lastname = ? where ID = ?" parameters="LASTNAME ID"/> + <delete sql="delete from customer where ID = ?" parameters="ID"/> + <Column columnName="ID" primaryKey="true"/> + <Column columnName="LASTNAME"/> + <Column columnName="ADDRESS"/> + </Table> + +</Config> diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/basicCustomerMappingWithInvalidCUD.xml b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/basicCustomerMappingWithInvalidCUD.xml new file mode 100644 index 0000000000..4b66281489 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/basicCustomerMappingWithInvalidCUD.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="ASCII"?> +<!-- + 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. + --> +<Config xsi:noNamespaceSchemaLocation="http:///org.apache.tuscany.das.rdb/config.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + + <Table tableName="CUSTOMER"> + <create sql="insert into customer blah values (?, ?, ?)" parameters="ID LASTNAME ADDRESS"/> + <update sql="update customer blah set lastname = ?, address = ? where ID = ?" parameters="LASTNAME ADDRESS ID"/> + <delete sql="delete from customer blah where ID = ?" parameters="ID"/> + + <Column columnName="ID" primaryKey="true"/> + <Column columnName="LASTNAME"/> + <Column columnName="ADDRESS"/> + </Table> + +</Config> diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/basicCustomerOrderMapping.xml b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/basicCustomerOrderMapping.xml new file mode 100644 index 0000000000..f7bb65934c --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/basicCustomerOrderMapping.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="ASCII"?> +<!-- + 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. + --> +<Config xsi:noNamespaceSchemaLocation="http:///org.apache.tuscany.das.rdb/config.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + + <Table tableName="CUSTOMER"> + <Column columnName="ID" primaryKey="true"/> + </Table> + <Table tableName="ANORDER"> + <Column columnName="ID" primaryKey="true"/> + <Column columnName="CUSTOMER_ID"/> + </Table> + + <Relationship name="orders" primaryKeyTable="CUSTOMER" foreignKeyTable="ANORDER" many="true"> + <KeyPair primaryKeyColumn="ID" foreignKeyColumn="CUSTOMER_ID"/> + </Relationship> + +</Config> + diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/basicStaticCustomer.xml b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/basicStaticCustomer.xml new file mode 100644 index 0000000000..65e5bea7da --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/basicStaticCustomer.xml @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="ASCII"?> +<!-- + 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. + --> +<Config xsi:noNamespaceSchemaLocation="http:///org.apache.tuscany.das.rdb/config.xsd" +xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" +dataObjectModel="http:///org.apache.tuscany.das.rdb.test/customer.xsd"> + + <Table tableName="CUSTOMER" typeName="Customer"> + <Column columnName="ID" primaryKey="true"/> + <Column columnName="LASTNAME"/> + <Column columnName="ADDRESS"/> + </Table> + +</Config> diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/cityStates.xml b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/cityStates.xml new file mode 100644 index 0000000000..d8fe1261ab --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/cityStates.xml @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="ASCII"?> +<!-- + 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. + --> +<Config xsi:noNamespaceSchemaLocation="http:///org.apache.tuscany.das.rdb/config.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + + <Table tableName="STATES"> + <Column columnName="ID" primaryKey="true"/> + <Column columnName="NAME"/> + </Table> + + <Table tableName="CITIES"> + + <Column columnName="ID" primaryKey="true"/> + <Column columnName="NAME"/> + <Column columnName="STATE_ID"/> + + </Table> + + <Relationship name="cities" primaryKeyTable="STATES" foreignKeyTable="CITIES" many="true"> + <KeyPair primaryKeyColumn="ID" foreignKeyColumn="STATE_ID"/> + </Relationship> + + +</Config> diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/company.ecore b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/company.ecore new file mode 100644 index 0000000000..888acdf1c3 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/company.ecore @@ -0,0 +1,130 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<ecore:EPackage xmi:version="2.0"
+ xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="company"
+ nsURI="org.apache.tuscany.das.rdb.test/company.xsd" nsPrefix="company">
+ <eClassifiers xsi:type="ecore:EClass" name="CompanyType">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="name" value="CompanyType"/>
+ <details key="kind" value="elementOnly"/>
+ </eAnnotations>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="departments" lowerBound="1"
+ upperBound="-1" eType="#//DepartmentType" containment="true" resolveProxies="false">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="kind" value="element"/>
+ <details key="name" value="departments"/>
+ </eAnnotations>
+ </eStructuralFeatures>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="employeeOfTheMonth" unique="false"
+ eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//IDREF">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="kind" value="attribute"/>
+ <details key="name" value="employeeOfTheMonth"/>
+ </eAnnotations>
+ </eStructuralFeatures>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" unique="false" eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//String">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="kind" value="attribute"/>
+ <details key="name" value="name"/>
+ </eAnnotations>
+ </eStructuralFeatures>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EClass" name="DepartmentType">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="name" value="DepartmentType"/>
+ <details key="kind" value="elementOnly"/>
+ </eAnnotations>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="employees" lowerBound="1"
+ upperBound="-1" eType="#//EmployeeType" containment="true" resolveProxies="false">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="kind" value="element"/>
+ <details key="name" value="employees"/>
+ </eAnnotations>
+ </eStructuralFeatures>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="location" unique="false"
+ eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//String">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="kind" value="attribute"/>
+ <details key="name" value="location"/>
+ </eAnnotations>
+ </eStructuralFeatures>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" unique="false" eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//String">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="kind" value="attribute"/>
+ <details key="name" value="name"/>
+ </eAnnotations>
+ </eStructuralFeatures>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="number" unique="false"
+ eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//Int" unsettable="true">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="kind" value="attribute"/>
+ <details key="name" value="number"/>
+ </eAnnotations>
+ </eStructuralFeatures>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EClass" name="DocumentRoot">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="name" value=""/>
+ <details key="kind" value="mixed"/>
+ </eAnnotations>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="mixed" unique="false" upperBound="-1"
+ eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EFeatureMapEntry">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="kind" value="elementWildcard"/>
+ <details key="name" value=":mixed"/>
+ </eAnnotations>
+ </eStructuralFeatures>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="xMLNSPrefixMap" upperBound="-1"
+ eType="ecore:EClass http://www.eclipse.org/emf/2002/Ecore#//EStringToStringMapEntry"
+ transient="true" containment="true" resolveProxies="false">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="kind" value="attribute"/>
+ <details key="name" value="xmlns:prefix"/>
+ </eAnnotations>
+ </eStructuralFeatures>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="xSISchemaLocation" upperBound="-1"
+ eType="ecore:EClass http://www.eclipse.org/emf/2002/Ecore#//EStringToStringMapEntry"
+ transient="true" containment="true" resolveProxies="false">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="kind" value="attribute"/>
+ <details key="name" value="xsi:schemaLocation"/>
+ </eAnnotations>
+ </eStructuralFeatures>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="company" upperBound="-2"
+ eType="#//CompanyType" volatile="true" transient="true" derived="true" containment="true"
+ resolveProxies="false">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="kind" value="element"/>
+ <details key="name" value="company"/>
+ <details key="namespace" value="##targetNamespace"/>
+ </eAnnotations>
+ </eStructuralFeatures>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EClass" name="EmployeeType">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="name" value="EmployeeType"/>
+ <details key="kind" value="empty"/>
+ </eAnnotations>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="manager" unique="false"
+ eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//Boolean"
+ unsettable="true">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="kind" value="attribute"/>
+ <details key="name" value="manager"/>
+ </eAnnotations>
+ </eStructuralFeatures>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" unique="false" eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//String">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="kind" value="attribute"/>
+ <details key="name" value="name"/>
+ </eAnnotations>
+ </eStructuralFeatures>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="sN" unique="false" eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//ID"
+ iD="true">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="kind" value="attribute"/>
+ <details key="name" value="SN"/>
+ </eAnnotations>
+ </eStructuralFeatures>
+ </eClassifiers>
+</ecore:EPackage>
diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/company.genmodel b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/company.genmodel new file mode 100644 index 0000000000..0b89c2c0c8 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/company.genmodel @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<genmodel:GenModel xmi:version="2.0"
+ xmlns:xmi="http://www.omg.org/XMI" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
+ xmlns:genmodel="http://www.eclipse.org/emf/2002/GenModel" modelDirectory="/rdbdas2/src/test/java"
+ modelPluginID="das.tests" modelName="Company" rootExtendsInterface="" rootExtendsClass="org.eclipse.emf.ecore.sdo.impl.EDataObjectImpl"
+ rootImplementsInterface="org.eclipse.emf.ecore.sdo.InternalEDataObject" suppressEMFTypes="true"
+ suppressEMFMetaData="true" featureMapWrapperInterface="commonj.sdo.Sequence" featureMapWrapperInternalInterface="org.eclipse.emf.ecore.sdo.util.ESequence"
+ featureMapWrapperClass="org.eclipse.emf.ecore.sdo.util.BasicESequence" importerID="org.eclipse.xsd.ecore.importer">
+ <foreignModel>company.xsd</foreignModel>
+ <staticPackages>http://www.eclipse.org/emf/2003/SDO</staticPackages>
+ <modelPluginVariables>EMF_COMMONJ_SDO=org.eclipse.emf.commonj.sdo</modelPluginVariables>
+ <modelPluginVariables>EMF_ECORE_SDO=org.eclipse.emf.ecore.sdo</modelPluginVariables>
+ <genPackages prefix="Company" basePackage="org.apache.tuscany.das.rdb.test" resource="XML"
+ disposableProviderFactory="true" ecorePackage="company.ecore#/">
+ <genClasses ecoreClass="company.ecore#//CompanyType">
+ <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference company.ecore#//CompanyType/departments"/>
+ <genFeatures createChild="false" ecoreFeature="ecore:EAttribute company.ecore#//CompanyType/employeeOfTheMonth"/>
+ <genFeatures createChild="false" ecoreFeature="ecore:EAttribute company.ecore#//CompanyType/name"/>
+ </genClasses>
+ <genClasses ecoreClass="company.ecore#//DepartmentType">
+ <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference company.ecore#//DepartmentType/employees"/>
+ <genFeatures createChild="false" ecoreFeature="ecore:EAttribute company.ecore#//DepartmentType/location"/>
+ <genFeatures createChild="false" ecoreFeature="ecore:EAttribute company.ecore#//DepartmentType/name"/>
+ <genFeatures createChild="false" ecoreFeature="ecore:EAttribute company.ecore#//DepartmentType/number"/>
+ </genClasses>
+ <genClasses ecoreClass="company.ecore#//DocumentRoot">
+ <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EAttribute company.ecore#//DocumentRoot/mixed"/>
+ <genFeatures property="None" notify="false" createChild="false" ecoreFeature="ecore:EReference company.ecore#//DocumentRoot/xMLNSPrefixMap"/>
+ <genFeatures property="None" notify="false" createChild="false" ecoreFeature="ecore:EReference company.ecore#//DocumentRoot/xSISchemaLocation"/>
+ <genFeatures property="None" notify="false" createChild="false" ecoreFeature="ecore:EReference company.ecore#//DocumentRoot/company"/>
+ </genClasses>
+ <genClasses ecoreClass="company.ecore#//EmployeeType">
+ <genFeatures createChild="false" ecoreFeature="ecore:EAttribute company.ecore#//EmployeeType/manager"/>
+ <genFeatures createChild="false" ecoreFeature="ecore:EAttribute company.ecore#//EmployeeType/name"/>
+ <genFeatures createChild="false" ecoreFeature="ecore:EAttribute company.ecore#//EmployeeType/sN"/>
+ </genClasses>
+ </genPackages>
+</genmodel:GenModel>
diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/company.xsd b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/company.xsd new file mode 100644 index 0000000000..42cf60c588 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/company.xsd @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. + --> +<xsd:schema targetNamespace="org.apache.tuscany.das.rdb.test/company.xsd" + xmlns:company="org.apache.tuscany.das.rdb.test/company.xsd" + xmlns:xsd="http://www.w3.org/2001/XMLSchema" + xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"> + + <xsd:element name="company" type="company:CompanyType"/> + + <xsd:complexType name="CompanyType"> + <xsd:sequence> + <xsd:element maxOccurs="unbounded" name="departments" type="company:DepartmentType"/> + </xsd:sequence> + <xsd:attribute name="name" type="xsd:string"/> + <xsd:attribute name="employeeOfTheMonth" type="xsd:IDREF" ecore:reference="EmployeeType"/> + </xsd:complexType> + + <xsd:complexType name="DepartmentType"> + <xsd:sequence> + <xsd:element maxOccurs="unbounded" name="employees" type="company:EmployeeType"/> + </xsd:sequence> + <xsd:attribute name="name" type="xsd:string"/> + <xsd:attribute name="location" type="xsd:string"/> + <xsd:attribute name="number" type="xsd:int"/> + </xsd:complexType> + <xsd:complexType name="EmployeeType"> + <xsd:attribute name="name" type="xsd:string"/> + <xsd:attribute name="SN" type="xsd:ID"/> + <xsd:attribute name="manager" type="xsd:boolean"/> + </xsd:complexType> + </xsd:schema> diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/companyMapping.xml b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/companyMapping.xml new file mode 100644 index 0000000000..76ff87a095 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/companyMapping.xml @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="ASCII"?> +<!-- + 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. + --> +<Config xsi:noNamespaceSchemaLocation="http:///org.apache.tuscany.das.rdb/config.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + + <Table tableName="COMPANY" typeName="CompanyType"> + <Column columnName="ID" primaryKey="true"/> + </Table> + + <Table tableName="DEPARTMENT" typeName="DepartmentType"> + <Column columnName="ID" primaryKey="true"/> + </Table> + + <Table tableName="EMPLOYEE" typeName="EmployeeType"> + <Column columnName="ID" primaryKey="true"/> + </Table> + + <Relationship name="departments" primaryKeyTable="COMPANY" foreignKeyTable="DEPARTMENT" many="true"> + <KeyPair primaryKeyColumn="ID" foreignKeyColumn="COMPANYID"/> + </Relationship> + + <Relationship name="employees" primaryKeyTable="DEPARTMENT" foreignKeyTable="EMPLOYEE" many="true"> + <KeyPair primaryKeyColumn="ID" foreignKeyColumn="DEPARTMENTID"/> + </Relationship> + +</Config> diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/companyMappingWithConverters.xml b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/companyMappingWithConverters.xml new file mode 100644 index 0000000000..d51e74a824 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/companyMappingWithConverters.xml @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="ASCII"?> +<!-- + 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. + --> +<Config xsi:noNamespaceSchemaLocation="http:///org.apache.tuscany.das.rdb/config.xsd" +xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" +dataObjectModel="org.apache.tuscany.das.rdb.test/company.xsd"> + + <Table tableName="COMPANY" typeName="CompanyType"> + <Column columnName="ID" primaryKey="true"/> + </Table> + + <Table tableName="DEPARTMENT" typeName="DepartmentType"> + <Column columnName="ID" primaryKey="true"/> + <Column columnName="NUMBER" converterClassName="org.apache.tuscany.das.rdb.test.mappings.StringToIntegerConverter"/> + </Table> + + <Table tableName="EMPLOYEE" typeName="EmployeeType"> + <Column columnName="ID" primaryKey="true"/> + <Column columnName="MANAGER" converterClassName="org.apache.tuscany.das.rdb.test.mappings.IntegerToBooleanConverter"/> + </Table> + + <Relationship name="departments" primaryKeyTable="COMPANY" foreignKeyTable="DEPARTMENT" many="true"> + <KeyPair primaryKeyColumn="ID" foreignKeyColumn="COMPANYID"/> + </Relationship> + + <Relationship name="employees" primaryKeyTable="DEPARTMENT" foreignKeyTable="EMPLOYEE" many="true"> + <KeyPair primaryKeyColumn="ID" foreignKeyColumn="DEPARTMENTID"/> + </Relationship> + +</Config> diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/customer.ecore b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/customer.ecore new file mode 100644 index 0000000000..74786d8af4 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/customer.ecore @@ -0,0 +1,96 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<ecore:EPackage xmi:version="2.0"
+ xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="customer"
+ nsURI="http:///org.apache.tuscany.das.rdb.test/customer.xsd" nsPrefix="customer">
+ <eClassifiers xsi:type="ecore:EClass" name="AnOrder">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="name" value="AnOrder"/>
+ <details key="kind" value="elementOnly"/>
+ </eAnnotations>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="iD" unique="false" lowerBound="1"
+ eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//Int" unsettable="true">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="kind" value="element"/>
+ <details key="name" value="ID"/>
+ </eAnnotations>
+ </eStructuralFeatures>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="product" unique="false"
+ lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//String">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="kind" value="element"/>
+ <details key="name" value="Product"/>
+ </eAnnotations>
+ </eStructuralFeatures>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="quantity" unique="false"
+ lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//Int"
+ unsettable="true">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="kind" value="element"/>
+ <details key="name" value="Quantity"/>
+ </eAnnotations>
+ </eStructuralFeatures>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="customerID" unique="false"
+ lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//Int"
+ unsettable="true">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="kind" value="element"/>
+ <details key="name" value="Customer_ID"/>
+ </eAnnotations>
+ </eStructuralFeatures>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EClass" name="Customer">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="name" value="Customer"/>
+ <details key="kind" value="elementOnly"/>
+ </eAnnotations>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="iD" unique="false" lowerBound="1"
+ eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//Int" unsettable="true">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="kind" value="element"/>
+ <details key="name" value="ID"/>
+ </eAnnotations>
+ </eStructuralFeatures>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="lastName" unique="false"
+ lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//String">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="kind" value="element"/>
+ <details key="name" value="lastName"/>
+ </eAnnotations>
+ </eStructuralFeatures>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="address" unique="false"
+ lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//String">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="kind" value="element"/>
+ <details key="name" value="address"/>
+ </eAnnotations>
+ </eStructuralFeatures>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="orders" lowerBound="1"
+ upperBound="-1" eType="#//AnOrder" containment="true" resolveProxies="false">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="kind" value="element"/>
+ <details key="name" value="orders"/>
+ </eAnnotations>
+ </eStructuralFeatures>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EClass" name="DataGraphRoot">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="name" value="DataGraphRoot"/>
+ <details key="kind" value="elementOnly"/>
+ </eAnnotations>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="customers" upperBound="-1"
+ eType="#//Customer" containment="true" resolveProxies="false">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="kind" value="element"/>
+ <details key="name" value="customers"/>
+ </eAnnotations>
+ </eStructuralFeatures>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="orders" upperBound="-1"
+ eType="#//AnOrder" containment="true" resolveProxies="false">
+ <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
+ <details key="kind" value="element"/>
+ <details key="name" value="orders"/>
+ </eAnnotations>
+ </eStructuralFeatures>
+ </eClassifiers>
+</ecore:EPackage>
diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/customer.genmodel b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/customer.genmodel new file mode 100644 index 0000000000..8c1cd53e57 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/customer.genmodel @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<genmodel:GenModel xmi:version="2.0"
+ xmlns:xmi="http://www.omg.org/XMI" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
+ xmlns:genmodel="http://www.eclipse.org/emf/2002/GenModel" modelDirectory="/rdbdas2/src"
+ modelPluginID="rdbdas2" modelName="Customer" rootExtendsInterface="" rootExtendsClass="org.eclipse.emf.ecore.sdo.impl.EDataObjectImpl"
+ rootImplementsInterface="org.eclipse.emf.ecore.sdo.InternalEDataObject" suppressEMFTypes="true"
+ suppressEMFMetaData="true" featureMapWrapperInterface="commonj.sdo.Sequence" featureMapWrapperInternalInterface="org.eclipse.emf.ecore.sdo.util.ESequence"
+ featureMapWrapperClass="org.eclipse.emf.ecore.sdo.util.BasicESequence" importerID="org.eclipse.xsd.ecore.importer">
+ <foreignModel>customer.xsd</foreignModel>
+ <staticPackages>http://www.eclipse.org/emf/2003/SDO</staticPackages>
+ <modelPluginVariables>EMF_COMMONJ_SDO=org.eclipse.emf.commonj.sdo</modelPluginVariables>
+ <modelPluginVariables>EMF_ECORE_SDO=org.eclipse.emf.ecore.sdo</modelPluginVariables>
+ <genPackages prefix="Customer" basePackage="org.apache.tuscany.das.rdb.test" resource="XML"
+ disposableProviderFactory="true" ecorePackage="customer.ecore#/">
+ <genClasses ecoreClass="customer.ecore#//AnOrder">
+ <genFeatures createChild="false" ecoreFeature="ecore:EAttribute customer.ecore#//AnOrder/iD"/>
+ <genFeatures createChild="false" ecoreFeature="ecore:EAttribute customer.ecore#//AnOrder/product"/>
+ <genFeatures createChild="false" ecoreFeature="ecore:EAttribute customer.ecore#//AnOrder/quantity"/>
+ <genFeatures createChild="false" ecoreFeature="ecore:EAttribute customer.ecore#//AnOrder/customerID"/>
+ </genClasses>
+ <genClasses ecoreClass="customer.ecore#//Customer">
+ <genFeatures createChild="false" ecoreFeature="ecore:EAttribute customer.ecore#//Customer/iD"/>
+ <genFeatures createChild="false" ecoreFeature="ecore:EAttribute customer.ecore#//Customer/lastName"/>
+ <genFeatures createChild="false" ecoreFeature="ecore:EAttribute customer.ecore#//Customer/address"/>
+ <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference customer.ecore#//Customer/orders"/>
+ </genClasses>
+ <genClasses ecoreClass="customer.ecore#//DataGraphRoot">
+ <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference customer.ecore#//DataGraphRoot/customers"/>
+ <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference customer.ecore#//DataGraphRoot/orders"/>
+ </genClasses>
+ </genPackages>
+</genmodel:GenModel>
diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/customer.xsd b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/customer.xsd new file mode 100644 index 0000000000..18a87aa299 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/customer.xsd @@ -0,0 +1,40 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. + --> +<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:this="http:///org.apache.tuscany.das.rdb.test/customer.xsd" targetNamespace="http:///org.apache.tuscany.das.rdb.test/customer.xsd"> + + <xsd:complexType name="Customer"> + <xsd:sequence> + <xsd:element name="ID" nillable="false" type="xsd:int"/> + <xsd:element name="lastName" type="xsd:string"/> + <xsd:element name="address" type="xsd:string"/> + <xsd:element maxOccurs="unbounded" name="orders" type="this:AnOrder"/> + </xsd:sequence> + </xsd:complexType> + + + <!-- An Order --> + <xsd:complexType name="AnOrder"> + <xsd:sequence> + <xsd:element name="ID" nillable="false" type="xsd:int"/> + <xsd:element name="Product" type="xsd:string"/> + <xsd:element name="Quantity" type="xsd:int"/> + <xsd:element name="Customer_ID" type="xsd:int"/> + </xsd:sequence> + </xsd:complexType> + + +</xsd:schema> diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/customerMapping.xml b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/customerMapping.xml new file mode 100644 index 0000000000..93c278dbe1 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/customerMapping.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="ASCII"?> +<!-- + 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. + --> +<Config xsi:noNamespaceSchemaLocation="http:///org.apache.tuscany.das.rdb/config.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + + <Table tableName="CUSTOMER" typeName="Customer"> + <Column columnName="ID" propertyName="id" primaryKey="true"/> + <Column columnName="LASTNAME" propertyName="lastname"/> + <Column columnName="ADDRESS" propertyName="address"/> + </Table> + +</Config> diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/customerOrderRelationshipMapping.xml b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/customerOrderRelationshipMapping.xml new file mode 100644 index 0000000000..a32d50dcd0 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/customerOrderRelationshipMapping.xml @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="ASCII"?> +<!-- + 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. + --> +<Config xsi:noNamespaceSchemaLocation="http:///org.apache.tuscany.das.rdb/config.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + + <Table tableName="CUSTOMER"> + <Column columnName="ID" primaryKey="true"/> + </Table> + <Table tableName="ANORDER"> + <Column columnName="ID" primaryKey="true"/> + </Table> + + <Relationship name="orders" primaryKeyTable="CUSTOMER" foreignKeyTable="ANORDER" many="true"> + <KeyPair primaryKeyColumn="ID" foreignKeyColumn="CUSTOMER_ID"/> + </Relationship> + +</Config> + diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/passiveConnection.xml b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/passiveConnection.xml new file mode 100644 index 0000000000..d6a7d83885 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/passiveConnection.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="ASCII"?> +<!-- + 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. + --> +<Config xsi:noNamespaceSchemaLocation="http:///org.apache.tuscany.das.rdb/config.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + + <ConnectionInfo managedtx="false"/> + + <Command name="get a customer" SQL="Select * from CUSTOMER where ID = 1" kind="select"/> + +</Config> diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/staticCustomer.xml b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/staticCustomer.xml new file mode 100644 index 0000000000..78f2409022 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/staticCustomer.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="ASCII"?> +<!-- + 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. + --> +<Config xsi:noNamespaceSchemaLocation="http:///org.apache.tuscany.das.rdb/config.xsd" +xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" +dataObjectModel="http:///org.apache.tuscany.das.rdb.test/customer.xsd"> + + +</Config> diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/staticCustomerOrder.xml b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/staticCustomerOrder.xml new file mode 100644 index 0000000000..13e0ae350f --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/staticCustomerOrder.xml @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="ASCII"?> +<!-- + 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. + --> +<Config xsi:noNamespaceSchemaLocation="http:///org.apache.tuscany.das.rdb/config.xsd" +xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" +dataObjectModel="http:///org.apache.tuscany.das.rdb.test/customer.xsd"> + + <Command name="Customer and Orders" SQL="SELECT * FROM CUSTOMER LEFT JOIN ANORDER ON CUSTOMER.ID = ANORDER.CUSTOMER_ID where CUSTOMER.ID = ?" kind="Select"/> + + <Table tableName="CUSTOMER" typeName="Customer"> + <Column columnName="ID" primaryKey="true"/> + </Table> + <Table tableName="ANORDER" typeName="AnOrder"> + <Column columnName="ID" primaryKey="true"/> + <Column columnName="CUSTOMER_ID"/> + </Table> + + <Relationship name="orders" primaryKeyTable="CUSTOMER" foreignKeyTable="ANORDER" many="true"> + <KeyPair primaryKeyColumn="ID" foreignKeyColumn="CUSTOMER_ID"/> + </Relationship> + +</Config> diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/staticInvalid.xml b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/staticInvalid.xml new file mode 100644 index 0000000000..d0571b8a14 --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/staticInvalid.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="ASCII"?> +<!-- + 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. + --> +<Config xsi:noNamespaceSchemaLocation="http:///org.apache.tuscany.das.rdb/config.xsd" +xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" +dataObjectModel="invalidURI"> + + +</Config> diff --git a/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/storedProcTest.xml b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/storedProcTest.xml new file mode 100644 index 0000000000..1412aedf7f --- /dev/null +++ b/sca-java-1.x/branches/java-post-M1/das/rdb/src/test/resources/storedProcTest.xml @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="ASCII"?> +<!-- + 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. + --> + +<Config xsi:noNamespaceSchemaLocation="http:///org.apache.tuscany.das.rdb/config.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <Command name="getNamedCustomers" SQL="{call GETNAMEDCUSTOMERS(?,?)}" kind="procedure"> + <Parameter name="name" direction="IN" columnType="commonj.sdo.String"/> + <Parameter name="number" direction="OUT" columnType="commonj.sdo.IntObject"/> + </Command> + +</Config> |