From bdd0a41aed7edf21ec2a65cfa17a86af2ef8c48a Mon Sep 17 00:00:00 2001 From: dims Date: Tue, 17 Jun 2008 00:23:01 +0000 Subject: Move Tuscany from Incubator to top level. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@668359 13f79535-47bb-0310-9956-ffa450edef68 --- .../modules/implementation-data-xml/LICENSE | 205 ++++++++ .../modules/implementation-data-xml/NOTICE | 6 + .../modules/implementation-data-xml/README | 78 +++ .../modules/implementation-data-xml/build.xml | 51 ++ .../modules/implementation-data-xml/company.sql | 28 + .../modules/implementation-data-xml/pom.xml | 209 ++++++++ .../tuscany/sca/implementation/data/DATA.java | 64 +++ .../sca/implementation/data/DATACollection.java | 28 + .../implementation/data/DATAImplementation.java | 161 ++++++ .../data/DATAImplementationFactory.java | 44 ++ .../data/DATAImplementationProcessor.java | 132 +++++ .../sca/implementation/data/jdbc/JDBCHelper.java | 215 ++++++++ .../data/jdbc/JDBCResultSetStreamReader.java | 53 ++ .../data/jdbc/ResultSetXmlNodeImpl.java | 244 +++++++++ .../data/provider/DATAImplementationProvider.java | 98 ++++ .../DATAImplementationProviderFactory.java | 47 ++ .../implementation/data/provider/DATAInvoker.java | 583 +++++++++++++++++++++ ...ca.contribution.processor.StAXArtifactProcessor | 19 + ...cany.sca.provider.ImplementationProviderFactory | 19 + .../data/DATACollectionTestCaseFIXME.java | 118 +++++ .../data/DATAImplementationProcessorTestCase.java | 133 +++++ .../sca/implementation/data/DATATestCase.java | 133 +++++ .../data/companyFeed/CompanyFeed.java | 62 +++ .../data/companyFeed/CompanyFeedTestCaseFIXME.java | 51 ++ .../src/test/resources/data-feed.composite | 50 ++ .../src/test/resources/data.composite | 36 ++ .../src/test/resources/insert.xml | 9 + .../src/test/resources/update.xml | 7 + 28 files changed, 2883 insertions(+) create mode 100644 branches/sca-java-1.3/modules/implementation-data-xml/LICENSE create mode 100644 branches/sca-java-1.3/modules/implementation-data-xml/NOTICE create mode 100644 branches/sca-java-1.3/modules/implementation-data-xml/README create mode 100644 branches/sca-java-1.3/modules/implementation-data-xml/build.xml create mode 100644 branches/sca-java-1.3/modules/implementation-data-xml/company.sql create mode 100644 branches/sca-java-1.3/modules/implementation-data-xml/pom.xml create mode 100644 branches/sca-java-1.3/modules/implementation-data-xml/src/main/java/org/apache/tuscany/sca/implementation/data/DATA.java create mode 100644 branches/sca-java-1.3/modules/implementation-data-xml/src/main/java/org/apache/tuscany/sca/implementation/data/DATACollection.java create mode 100644 branches/sca-java-1.3/modules/implementation-data-xml/src/main/java/org/apache/tuscany/sca/implementation/data/DATAImplementation.java create mode 100644 branches/sca-java-1.3/modules/implementation-data-xml/src/main/java/org/apache/tuscany/sca/implementation/data/DATAImplementationFactory.java create mode 100644 branches/sca-java-1.3/modules/implementation-data-xml/src/main/java/org/apache/tuscany/sca/implementation/data/DATAImplementationProcessor.java create mode 100644 branches/sca-java-1.3/modules/implementation-data-xml/src/main/java/org/apache/tuscany/sca/implementation/data/jdbc/JDBCHelper.java create mode 100644 branches/sca-java-1.3/modules/implementation-data-xml/src/main/java/org/apache/tuscany/sca/implementation/data/jdbc/JDBCResultSetStreamReader.java create mode 100644 branches/sca-java-1.3/modules/implementation-data-xml/src/main/java/org/apache/tuscany/sca/implementation/data/jdbc/ResultSetXmlNodeImpl.java create mode 100644 branches/sca-java-1.3/modules/implementation-data-xml/src/main/java/org/apache/tuscany/sca/implementation/data/provider/DATAImplementationProvider.java create mode 100644 branches/sca-java-1.3/modules/implementation-data-xml/src/main/java/org/apache/tuscany/sca/implementation/data/provider/DATAImplementationProviderFactory.java create mode 100644 branches/sca-java-1.3/modules/implementation-data-xml/src/main/java/org/apache/tuscany/sca/implementation/data/provider/DATAInvoker.java create mode 100644 branches/sca-java-1.3/modules/implementation-data-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 branches/sca-java-1.3/modules/implementation-data-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory create mode 100644 branches/sca-java-1.3/modules/implementation-data-xml/src/test/java/org/apache/tuscany/sca/implementation/data/DATACollectionTestCaseFIXME.java create mode 100644 branches/sca-java-1.3/modules/implementation-data-xml/src/test/java/org/apache/tuscany/sca/implementation/data/DATAImplementationProcessorTestCase.java create mode 100644 branches/sca-java-1.3/modules/implementation-data-xml/src/test/java/org/apache/tuscany/sca/implementation/data/DATATestCase.java create mode 100644 branches/sca-java-1.3/modules/implementation-data-xml/src/test/java/org/apache/tuscany/sca/implementation/data/companyFeed/CompanyFeed.java create mode 100644 branches/sca-java-1.3/modules/implementation-data-xml/src/test/java/org/apache/tuscany/sca/implementation/data/companyFeed/CompanyFeedTestCaseFIXME.java create mode 100644 branches/sca-java-1.3/modules/implementation-data-xml/src/test/resources/data-feed.composite create mode 100644 branches/sca-java-1.3/modules/implementation-data-xml/src/test/resources/data.composite create mode 100644 branches/sca-java-1.3/modules/implementation-data-xml/src/test/resources/insert.xml create mode 100644 branches/sca-java-1.3/modules/implementation-data-xml/src/test/resources/update.xml (limited to 'branches/sca-java-1.3/modules/implementation-data-xml') diff --git a/branches/sca-java-1.3/modules/implementation-data-xml/LICENSE b/branches/sca-java-1.3/modules/implementation-data-xml/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/branches/sca-java-1.3/modules/implementation-data-xml/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. + + + diff --git a/branches/sca-java-1.3/modules/implementation-data-xml/NOTICE b/branches/sca-java-1.3/modules/implementation-data-xml/NOTICE new file mode 100644 index 0000000000..fdfa0e9faa --- /dev/null +++ b/branches/sca-java-1.3/modules/implementation-data-xml/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2008 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/branches/sca-java-1.3/modules/implementation-data-xml/README b/branches/sca-java-1.3/modules/implementation-data-xml/README new file mode 100644 index 0000000000..763daafe46 --- /dev/null +++ b/branches/sca-java-1.3/modules/implementation-data-xml/README @@ -0,0 +1,78 @@ +Implementation CRUD Sample +========================== +This sample demonstrates how new implementation types are constructed for +Apache Tuscany SCA. + +The README in the samples directory (the directory above this) provides +general instructions about building and running samples. Take a look there +first. + +If you want to try out the crud implementation type that this sample provides +please see the implementation-crud-client sample that provides the necessary +client code to bring up an application that uses this implementation-crud + +Sample Overview +--------------- +This sample contains a CRUD implementation type as an example of how to create +new implementation types. Components using this implementation type always +expose the same Create, Retrieve, Update and Delete interface. This sample +uses a singleton ResourceManager to perform the CRUD operations but of course +a real component would provide a real implementation. + +implementation-crud/ + src/ + main/ + java/ + crud/ - implementation model interfaces + crud.backend/ - fake component implementation + crud.impl/ - implementations of the model interfaces + crud.module/ - gets the implementation-crud module registered + with the SCA runtime + crud.provider/ - runtime implementation + resources/ + crud.composite - the SCA assembly used during unit testing + + build.xml - the Ant build file + pom.xml - the Maven build file + +Building The Sample Extension Using Ant +----------------------------------------- +With the binary distribution the sample extension can be built using Ant as +follows + +cd implementation-crud +ant compile + +See the sample implementation-crud-client to run a sample that uses this +binding. + +Building The Sample Using Maven +------------------------------------------- +With either the binary or source distributions the sample can be built +using Maven as follows. + +cd implementation-crud +mvn + +Maven will also test that the sample extension built properly. You should see +the following output from the test phase. + +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running crud.CRUDTestCase +Starting CRUDServiceComponent +create(ABC) in tmp +retrieve(0) +update(0) +retrieve(0) +delete(0) +retrieve(0) +Stopping CRUDServiceComponent +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.212 sec + +Results : + +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 + +This shows that the Junit test cases have run successfully. diff --git a/branches/sca-java-1.3/modules/implementation-data-xml/build.xml b/branches/sca-java-1.3/modules/implementation-data-xml/build.xml new file mode 100644 index 0000000000..ab0d93beb0 --- /dev/null +++ b/branches/sca-java-1.3/modules/implementation-data-xml/build.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/branches/sca-java-1.3/modules/implementation-data-xml/company.sql b/branches/sca-java-1.3/modules/implementation-data-xml/company.sql new file mode 100644 index 0000000000..4911f9e62f --- /dev/null +++ b/branches/sca-java-1.3/modules/implementation-data-xml/company.sql @@ -0,0 +1,28 @@ +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, +-- software distributed under the License is distributed on an +-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +-- KIND, either express or implied. See the License for the +-- specific language governing permissions and limitations +-- under the License. +-- + +DROP TABLE COMPANY; + +CREATE TABLE COMPANY ( + ID INT PRIMARY KEY NOT NULL GENERATED ALWAYS AS IDENTITY, + NAME VARCHAR(30)); + +INSERT INTO COMPANY (NAME) VALUES('ACME Publishing'); +INSERT INTO COMPANY (NAME) VALUES('Do-rite plumbing'); +INSERT INTO COMPANY (NAME) VALUES('MegaCorp'); \ No newline at end of file diff --git a/branches/sca-java-1.3/modules/implementation-data-xml/pom.xml b/branches/sca-java-1.3/modules/implementation-data-xml/pom.xml new file mode 100644 index 0000000000..b85e5143aa --- /dev/null +++ b/branches/sca-java-1.3/modules/implementation-data-xml/pom.xml @@ -0,0 +1,209 @@ + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.3-SNAPSHOT + ../pom.xml + + tuscany-implementation-data-xml + Apache Tuscany SCA Data Implementation Extension + + + + apache.incubator + http://people.apache.org/repo/m2-incubating-repository + + + + + + org.apache.tuscany.das + tuscany-das-rdb + 1.0-incubating-SNAPSHOT + compile + + + org.apache.tuscany.sca + tuscany-assembly + 1.3-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-core + 1.3-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-interface + 1.3-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-assembly-xml + 1.3-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-contribution-impl + 1.3-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-sca-api + 1.3-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-databinding + 1.3-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 1.3-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-host-embedded + 1.3-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-data-engine-helper + 1.3-SNAPSHOT + compile + + + org.apache.tuscany.sca + tuscany-binding-atom-abdera + 1.3-SNAPSHOT + runtime + + + org.apache.derby + derby + 10.3.1.4 + runtime + + + org.apache.tuscany.sca + tuscany-host-jetty + 1.3-SNAPSHOT + test + + + javax.servlet + servlet-api + 2.5 + test + + + junit + junit + 4.2 + compile + + + org.easymock + easymock + 2.2 + test + + + org.apache.tuscany.sca + tuscany-data-api + 1.3-SNAPSHOT + compile + + + + + ${artifactId} + + + + org.codehaus.mojo + sql-maven-plugin + + 1.1-SNAPSHOT + + + + org.apache.derby + derby + 10.1.2.1 + + + + + + create-db + generate-resources + + execute + + + org.apache.derby.jdbc.EmbeddedDriver + jdbc:derby:${pom.basedir}/target/test-classes/company;create=true + true + continue + skip + ; + + ${pom.basedir}/company.sql + + + + + + + shutdown-database-sothat-test-can-run + process-test-resources + + execute + + + org.apache.derby.jdbc.EmbeddedDriver + jdbc:derby:${pom.basedir}/target/test-classes/company;shutdown=true + true + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.implementation.data.xml + ${pom.name} + org.apache.tuscany.sca.implementation.data* + + + + + + + diff --git a/branches/sca-java-1.3/modules/implementation-data-xml/src/main/java/org/apache/tuscany/sca/implementation/data/DATA.java b/branches/sca-java-1.3/modules/implementation-data-xml/src/main/java/org/apache/tuscany/sca/implementation/data/DATA.java new file mode 100644 index 0000000000..3ce96e58da --- /dev/null +++ b/branches/sca-java-1.3/modules/implementation-data-xml/src/main/java/org/apache/tuscany/sca/implementation/data/DATA.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.implementation.data; + +import javax.xml.stream.XMLStreamReader; + +/** + * The service interface of a DAS service provided by DAS components. + * + * @version $Rev$ $Date$ + */ +public interface DATA { + + /** + * Retrieve the Database table contents If a id is given, the results will + * be filtered to a matching row + * + * @param id The PK that identifies the row on the table + * @return The row content in XML format + */ + XMLStreamReader get(String id); + + /** + * Insert new content in the Database + * + * @param insertStream The insertion in XML format + * @return The number of rows affected + */ + int insert(XMLStreamReader insertStream); + + /** + * Update the Database table contents + * + * @param updateStream The updates in XML format + * @return The number of rows affected + */ + int update(XMLStreamReader updateStream); + + /** + * Delete the Database table contents If a id is given, only a specific row + * will be deleted + * + * @param id The PK that identifies the row on the table + * @return The number of rows affected + */ + int delete(String id); + +} diff --git a/branches/sca-java-1.3/modules/implementation-data-xml/src/main/java/org/apache/tuscany/sca/implementation/data/DATACollection.java b/branches/sca-java-1.3/modules/implementation-data-xml/src/main/java/org/apache/tuscany/sca/implementation/data/DATACollection.java new file mode 100644 index 0000000000..1dc5673fe5 --- /dev/null +++ b/branches/sca-java-1.3/modules/implementation-data-xml/src/main/java/org/apache/tuscany/sca/implementation/data/DATACollection.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.implementation.data; + +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.data.collection.Collection; + +public interface DATACollection extends Collection { + +} diff --git a/branches/sca-java-1.3/modules/implementation-data-xml/src/main/java/org/apache/tuscany/sca/implementation/data/DATAImplementation.java b/branches/sca-java-1.3/modules/implementation-data-xml/src/main/java/org/apache/tuscany/sca/implementation/data/DATAImplementation.java new file mode 100644 index 0000000000..a50ad89b64 --- /dev/null +++ b/branches/sca-java-1.3/modules/implementation-data-xml/src/main/java/org/apache/tuscany/sca/implementation/data/DATAImplementation.java @@ -0,0 +1,161 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.implementation.data; + +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.assembly.Property; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.data.engine.config.ConnectionInfo; +import org.apache.tuscany.sca.implementation.data.jdbc.JDBCHelper; +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; + + +/** + * The model representing a sample DATA implementation in an SCA assembly model. + * + * @version $Rev$ $Date$ + */ +public class DATAImplementation implements Implementation { + private AssemblyFactory assemblyFactory; + private JavaInterfaceFactory javaFactory; + + private ConnectionInfo connectionInfo; + private List services = new ArrayList(); + + /** + * Constructs a new DAS implementation. + */ + public DATAImplementation(AssemblyFactory assemblyFactory, + JavaInterfaceFactory javaFactory) { + + // DATA implementation provides one service per database table + // exposing the DATA interface, and have no references and properties + this.assemblyFactory = assemblyFactory; + this.javaFactory = javaFactory; + } + + private void introspectServices( AssemblyFactory assemblyFactory, JavaInterfaceFactory javaFactory) { + Connection connection = null; + try { + connection = JDBCHelper.getConnection(connectionInfo); + DatabaseMetaData databaseMetaData = connection.getMetaData(); + ResultSet tables = databaseMetaData.getTables(null, null, "%", null); + while(tables.next()) { + //create the SCA service for the table + Service dataService = assemblyFactory.createService(); + Service dataCollectionService = assemblyFactory.createService(); + + dataService.setName(tables.getString(3)+"_DATA"); + dataCollectionService.setName(tables.getString(3)); + + JavaInterface dataInterface; + JavaInterface dataCollectionInterface; + + try { + dataInterface = javaFactory.createJavaInterface(DATA.class); + dataCollectionInterface = javaFactory.createJavaInterface(DATACollection.class); + } catch (InvalidInterfaceException e) { + throw new IllegalArgumentException(e); + } + JavaInterfaceContract dataInterfaceContract = javaFactory.createJavaInterfaceContract(); + JavaInterfaceContract dataCollectionInterfaceContract = javaFactory.createJavaInterfaceContract(); + + dataInterfaceContract.setInterface(dataInterface); + dataCollectionInterfaceContract.setInterface(dataCollectionInterface); + + dataService.setInterfaceContract(dataInterfaceContract); + dataCollectionService.setInterfaceContract(dataCollectionInterfaceContract); + + services.add(dataService); + services.add(dataCollectionService); + + } + } catch(SQLException e) { + + } finally { + JDBCHelper.cleanupResources(connection, null, null); + } + } + + public ConnectionInfo getConnectionInfo() { + return this.connectionInfo; + } + + public void setConnectionInfo(ConnectionInfo connectionInfo) { + this.connectionInfo = connectionInfo; + } + + public ConstrainingType getConstrainingType() { + // The sample DATA implementation does not support constrainingTypes + return null; + } + + public List getProperties() { + // The sample DATA implementation does not support properties + return Collections.emptyList(); + } + + public List getServices() { + if(services == null || services.size() == 0) { + introspectServices(assemblyFactory, javaFactory); + } + return services; + } + + public List getReferences() { + // The sample DATA implementation does not support references + return Collections.emptyList(); + } + + public String getURI() { + // The sample DATA implementation does not have a URI + return null; + } + + public void setConstrainingType(ConstrainingType constrainingType) { + // The sample DATA implementation does not support constrainingTypes + } + + public void setURI(String uri) { + // The sample DATA implementation does not have a URI + } + + public boolean isUnresolved() { + // The sample DATA implementation is always resolved + return false; + } + + public void setUnresolved(boolean unresolved) { + // The sample DATA implementation is always resolved + } +} diff --git a/branches/sca-java-1.3/modules/implementation-data-xml/src/main/java/org/apache/tuscany/sca/implementation/data/DATAImplementationFactory.java b/branches/sca-java-1.3/modules/implementation-data-xml/src/main/java/org/apache/tuscany/sca/implementation/data/DATAImplementationFactory.java new file mode 100644 index 0000000000..d4cf816dbf --- /dev/null +++ b/branches/sca-java-1.3/modules/implementation-data-xml/src/main/java/org/apache/tuscany/sca/implementation/data/DATAImplementationFactory.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.implementation.data; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; + +/** + * A default factory for the DATA implementation model. + * + * @version $Rev$ $Date$ + */ +public class DATAImplementationFactory { + + private AssemblyFactory assemblyFactory; + private JavaInterfaceFactory javaFactory; + + public DATAImplementationFactory(AssemblyFactory assemblyFactory, JavaInterfaceFactory javaFactory) { + this.assemblyFactory = assemblyFactory; + this.javaFactory = javaFactory; + } + + public DATAImplementation createDASImplementation() { + return new DATAImplementation(assemblyFactory, javaFactory); + } + +} diff --git a/branches/sca-java-1.3/modules/implementation-data-xml/src/main/java/org/apache/tuscany/sca/implementation/data/DATAImplementationProcessor.java b/branches/sca-java-1.3/modules/implementation-data-xml/src/main/java/org/apache/tuscany/sca/implementation/data/DATAImplementationProcessor.java new file mode 100644 index 0000000000..16c5a370ec --- /dev/null +++ b/branches/sca-java-1.3/modules/implementation-data-xml/src/main/java/org/apache/tuscany/sca/implementation/data/DATAImplementationProcessor.java @@ -0,0 +1,132 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.implementation.data; + +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.data.engine.ConnectionInfoArtifactProcessor; +import org.apache.tuscany.sca.data.engine.config.ConnectionInfo; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; +import org.apache.tuscany.sca.monitor.Monitor; + + +/** + * Implements a StAX artifact processor for DATA implementations. + * + * The artifact processor is responsible for processing + * elements in SCA assembly XML composite files and populating the DATA + * implementation model, resolving its references to other artifacts in the SCA + * contribution, and optionally write the model back to SCA assembly XML. + * + * @version $Rev$ $Date$ + */ +public class DATAImplementationProcessor implements StAXArtifactProcessor { + protected static final QName IMPLEMENTATION_DATA_XML = new QName(Constants.SCA10_TUSCANY_NS, "implementation.data.xml"); + + private DATAImplementationFactory dataFactory; + private Monitor monitor; + private StAXArtifactProcessor connectionInfoProcessor; + + public DATAImplementationProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) { + AssemblyFactory assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); + JavaInterfaceFactory javaFactory = modelFactories.getFactory(JavaInterfaceFactory.class); + this.monitor = monitor; + this.dataFactory = new DATAImplementationFactory(assemblyFactory, javaFactory); + this.connectionInfoProcessor = new ConnectionInfoArtifactProcessor(modelFactories, this.monitor); + } + + public QName getArtifactType() { + // Returns the qname of the XML element processed by this processor + return IMPLEMENTATION_DATA_XML; + } + + public Class getModelType() { + // Returns the type of model processed by this processor + return DATAImplementation.class; + } + + /* + * + * + * + * + * + * + * + */ + public DATAImplementation read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + assert IMPLEMENTATION_DATA_XML.equals(reader.getName()); + + // Read an element + + // Create an initialize the DAS implementation model + DATAImplementation implementation = dataFactory.createDASImplementation(); + + while (true) { + int event = reader.next(); + switch (event) { + + case START_ELEMENT: + if (ConnectionInfoArtifactProcessor.CONNECTION_INFO.equals(reader.getName())) { + + // Read connection info + ConnectionInfo connectionInfo = (ConnectionInfo) connectionInfoProcessor.read(reader); + implementation.setConnectionInfo(connectionInfo); + } + break; + case XMLStreamConstants.END_ELEMENT: + if (IMPLEMENTATION_DATA_XML.equals(reader.getName())) { + return implementation; + } + break; + } + } + + } + + public void resolve(DATAImplementation impl, ModelResolver resolver) throws ContributionResolveException { + } + + public void write(DATAImplementation implementation, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + writer.writeStartElement(IMPLEMENTATION_DATA_XML.getNamespaceURI(), IMPLEMENTATION_DATA_XML.getLocalPart()); + + if (implementation.getConnectionInfo() != null) { + connectionInfoProcessor.write(implementation.getConnectionInfo(), writer); + } + + writer.writeEndElement(); + } +} diff --git a/branches/sca-java-1.3/modules/implementation-data-xml/src/main/java/org/apache/tuscany/sca/implementation/data/jdbc/JDBCHelper.java b/branches/sca-java-1.3/modules/implementation-data-xml/src/main/java/org/apache/tuscany/sca/implementation/data/jdbc/JDBCHelper.java new file mode 100644 index 0000000000..265f250717 --- /dev/null +++ b/branches/sca-java-1.3/modules/implementation-data-xml/src/main/java/org/apache/tuscany/sca/implementation/data/jdbc/JDBCHelper.java @@ -0,0 +1,215 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.implementation.data.jdbc; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Properties; + +import javax.naming.InitialContext; +import javax.naming.NamingException; +import javax.sql.DataSource; + +import org.apache.tuscany.das.rdb.exception.DataSourceInitializationException; +import org.apache.tuscany.sca.data.engine.config.ConnectionInfo; + +/** + * JDBC Helper + * - JDBC Connection utility methods + * - JDBC Resource cleanup methods + * + * @version $Rev$ $Date$ + */ +public class JDBCHelper { + + /** + * protected constructor + */ + protected JDBCHelper() { + + } + + /** + * + * @param connectionInfo + * @return + */ + public static Connection getConnection(ConnectionInfo connectionInfo) { + if (connectionInfo.getDataSource() == null && connectionInfo.getConnectionProperties() == null) { + throw new IllegalArgumentException("Not enough information to create Database Connection."); + } + + if(connectionInfo.getDataSource() != null && connectionInfo.getConnectionProperties() != null) { + throw new IllegalArgumentException("Use either dataSource or ConnectionProperties. Can't use both !"); + } + + if(connectionInfo.getDataSource() != null) { + return getDataSourceConnection(connectionInfo); + } else { + return getDriverManagerConnection(connectionInfo); + } + } + + /** + * Initializes a DB connection on a managed environment (e.g inside Tomcat) + * + * @param connectionInfo + * @return + */ + private static Connection getDataSourceConnection(ConnectionInfo connectionInfo) { + Connection connection = null; + + InitialContext ctx; + try { + ctx = new InitialContext(); + } catch (NamingException e) { + throw new RuntimeException(e); + } + try { + DataSource ds = (DataSource) ctx.lookup(connectionInfo.getDataSource()); + try { + connection = ds.getConnection(); + if (connection == null) { + throw new RuntimeException("Could not obtain a Connection from DataSource"); + } + connection.setAutoCommit(false); + } catch (SQLException e) { + throw new RuntimeException(e); + } + } catch (NamingException e) { + throw new RuntimeException(e); + } + + return connection; + } + + /** + * Initialize a DB connection on a J2SE environment + * For more info, see http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/drivermanager.html + * + * @param connectionInfo + * @return + */ + private static Connection getDriverManagerConnection(ConnectionInfo connectionInfo) { + Connection connection = null; + + if (connectionInfo.getConnectionProperties() == null) { + throw new RuntimeException("No existing context and no connection properties"); + } + + if (connectionInfo.getConnectionProperties().getDriverClass() == null) { + throw new RuntimeException("No jdbc driver class specified!"); + } + + try { + Properties p = System.getProperties(); + p.put("derby.system.home", "target"); + + //initialize driver and register it with DriverManager + Class.forName(connectionInfo.getConnectionProperties().getDriverClass()); + + //prepare to initialize connection + String databaseUrl = connectionInfo.getConnectionProperties().getDatabaseURL(); + String userName = connectionInfo.getConnectionProperties().getUsername(); + String userPassword = connectionInfo.getConnectionProperties().getPassword(); + int loginTimeout = connectionInfo.getConnectionProperties().getLoginTimeout(); + + DriverManager.setLoginTimeout(loginTimeout); + if( (userName == null || userName.length() ==0) && (userPassword == null || userPassword.length()==0) ){ + //no username or password supplied + connection = DriverManager.getConnection(databaseUrl); + }else{ + connection = DriverManager.getConnection(databaseUrl, userName, userPassword); + } + + if(connection == null){ + throw new DataSourceInitializationException("Error initializing connection : null"); + } + + //FIXME we should make this flexible, we can't autocommit when participating in transactions + connection.setAutoCommit(true); + + }catch(ClassNotFoundException cnf){ + throw new DataSourceInitializationException("JDBC Driver '" + connectionInfo.getConnectionProperties().getDriverClass() + "' not found", cnf); + }catch(SQLException sqle){ + throw new DataSourceInitializationException(sqle.getMessage(), sqle); + } + + return connection; + } + + /** + * Cleanup and close all JDBC resources in the proper order and ignoring erros + * @param connection The connection to be closed + * @param queryStatement The statement to be closed + * @param resultSet The ResultSet to be closed + */ + public static void cleanupResources(Connection connection, PreparedStatement queryStatement, ResultSet resultSet) { + cleanupResultSet(resultSet); + cleanupPreparedStatement(queryStatement); + cleanupConnection(connection); + } + + /** + * Proper cleanup the ResultSet + * @param resultSet + */ + private static void cleanupResultSet(ResultSet resultSet) { + if (resultSet != null) { + try { + resultSet.close(); + } catch (SQLException e) { + // We should log the error. Since we're trying to close, we don't re-throw. + } + } + } + + /** + * Proper cleanup the prepared statement + * @param queryStatement + */ + private static void cleanupPreparedStatement(PreparedStatement queryStatement) { + if (queryStatement != null) { + try { + queryStatement.close(); + } catch (SQLException e) { + // We should log the error. Since we're trying to close, we don't re-throw. + } + } + } + + /** + * proper cleanup the connection + * @param connection + */ + private static void cleanupConnection(Connection connection) { + if (connection != null) { + try { + connection.close(); + } catch (SQLException e) { + // We should log the error. Since we're trying to close, we don't re-throw. + } + } + } + +} diff --git a/branches/sca-java-1.3/modules/implementation-data-xml/src/main/java/org/apache/tuscany/sca/implementation/data/jdbc/JDBCResultSetStreamReader.java b/branches/sca-java-1.3/modules/implementation-data-xml/src/main/java/org/apache/tuscany/sca/implementation/data/jdbc/JDBCResultSetStreamReader.java new file mode 100644 index 0000000000..316330243b --- /dev/null +++ b/branches/sca-java-1.3/modules/implementation-data-xml/src/main/java/org/apache/tuscany/sca/implementation/data/jdbc/JDBCResultSetStreamReader.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.implementation.data.jdbc; + +import java.sql.ResultSet; +import java.sql.SQLException; + +import javax.xml.stream.XMLStreamException; + +import org.apache.tuscany.sca.databinding.xml.XmlTreeStreamReaderImpl; + +/** + * JDBCResultSetStreamReader perform streaming of database tables as XML + * + * @version $Rev$ $Date$ + */ +public class JDBCResultSetStreamReader extends XmlTreeStreamReaderImpl { + private ResultSet resultSet; + + /** + * @param root + */ + public JDBCResultSetStreamReader(ResultSet resultSet) { + super(new ResultSetXmlNodeImpl(resultSet)); + this.resultSet = resultSet; + } + + @Override + public void close() throws XMLStreamException { + try { + resultSet.close(); + } catch (SQLException e) { + } + } +} + diff --git a/branches/sca-java-1.3/modules/implementation-data-xml/src/main/java/org/apache/tuscany/sca/implementation/data/jdbc/ResultSetXmlNodeImpl.java b/branches/sca-java-1.3/modules/implementation-data-xml/src/main/java/org/apache/tuscany/sca/implementation/data/jdbc/ResultSetXmlNodeImpl.java new file mode 100644 index 0000000000..c826e27e20 --- /dev/null +++ b/branches/sca-java-1.3/modules/implementation-data-xml/src/main/java/org/apache/tuscany/sca/implementation/data/jdbc/ResultSetXmlNodeImpl.java @@ -0,0 +1,244 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.implementation.data.jdbc; + +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.util.Arrays; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.databinding.xml.SimpleXmlNodeImpl; +import org.apache.tuscany.sca.databinding.xml.XmlNode; + +/** + * @version $Rev$ $Date$ + */ +public class ResultSetXmlNodeImpl implements XmlNode { + private static final String NS = ""; + private static final QName RESULT_SET = new QName(NS, "resultSet"); + private static final QName RECORD = new QName(NS, "record"); + private static final QName COLUMN = new QName(NS, "column"); + private static final QName NAME = new QName(NS, "name"); + + private ResultSet resultSet; + private String[] columnNames; + + /** + * @param resultSet + */ + public ResultSetXmlNodeImpl(ResultSet resultSet) { + super(); + this.resultSet = resultSet; + try { + ResultSetMetaData metaData = resultSet.getMetaData(); + columnNames = new String[metaData.getColumnCount()]; + for (int i = 0; i < columnNames.length; i++) { + columnNames[i] = metaData.getColumnName(i + 1); + } + } catch (SQLException e) { + throw new IllegalStateException(e); + } + } + + /** + * @see org.apache.tuscany.sca.databinding.xml.XmlNode#attributes() + */ + public List attributes() { + return Collections.emptyList(); + } + + public Type getType() { + return Type.ELEMENT; + } + + + /** + * @see org.apache.tuscany.sca.databinding.xml.XmlNode#children() + */ + public Iterator children() { + return new ResultSetIteraror(); + } + + private class ResultSetIteraror implements Iterator { + private Boolean hasNext; + + public ResultSetIteraror() { + } + + public boolean hasNext() { + try { + if (hasNext == null) { + hasNext = resultSet.next(); + } + return hasNext; + } catch (SQLException e) { + throw new IllegalStateException(e); + } + } + + public XmlNode next() { + hasNext(); + hasNext = null; + return new RecordXmlNodeImpl(); + } + + public void remove() { + } + } + + /** + * @see org.apache.tuscany.sca.databinding.xml.XmlNode#getName() + */ + public QName getName() { + return RESULT_SET; + } + + /** + * @see org.apache.tuscany.sca.databinding.xml.XmlNode#getValue() + */ + public String getValue() { + return null; + } + + /** + * @see org.apache.tuscany.sca.databinding.xml.XmlNode#namespaces() + */ + public Map namespaces() { + return Collections.emptyMap(); + } + + private class RecordXmlNodeImpl extends XmlNodeImpl { + int index = 0; + + public Iterator children() { + return new Iterator() { + + public boolean hasNext() { + return index < columnNames.length; + } + + public XmlNode next() { + return new ColumnXmlNodeImpl(index++); + } + + public void remove() { + } + + }; + } + + public QName getName() { + return RECORD; + } + + } + + private class ColumnXmlNodeImpl extends XmlNodeImpl { + private int index; + + /** + * @param index + */ + public ColumnXmlNodeImpl(int index) { + super(); + this.index = index; + } + + public List attributes() { + XmlNode attr = new SimpleXmlNodeImpl(NAME, columnNames[index], XmlNode.Type.ATTRIBUTE); + return Arrays.asList(attr); + } + + public Iterator children() { + XmlNode[] nodes = {new ValueXmlNodeImpl(index)}; + return Arrays.asList(nodes).iterator(); + } + + public QName getName() { + return COLUMN; + } + + } + + private class ValueXmlNodeImpl extends XmlNodeImpl { + private int index; + + /** + * @param index + */ + public ValueXmlNodeImpl(int index) { + super(); + this.index = index; + } + + public String getValue() { + try { + return String.valueOf(resultSet.getObject(index + 1)); + } catch (SQLException e) { + throw new IllegalStateException(e); + } + } + + public Type getType() { + return Type.CHARACTERS; + } + + } + + private static abstract class XmlNodeImpl implements XmlNode { + + public List attributes() { + return Collections.emptyList(); + } + + public Iterator children() { + return null; + } + + public QName getName() { + return null; + } + + public String getValue() { + return null; + } + + public boolean isLeaf() { + return false; + } + + public Map namespaces() { + return Collections.emptyMap(); + } + + public Type getType() { + return Type.ELEMENT; + } + + } + + +} diff --git a/branches/sca-java-1.3/modules/implementation-data-xml/src/main/java/org/apache/tuscany/sca/implementation/data/provider/DATAImplementationProvider.java b/branches/sca-java-1.3/modules/implementation-data-xml/src/main/java/org/apache/tuscany/sca/implementation/data/provider/DATAImplementationProvider.java new file mode 100644 index 0000000000..bbd963922c --- /dev/null +++ b/branches/sca-java-1.3/modules/implementation-data-xml/src/main/java/org/apache/tuscany/sca/implementation/data/provider/DATAImplementationProvider.java @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.implementation.data.provider; + +import org.apache.tuscany.sca.implementation.data.DATAImplementation; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.ImplementationProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * DATA Implementation provider + * + * @version $Rev$ $Date$ + */ +public class DATAImplementationProvider implements ImplementationProvider { + //private RuntimeComponent component; + private DATAImplementation implementation; + + /** + * Constructs a new DATA implementation. + */ + public DATAImplementationProvider(RuntimeComponent component, DATAImplementation implementation) { + //this.component = component; + this.implementation = implementation; + } + + public Invoker createInvoker(RuntimeComponentService service, Operation operation) { + String operationName = operation.getName(); + String tableName = service.getName(); + + String interfaceFullName = operation.getInterface().toString(); + int index = interfaceFullName.lastIndexOf(".") + 1; + String interfaceName = interfaceFullName.substring(index, interfaceFullName.length()); + + if (interfaceName.equals("DATACollection")) { + + if (operationName.equals("getAll")) { + return new DATAInvoker.GetAllInvoker(operation, implementation.getConnectionInfo(), tableName); + } else if (operationName.equals("query")) { + return new DATAInvoker.QueryInvoker(operation, implementation.getConnectionInfo(), tableName); + } else if (operationName.equals("post")) { + return new DATAInvoker.PostInvoker(operation, implementation.getConnectionInfo(), tableName); + } else if (operationName.equals("get")) { + return new DATAInvoker.GetInvoker(operation, implementation.getConnectionInfo(), tableName); + } else if (operationName.equals("put")) { + return new DATAInvoker.PutInvoker(operation, implementation.getConnectionInfo(), tableName); + } else if (operationName.equals("delete")) { + return new DATAInvoker.DeleteInvoker(operation, implementation.getConnectionInfo(), tableName); + } + + } else if (interfaceName.equals("DATA")) { + + tableName = tableName.split("_")[0]; + + if (operationName.equals("get")) { + return new DATAInvoker.GetDATAInvoker(operation, implementation.getConnectionInfo(), tableName); + } else if (operationName.equals("insert")) { + return new DATAInvoker.InsertDATAInvoker(operation, implementation.getConnectionInfo(), tableName); + } else if (operationName.equals("update")) { + return new DATAInvoker.UpdateDATAInvoker(operation, implementation.getConnectionInfo(), tableName); + } else if (operationName.equals("delete")) { + return new DATAInvoker.DeleteDATAInvoker(operation, implementation.getConnectionInfo(), tableName); + } + } + + return new DATAInvoker(operation, implementation.getConnectionInfo(), tableName); + } + + public boolean supportsOneWayInvocation() { + return false; + } + + public void start() { + // System.out.println("Starting " + component.getName()); + } + + public void stop() { + // System.out.println("Stopping " + component.getName()); + } +} diff --git a/branches/sca-java-1.3/modules/implementation-data-xml/src/main/java/org/apache/tuscany/sca/implementation/data/provider/DATAImplementationProviderFactory.java b/branches/sca-java-1.3/modules/implementation-data-xml/src/main/java/org/apache/tuscany/sca/implementation/data/provider/DATAImplementationProviderFactory.java new file mode 100644 index 0000000000..e1af9ecd92 --- /dev/null +++ b/branches/sca-java-1.3/modules/implementation-data-xml/src/main/java/org/apache/tuscany/sca/implementation/data/provider/DATAImplementationProviderFactory.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.implementation.data.provider; + +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.implementation.data.DATAImplementation; +import org.apache.tuscany.sca.provider.ImplementationProvider; +import org.apache.tuscany.sca.provider.ImplementationProviderFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * Factory for DATA Implementation Provider + * + * @version $Rev$ $Date$ + */ +public class DATAImplementationProviderFactory implements ImplementationProviderFactory { + + /** + * Constructs a new DATA implementation. + */ + public DATAImplementationProviderFactory(ExtensionPointRegistry extensionPoints) { + } + + public ImplementationProvider createImplementationProvider(RuntimeComponent component, DATAImplementation implementation) { + return new DATAImplementationProvider(component, implementation); + } + + public Class getModelType() { + return DATAImplementation.class; + } +} diff --git a/branches/sca-java-1.3/modules/implementation-data-xml/src/main/java/org/apache/tuscany/sca/implementation/data/provider/DATAInvoker.java b/branches/sca-java-1.3/modules/implementation-data-xml/src/main/java/org/apache/tuscany/sca/implementation/data/provider/DATAInvoker.java new file mode 100644 index 0000000000..e74bf4d134 --- /dev/null +++ b/branches/sca-java-1.3/modules/implementation-data-xml/src/main/java/org/apache/tuscany/sca/implementation/data/provider/DATAInvoker.java @@ -0,0 +1,583 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.implementation.data.provider; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.data.engine.config.ConnectionInfo; +import org.apache.tuscany.sca.implementation.data.jdbc.JDBCHelper; +import org.apache.tuscany.sca.implementation.data.jdbc.JDBCResultSetStreamReader; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.osoa.sca.ServiceRuntimeException; + +/** + * Implements a target invoker for DAS component implementations. + * + * The target invoker is responsible for dispatching invocations to the particular + * component implementation logic. The current component implementation will + * dispatch calls to the DAS APIs to retrieve the requested data from the back-end store + * + * @version $Rev$ $Date$ + */ +public class DATAInvoker implements Invoker { + + protected final Operation operation; + protected final ConnectionInfo connectionInfo; + protected final String table; + + public DATAInvoker(Operation operation, ConnectionInfo connectionInfo, String table) { + this.operation = operation; + this.connectionInfo = connectionInfo; + this.table = table; + } + + public Message invoke(Message msg) { + // Shouldn't get here, as the only supported operations + // are the ones defined DATA interface and implemented + // by specific invoker subclasses + + throw new UnsupportedOperationException(operation.getName()); + } + + /**************************************************************** + * + * Internal invoker implementations for each supported operation + * + *****************************************************************/ + /** + * GetAll operation invoker + */ + public static class GetAllInvoker extends DATAInvoker { + + public GetAllInvoker(Operation operation, ConnectionInfo connectionInfo, String table) { + super(operation, connectionInfo, table); + } + + @Override + public Message invoke(Message msg) { + return msg; + } + } + + /** + * Query operation invoker + */ + public static class QueryInvoker extends DATAInvoker { + + public QueryInvoker(Operation operation, ConnectionInfo connectionInfo, String table) { + super(operation, connectionInfo, table); + } + + @Override + public Message invoke(Message msg) { + return msg; + } + } + + /** + * Post operation invoker + */ + public static class PostInvoker extends DATAInvoker { + + public PostInvoker(Operation operation, ConnectionInfo connectionInfo, String table) { + super(operation, connectionInfo, table); + } + + @Override + public Message invoke(Message msg) { + + StringBuilder sqlInsert = new StringBuilder(); + XMLStreamReader insertStream = (XMLStreamReader) ((Object[]) msg.getBody())[1]; + + if (insertStream == null) { + throw new IllegalArgumentException("The XMLStreamReader \"insertStream\" must not be null"); + } + + + Connection connection = null; + PreparedStatement inStmt = null; + + List colNames = new ArrayList(); + List values = new ArrayList(); + + int result = 0; + try { + + connection = JDBCHelper.getConnection(connectionInfo); + + while (insertStream.hasNext()) { + + insertStream.next(); + if (insertStream.isStartElement()) { + if (insertStream.getLocalName().equals("record")) { + sqlInsert.append("INSERT INTO " + this.table + " ("); + } else if (insertStream.getLocalName().equals("column")) { + colNames.add(insertStream.getAttributeValue(0)); + insertStream.next(); + if (insertStream.isCharacters()) { + values.add(insertStream.getText()); + } + } + } else if (insertStream.isEndElement() && insertStream.getLocalName().equals("record")) { + for (String c : colNames) { + sqlInsert.append(" " + c + ","); + } + + sqlInsert.deleteCharAt(sqlInsert.length() - 1); + sqlInsert.append(" ) VALUES ("); + + for (String v : values) { + sqlInsert.append(" '" + v + "',"); + } + + sqlInsert.deleteCharAt(sqlInsert.length() - 1); + sqlInsert.append(" )"); + + inStmt = connection.prepareStatement(sqlInsert.toString()); + + result += inStmt.executeUpdate(); + + // Clean up resources + inStmt.close(); + sqlInsert.delete(0, sqlInsert.length()); + values.clear(); + colNames.clear(); + } + } + } catch (XMLStreamException e) { + msg.setFaultBody(new ServiceRuntimeException(e)); + } catch (SQLException sqle) { + sqle.printStackTrace(); + msg.setFaultBody(new ServiceRuntimeException(sqle.getCause())); + } catch (Exception e) { + msg.setFaultBody(new ServiceRuntimeException(e)); + } finally { + JDBCHelper.cleanupResources(connection, inStmt, null); + } + + msg.setBody(Integer.toString(result)); + return msg; + } + } + + /** + * Get operation invoker + */ + public static class GetInvoker extends DATAInvoker { + + public GetInvoker(Operation operation, ConnectionInfo connectionInfo, String table) { + super(operation, connectionInfo, table); + } + + @Override + public Message invoke(Message msg) { + + // Get an entry + String sqlQuery = null; + String id = (String) ((Object[]) msg.getBody())[0]; + + if (id == null) { + sqlQuery = "SELECT * FROM " + this.table; + } else { + sqlQuery = "SELECT * FROM " + this.table + " WHERE ID = " + id; + } + + Connection connection = null; + PreparedStatement queryStatement = null; + ResultSet resultSet = null; + try { + connection = JDBCHelper.getConnection(connectionInfo); + queryStatement = connection.prepareStatement(sqlQuery); + resultSet = queryStatement.executeQuery(); + + + } catch (SQLException sqle) { + msg.setFaultBody(new ServiceRuntimeException(sqle.getCause())); + JDBCHelper.cleanupResources(connection, queryStatement, resultSet); + } catch (Exception e) { + msg.setFaultBody(new ServiceRuntimeException(e)); + JDBCHelper.cleanupResources(connection, queryStatement, resultSet); + } finally { + //default we leave the connection open to pass to the JDBCStreamReader + } + + msg.setBody(new JDBCResultSetStreamReader(resultSet)); + return msg; + } + } + + /** + * Put operation invoker + */ + public static class PutInvoker extends DATAInvoker { + + public PutInvoker(Operation operation, ConnectionInfo connectionInfo, String table) { + super(operation, connectionInfo, table); + } + + @Override + public Message invoke(Message msg) { + + XMLStreamReader updateStream = (XMLStreamReader) ((Object[]) msg.getBody())[1]; + + if (updateStream == null) { + throw new IllegalArgumentException("The XMLStreamReader \"updateStream\" must not be null"); + } + + Connection connection = null; + PreparedStatement upStmt = null; + + String id = null; + String columnName = null; + String newValue = null; + int result = 0; + + try { + connection = JDBCHelper.getConnection(connectionInfo); + while (updateStream.hasNext()) { + updateStream.next(); + + if (updateStream.isStartElement() && updateStream.getLocalName().equals("column")) { + columnName = updateStream.getAttributeValue(0); + updateStream.next(); + if (updateStream.isCharacters()) { + if (columnName.equals("ID")) { + id = updateStream.getText(); + } else { + newValue = updateStream.getText(); + + upStmt = connection.prepareStatement("UPDATE " + this.table + " SET " + columnName + " = '" + newValue + "' WHERE ID = " + id); + + result += upStmt.executeUpdate(); + upStmt.close(); + } + } + } + } + } catch (XMLStreamException e) { + msg.setFaultBody(new ServiceRuntimeException(e)); + } catch (SQLException sqle) { + sqle.printStackTrace(); + msg.setFaultBody(new ServiceRuntimeException(sqle.getCause())); + } catch (Exception e) { + msg.setFaultBody(new ServiceRuntimeException(e)); + } finally { + JDBCHelper.cleanupResources(connection, upStmt, null); + } + + msg.setBody(result); + return msg; + } + } + + /** + * Delete operation invoker + */ + public static class DeleteInvoker extends DATAInvoker { + + public DeleteInvoker(Operation operation, ConnectionInfo connectionInfo, String table) { + super(operation, connectionInfo, table); + } + + @Override + public Message invoke(Message msg) { + + // Get an entry + String sqlDelete = null; + String id = (String) ((Object[]) msg.getBody())[0]; + + if (id == null) { + sqlDelete = "DELETE FROM " + this.table; + } else { + sqlDelete = "DELETE FROM " + this.table + " WHERE ID = " + id; + } + + Connection connection = null; + PreparedStatement deleteStatement = null; + int result = -1; + + try { + connection = JDBCHelper.getConnection(connectionInfo); + deleteStatement = connection.prepareStatement(sqlDelete); + result = deleteStatement.executeUpdate(); + + } catch (SQLException sqle) { + msg.setFaultBody(new ServiceRuntimeException(sqle.getCause())); + } catch (Exception e) { + msg.setFaultBody(new ServiceRuntimeException(e)); + } finally { + JDBCHelper.cleanupResources(connection, deleteStatement, null); + } + + msg.setBody(result); + return msg; + } + } + /** + * Get operation invoker + * + * @version $Rev$ $Date$ + */ + public static class GetDATAInvoker extends DATAInvoker { + + public GetDATAInvoker(Operation operation, ConnectionInfo connectionInfo, String table) { + super(operation, connectionInfo, table); + } + + @Override + public Message invoke(Message msg) { + + // Get an entry + String sqlQuery = null; + String id = (String) ((Object[]) msg.getBody())[0]; + + if (id == null) { + sqlQuery = "SELECT * FROM " + this.table; + } else { + sqlQuery = "SELECT * FROM " + this.table + " WHERE ID = " + id; + } + + Connection connection = null; + PreparedStatement queryStatement = null; + ResultSet resultSet = null; + try { + connection = JDBCHelper.getConnection(connectionInfo); + queryStatement = connection.prepareStatement(sqlQuery); + resultSet = queryStatement.executeQuery(); + + + } catch (SQLException sqle) { + msg.setFaultBody(new ServiceRuntimeException(sqle.getCause())); + JDBCHelper.cleanupResources(connection, queryStatement, resultSet); + } catch (Exception e) { + msg.setFaultBody(new ServiceRuntimeException(e)); + JDBCHelper.cleanupResources(connection, queryStatement, resultSet); + } finally { + //default we leave the connection open to pass to the JDBCStreamReader + } + + msg.setBody(new JDBCResultSetStreamReader(resultSet)); + return msg; + } + } + + /** + * Insert operation invoker + */ + public static class InsertDATAInvoker extends DATAInvoker { + + public InsertDATAInvoker(Operation operation, + ConnectionInfo connectionInfo, String table) { + super(operation, connectionInfo, table); + } + + @Override + public Message invoke(Message msg) throws IllegalArgumentException { + StringBuilder sqlInsert = new StringBuilder(); + XMLStreamReader insertStream = (XMLStreamReader) ((Object[]) msg.getBody())[0]; + + if (insertStream == null) { + throw new IllegalArgumentException("The XMLStreamReader \"insertStream\" must not be null"); + } + + + Connection connection = null; + PreparedStatement inStmt = null; + + List colNames = new ArrayList(); + List values = new ArrayList(); + + int result = 0; + try { + + connection = JDBCHelper.getConnection(connectionInfo); + + while (insertStream.hasNext()) { + + insertStream.next(); + if (insertStream.isStartElement()) { + if (insertStream.getLocalName().equals("record")) { + sqlInsert.append("INSERT INTO " + this.table + " ("); + } else if (insertStream.getLocalName().equals("column")) { + colNames.add(insertStream.getAttributeValue(0)); + insertStream.next(); + if (insertStream.isCharacters()) { + values.add(insertStream.getText()); + } + } + } else if (insertStream.isEndElement() && insertStream.getLocalName().equals("record")) { + for (String c : colNames) { + sqlInsert.append(" " + c + ","); + } + + sqlInsert.deleteCharAt(sqlInsert.length() - 1); + sqlInsert.append(" ) VALUES ("); + + for (String v : values) { + sqlInsert.append(" '" + v + "',"); + } + + sqlInsert.deleteCharAt(sqlInsert.length() - 1); + sqlInsert.append(" )"); + + inStmt = connection.prepareStatement(sqlInsert.toString()); + result += inStmt.executeUpdate(); + + // Clean up resources + inStmt.close(); + sqlInsert.delete(0, sqlInsert.length()); + values.clear(); + colNames.clear(); + } + } + } catch (XMLStreamException e) { + msg.setFaultBody(new ServiceRuntimeException(e)); + } catch (SQLException sqle) { + sqle.printStackTrace(); + msg.setFaultBody(new ServiceRuntimeException(sqle.getCause())); + } catch (Exception e) { + msg.setFaultBody(new ServiceRuntimeException(e)); + } finally { + JDBCHelper.cleanupResources(connection, inStmt, null); + } + + msg.setBody(result); + return msg; + } + } + + /** + * Update operation invoker + */ + public static class UpdateDATAInvoker extends DATAInvoker { + + public UpdateDATAInvoker(Operation operation, + ConnectionInfo connectionInfo, String table) { + super(operation, connectionInfo, table); + } + + @Override + public Message invoke(Message msg) throws IllegalArgumentException { + + XMLStreamReader updateStream = (XMLStreamReader) ((Object[]) msg.getBody())[0]; + + if (updateStream == null) { + throw new IllegalArgumentException("The XMLStreamReader \"updateStream\" must not be null"); + } + + Connection connection = null; + PreparedStatement upStmt = null; + + String id = null; + String columnName = null; + String newValue = null; + int result = 0; + + try { + connection = JDBCHelper.getConnection(connectionInfo); + while (updateStream.hasNext()) { + updateStream.next(); + + if (updateStream.isStartElement() && updateStream.getLocalName().equals("column")) { + columnName = updateStream.getAttributeValue(0); + updateStream.next(); + if (updateStream.isCharacters()) { + if (columnName.equals("ID")) { + id = updateStream.getText(); + } else { + newValue = updateStream.getText(); + + upStmt = connection.prepareStatement("UPDATE " + this.table + " SET " + columnName + " = '" + newValue + "' WHERE ID = " + id); + + result += upStmt.executeUpdate(); + upStmt.close(); + } + } + } + } + } catch (XMLStreamException e) { + msg.setFaultBody(new ServiceRuntimeException(e)); + } catch (SQLException sqle) { + sqle.printStackTrace(); + msg.setFaultBody(new ServiceRuntimeException(sqle.getCause())); + } catch (Exception e) { + msg.setFaultBody(new ServiceRuntimeException(e)); + } finally { + JDBCHelper.cleanupResources(connection, upStmt, null); + } + + msg.setBody(result); + return msg; + } + } + + /** + * Delete operation invoker + */ + public static class DeleteDATAInvoker extends DATAInvoker { + + public DeleteDATAInvoker(Operation operation, ConnectionInfo connectionInfo, String table) { + super(operation, connectionInfo, table); + } + + @Override + public Message invoke(Message msg) { + + // Get an entry + String sqlDelete = null; + String id = (String) ((Object[]) msg.getBody())[0]; + + if (id == null) { + sqlDelete = "DELETE FROM " + this.table; + } else { + sqlDelete = "DELETE FROM " + this.table + " WHERE ID = " + id; + } + + Connection connection = null; + PreparedStatement deleteStatement = null; + int result = -1; + + try { + connection = JDBCHelper.getConnection(connectionInfo); + deleteStatement = connection.prepareStatement(sqlDelete); + result = deleteStatement.executeUpdate(); + + } catch (SQLException sqle) { + msg.setFaultBody(new ServiceRuntimeException(sqle.getCause())); + } catch (Exception e) { + msg.setFaultBody(new ServiceRuntimeException(e)); + } finally { + JDBCHelper.cleanupResources(connection, deleteStatement, null); + } + + msg.setBody(result); + return msg; + } + } +} diff --git a/branches/sca-java-1.3/modules/implementation-data-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/branches/sca-java-1.3/modules/implementation-data-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..5cd3334e3f --- /dev/null +++ b/branches/sca-java-1.3/modules/implementation-data-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the artifact processor extension +org.apache.tuscany.sca.implementation.data.DATAImplementationProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#implementation.data.xml,model=org.apache.tuscany.sca.implementation.data.DATAImplementation diff --git a/branches/sca-java-1.3/modules/implementation-data-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory b/branches/sca-java-1.3/modules/implementation-data-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory new file mode 100644 index 0000000000..e20f1a6379 --- /dev/null +++ b/branches/sca-java-1.3/modules/implementation-data-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the implementation extension +org.apache.tuscany.sca.implementation.data.provider.DATAImplementationProviderFactory;model=org.apache.tuscany.sca.implementation.data.DATAImplementation diff --git a/branches/sca-java-1.3/modules/implementation-data-xml/src/test/java/org/apache/tuscany/sca/implementation/data/DATACollectionTestCaseFIXME.java b/branches/sca-java-1.3/modules/implementation-data-xml/src/test/java/org/apache/tuscany/sca/implementation/data/DATACollectionTestCaseFIXME.java new file mode 100644 index 0000000000..458025dd66 --- /dev/null +++ b/branches/sca-java-1.3/modules/implementation-data-xml/src/test/java/org/apache/tuscany/sca/implementation/data/DATACollectionTestCaseFIXME.java @@ -0,0 +1,118 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.implementation.data; + +import java.io.FileInputStream; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; +import junit.framework.TestCase; +import org.apache.tuscany.sca.databinding.xml.XMLStreamReader2String; +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.apache.tuscany.sca.implementation.data.DATACollection; + +public class DATACollectionTestCaseFIXME extends TestCase { + + private SCADomain scaDomain; + private DATACollection dataService; + + /** + * @throws java.lang.Exception + */ + @Override + protected void setUp() throws Exception { + scaDomain = SCADomain.newInstance("data.composite"); + dataService = scaDomain.getService(DATACollection.class, "DataComponent/COMPANY"); + } + + /** + * @throws java.lang.Exception + */ + @Override + protected void tearDown() throws Exception { + scaDomain.close(); + } + + public void testInsert() throws Exception { + System.out.println(">testInsert"); + + //Read and process the XML file + FileInputStream fileInputStream = new FileInputStream("src/test/resources/insert.xml"); + XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(fileInputStream); + + String result = dataService.post(null, reader); + assertEquals(result, "2"); + + System.out.println("Number of rows inserted: " + result); + + reader.close(); + } + + public void testGet() throws Exception { + + System.out.println(">testGet"); + + XMLStreamReader reader = dataService.get(null); + assertNotNull(reader); + String xml = new XMLStreamReader2String().transform(reader, null); + System.out.println(xml); + reader.close(); + } + + public void testUpdate() throws Exception { + + System.out.println(">testUpdate"); + + //Read and process the XML file + FileInputStream fileInputStream = new FileInputStream("src/test/resources/update.xml"); + XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(fileInputStream); + + dataService.put(null,reader); + + reader.close(); + } + + public void testGetByID() throws Exception { + System.out.println(">testGetByID"); + + Integer companyID = new Integer(4); + + XMLStreamReader reader = dataService.get(companyID.toString()); + assertNotNull(reader); + String xml = new XMLStreamReader2String().transform(reader, null); + System.out.println(xml); + reader.close(); + } + + public void testDeleteByID() throws Exception { + System.out.println(">testDeleteByID"); + + Integer companyID = new Integer(4); + dataService.delete(companyID.toString()); + } + + public void testDelete() throws Exception { + System.out.println(">testDelete"); + + dataService.delete(null); + + System.out.println("recreating database..."); + //Helper.createDB(); + System.out.println("done!"); + } +} diff --git a/branches/sca-java-1.3/modules/implementation-data-xml/src/test/java/org/apache/tuscany/sca/implementation/data/DATAImplementationProcessorTestCase.java b/branches/sca-java-1.3/modules/implementation-data-xml/src/test/java/org/apache/tuscany/sca/implementation/data/DATAImplementationProcessorTestCase.java new file mode 100644 index 0000000000..dcf87d8c68 --- /dev/null +++ b/branches/sca-java-1.3/modules/implementation-data-xml/src/test/java/org/apache/tuscany/sca/implementation/data/DATAImplementationProcessorTestCase.java @@ -0,0 +1,133 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.implementation.data; + +import java.io.StringReader; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.SCABindingFactory; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; +import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl; +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.data.engine.config.ConnectionInfo; +import org.apache.tuscany.sca.data.engine.config.ConnectionProperties; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl; +import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory; + +/** + * @version $Rev: 538445 $ $Date: 2007-05-15 23:20:37 -0700 (Tue, 15 May 2007) $ + */ +public class DATAImplementationProcessorTestCase extends TestCase { + + protected static final QName IMPLEMENTATION_DATA = new QName(Constants.SCA10_TUSCANY_NS, "implementation.data.xml"); + + private static final String COMPOSITE_USING_DATASOURCE = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + ""; + + private static final String COMPOSITE_USING_CONNECTION_PROPERTIES = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + ""; + + private XMLInputFactory inputFactory; + private StAXArtifactProcessor staxProcessor; + private CompositeBuilder compositeBuilder; + + @Override + protected void setUp() throws Exception { + DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + inputFactory = XMLInputFactory.newInstance(); + StAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null); + + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + AssemblyFactory assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); + SCABindingFactory scaBindingFactory = modelFactories.getFactory(SCABindingFactory.class); + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + InterfaceContractMapper mapper = utilities.getUtility(InterfaceContractMapper.class); + IntentAttachPointTypeFactory attachPointTypeFactory = modelFactories.getFactory(IntentAttachPointTypeFactory.class); + compositeBuilder = new CompositeBuilderImpl(assemblyFactory, scaBindingFactory, attachPointTypeFactory, mapper, null); + } + + public void testLoadCompositeUsingDatasource() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(COMPOSITE_USING_DATASOURCE)); + + Composite composite = (Composite)staxProcessor.read(reader); + DATAImplementation implementation = (DATAImplementation)composite.getComponents().get(0).getImplementation(); + assertNotNull(implementation); + + ConnectionInfo connInfo = implementation.getConnectionInfo(); + assertNotNull(connInfo); + assertEquals("dataSource", connInfo.getDataSource()); + + ConnectionProperties connProperties = connInfo.getConnectionProperties(); + assertNull(connProperties); + } + + public void testLoadCompositeUsingConnectionProperties() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(COMPOSITE_USING_CONNECTION_PROPERTIES)); + + Composite composite = (Composite)staxProcessor.read(reader); + DATAImplementation implementation = (DATAImplementation)composite.getComponents().get(0).getImplementation(); + assertNotNull(implementation); + + ConnectionInfo connInfo = implementation.getConnectionInfo(); + assertNotNull(connInfo); + assertNull("dataSource", connInfo.getDataSource()); + + ConnectionProperties connProperties = connInfo.getConnectionProperties(); + assertNotNull(connProperties); + assertEquals("driverClass",connProperties.getDriverClass()); + assertEquals("databaseURL",connProperties.getDatabaseURL()); + assertEquals(1,connProperties.getLoginTimeout().intValue()); + } +} diff --git a/branches/sca-java-1.3/modules/implementation-data-xml/src/test/java/org/apache/tuscany/sca/implementation/data/DATATestCase.java b/branches/sca-java-1.3/modules/implementation-data-xml/src/test/java/org/apache/tuscany/sca/implementation/data/DATATestCase.java new file mode 100644 index 0000000000..4010cb63d3 --- /dev/null +++ b/branches/sca-java-1.3/modules/implementation-data-xml/src/test/java/org/apache/tuscany/sca/implementation/data/DATATestCase.java @@ -0,0 +1,133 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.implementation.data; + +import java.io.FileInputStream; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.databinding.xml.XMLStreamReader2String; +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.apache.tuscany.sca.implementation.data.DATA; + +/** + * Tests the DAS service + * + * @version $Rev$ $Date$ + */ +public class DATATestCase extends TestCase { + private SCADomain scaDomain; + private DATA dataService; + + /** + * @throws java.lang.Exception + */ + @Override + protected void setUp() throws Exception { + scaDomain = SCADomain.newInstance("data.composite"); + dataService = scaDomain.getService(DATA.class, "DataComponent/COMPANY_DATA"); + } + + /** + * @throws java.lang.Exception + */ + @Override + protected void tearDown() throws Exception { + scaDomain.close(); + } + + public void testInsert() throws Exception { + System.out.println(">testInsert"); + + //Read and process the XML file + FileInputStream fileInputStream = new FileInputStream("src/test/resources/insert.xml"); + XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(fileInputStream); + + int result = dataService.insert(reader); + assertEquals(result,2); + + System.out.println("Number of rows inserted: "+result); + + reader.close(); + } + + public void testGet() throws Exception { + + System.out.println(">testGet"); + + XMLStreamReader reader = dataService.get(null); + assertNotNull(reader); + String xml = new XMLStreamReader2String().transform(reader, null); + System.out.println(xml); + reader.close(); + } + + public void testUpdate() throws Exception { + + System.out.println(">testUpdate"); + + //Read and process the XML file + FileInputStream fileInputStream = new FileInputStream("src/test/resources/update.xml"); + XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(fileInputStream); + + int result = dataService.update(reader); + assertEquals(result,1); + System.out.println("Number of rows affected: "+result); + + reader.close(); + } + + public void testGetByID() throws Exception { + System.out.println(">testGetByID"); + + Integer companyID = new Integer(4); + + XMLStreamReader reader = dataService.get(companyID.toString()); + assertNotNull(reader); + String xml = new XMLStreamReader2String().transform(reader, null); + System.out.println(xml); + reader.close(); + } + + public void testDeleteByID() throws Exception { + System.out.println(">testDeleteByID"); + + Integer companyID = new Integer(4); + int result = dataService.delete(companyID.toString()); + assertEquals(result,1); + System.out.println("Number of rows deleted: "+result); + } + + public void testDelete() throws Exception { + System.out.println(">testDelete"); + + int result = dataService.delete(null); + assertEquals(result,4); + System.out.println("Number of rows deleted: "+result); + + System.out.println("recreating database..."); + //Helper.createDB(); + System.out.println("done!"); + } + +} diff --git a/branches/sca-java-1.3/modules/implementation-data-xml/src/test/java/org/apache/tuscany/sca/implementation/data/companyFeed/CompanyFeed.java b/branches/sca-java-1.3/modules/implementation-data-xml/src/test/java/org/apache/tuscany/sca/implementation/data/companyFeed/CompanyFeed.java new file mode 100644 index 0000000000..7f0707c0bc --- /dev/null +++ b/branches/sca-java-1.3/modules/implementation-data-xml/src/test/java/org/apache/tuscany/sca/implementation/data/companyFeed/CompanyFeed.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.implementation.data.companyFeed; + +import org.apache.tuscany.sca.data.collection.Collection; +import org.apache.tuscany.sca.data.collection.Entry; +import org.apache.tuscany.sca.data.collection.NotFoundException; +import org.apache.tuscany.sca.implementation.data.DATA; +import org.osoa.sca.annotations.Reference; + +import commonj.sdo.DataObject; + +public class CompanyFeed implements Collection { + + @Reference + protected DATA dataService; + + public Entry[] getAll() { + return null; + } + + public DataObject get(String id) throws NotFoundException{ + + DataObject data = null;//dataService.get(id); + if(data == null) { + throw new NotFoundException(); + } else { + return data; + } + } + + public void delete(String id) throws NotFoundException { + } + + public String post(String key, DataObject item) { + return null; + } + + public void put(String key, DataObject item) throws NotFoundException { + } + + public Entry[] query(String queryString) { + return null; + } +} diff --git a/branches/sca-java-1.3/modules/implementation-data-xml/src/test/java/org/apache/tuscany/sca/implementation/data/companyFeed/CompanyFeedTestCaseFIXME.java b/branches/sca-java-1.3/modules/implementation-data-xml/src/test/java/org/apache/tuscany/sca/implementation/data/companyFeed/CompanyFeedTestCaseFIXME.java new file mode 100644 index 0000000000..b72ff89e3b --- /dev/null +++ b/branches/sca-java-1.3/modules/implementation-data-xml/src/test/java/org/apache/tuscany/sca/implementation/data/companyFeed/CompanyFeedTestCaseFIXME.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.implementation.data.companyFeed; + +import java.io.IOException; +import java.net.Socket; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * @version $Rev: 543175 $ $Date: 2007-05-31 09:09:12 -0700 (Thu, 31 May 2007) $ + */ +public class CompanyFeedTestCaseFIXME extends TestCase { + private SCADomain scaDomain; + + @Override + protected void setUp() throws Exception { + super.setUp(); + scaDomain = SCADomain.newInstance("data-feed.composite"); + //System.in.read(); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + scaDomain.close(); + } + + public void testPing() throws IOException { + new Socket("127.0.0.1", 8085); + } + +} diff --git a/branches/sca-java-1.3/modules/implementation-data-xml/src/test/resources/data-feed.composite b/branches/sca-java-1.3/modules/implementation-data-xml/src/test/resources/data-feed.composite new file mode 100644 index 0000000000..40c755b134 --- /dev/null +++ b/branches/sca-java-1.3/modules/implementation-data-xml/src/test/resources/data-feed.composite @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/branches/sca-java-1.3/modules/implementation-data-xml/src/test/resources/data.composite b/branches/sca-java-1.3/modules/implementation-data-xml/src/test/resources/data.composite new file mode 100644 index 0000000000..f30b15e34c --- /dev/null +++ b/branches/sca-java-1.3/modules/implementation-data-xml/src/test/resources/data.composite @@ -0,0 +1,36 @@ + + + + + + + + + + + + + diff --git a/branches/sca-java-1.3/modules/implementation-data-xml/src/test/resources/insert.xml b/branches/sca-java-1.3/modules/implementation-data-xml/src/test/resources/insert.xml new file mode 100644 index 0000000000..c0a5ada4bf --- /dev/null +++ b/branches/sca-java-1.3/modules/implementation-data-xml/src/test/resources/insert.xml @@ -0,0 +1,9 @@ + + + + New Coorporation I + + + New Coorporation II + + diff --git a/branches/sca-java-1.3/modules/implementation-data-xml/src/test/resources/update.xml b/branches/sca-java-1.3/modules/implementation-data-xml/src/test/resources/update.xml new file mode 100644 index 0000000000..c6cef75274 --- /dev/null +++ b/branches/sca-java-1.3/modules/implementation-data-xml/src/test/resources/update.xml @@ -0,0 +1,7 @@ + + + + 4 + Update Coorporation + + -- cgit v1.2.3