diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2010-01-13 02:16:12 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2010-01-13 02:16:12 +0000 |
commit | 83355a7557cf91c455a65e0ce79ea8dd4d880052 (patch) | |
tree | 25fb3c02f2eca9990323a3b9c03bc6028f73fb38 /sandbox/lresende/sca-1.x/modules/implementation-data-pojo | |
parent | 3e33ce505cf18f5f603f29cf0be4b4fd33053d3d (diff) |
Refactoring sandbox structure to accomodate 1.x versus 2.x stuff
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@898623 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sandbox/lresende/sca-1.x/modules/implementation-data-pojo')
31 files changed, 1853 insertions, 0 deletions
diff --git a/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/DISCLAIMER b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software
+Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is
+required of all newly accepted projects until a further review indicates that
+the infrastructure, communications, and decision making process have stabilized
+in a manner consistent with other successful ASF projects. While incubation
+status is not necessarily a reflection of the completeness or stability of the
+code, it does indicate that the project has yet to be fully endorsed by the ASF.
+
diff --git a/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/LICENSE b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/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/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/NOTICE b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/README b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/README new file mode 100644 index 0000000000..ff6ee6a8f4 --- /dev/null +++ b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/README @@ -0,0 +1,33 @@ +Tuscany implementation OpenJpa +=============================== +Persistence technology is a very part of enterprise level application system. Tuscany has provided +SDO implementation and a non standard but useful DAS infrastructure. +But Tuscany also considered much existed software resource has used popular technologies as +hibernate and jpa. +Hibernate has license problem so an implementation based on it can not be hosted by Apache. +This implementation is developed on the bases of Tuscany¡¯s robust extensible architecture and of +course the jpa implementation project: Apache OpenJPA. + +This module is under the process of more improvement: + +For the time being, user of this module could configure a component as did by the *.composite file +in this module. The component is infact a proxy of a JPA top api: + javax.persitence.EntityManager +User of this module could use all the method provided by this interface. + +An difference is: OpenJPA could work with 2PC only if there is JNDI context and +TransactionManager registered in the JNDI. This module modified much to work with +policy-transaction module. + +For the time being, the Transaction boundary is located around one invocation of the EntityManager. But in the future, these boundary will move up to an component who references the EntityManager, that will be the righteous way for SCA developers! + +The data base working in this module is now Derby, it is for the ease of test running. MySQL +could also work with this module, but it need database deployment in before. Not all types of database could work with this module, such as HSql, it did not provided a XA DataSource implementation up to now. + +There are much powerful features provided by openjpa, such as table auto generation, it is now also working in this module. + +User could get start from looking at what is done by: +??org.apache.tuscany.sca.implementation.openjpa.ImplJpaTestCase +??and +??openjpa.composite +When running the testcase, a RuntimeException stack trace(from inside openjpa api) will get printed on your screen, it is just ok, because of a trying of duplication primary key insertion, and it causes transaction rolling back. diff --git a/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/company.sql b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/company.sql new file mode 100644 index 0000000000..4911f9e62f --- /dev/null +++ b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/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/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/pom.xml b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/pom.xml new file mode 100644 index 0000000000..7e56a256a2 --- /dev/null +++ b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/pom.xml @@ -0,0 +1,174 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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. +--> +<project> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-modules</artifactId> + <version>1.5-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + <artifactId>tuscany-implementation-data-pojo</artifactId> + <name>Apache Tuscany SCA OpenJPA Implementation Extension</name> + + <repositories> + <repository> + <id>apache.incubator</id> + <url>http://people.apache.org/repo/m2-incubating-repository</url> + </repository> + </repositories> + + <dependencies> + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-assembly</artifactId> + <version>1.5-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-core</artifactId> + <version>1.5-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-interface</artifactId> + <version>1.5-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-assembly-xml</artifactId> + <version>1.5-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-contribution-impl</artifactId> + <version>1.5-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-sca-api</artifactId> + <version>1.5-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-databinding</artifactId> + <version>1.5-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-implementation-java-runtime</artifactId> + <version>1.5-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-data-api</artifactId> + <version>1.5-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-host-embedded</artifactId> + <version>1.5-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-policy-transaction</artifactId> + <version>1.5-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.apache.geronimo.specs</groupId> + <artifactId>geronimo-jpa_3.0_spec</artifactId> + <version>1.1</version> + </dependency> + <dependency> + <groupId>org.apache.openjpa</groupId> + <artifactId>openjpa</artifactId> + <version>1.0.0</version> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.derby</groupId> + <artifactId>derby</artifactId> + <version>10.3.1.4</version> + <scope>compile</scope> + </dependency> + </dependencies> + + <build> + <finalName>${artifactId}</finalName> + + <plugins> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>sql-maven-plugin</artifactId> + <version>1.3</version> + + <dependencies> + <dependency> + <groupId>org.apache.derby</groupId> + <artifactId>derby</artifactId> + <!--version>10.1.2.1</version--> + <version>10.3.1.4</version> + </dependency> + </dependencies> + + <executions> + <execution> + <id>create-db</id> + <phase>generate-resources</phase> + <goals> + <goal>execute</goal> + </goals> + <configuration> + <driver>org.apache.derby.jdbc.EmbeddedDriver</driver> + <url>jdbc:derby:${pom.basedir}/target/test-classes/company;create=true</url> + <autocommit>true</autocommit> + <onError>continue</onError> + <onConnectionError>skip</onConnectionError> + <delimiter>;</delimiter> + <srcFiles> + <srcFile>${pom.basedir}/company.sql</srcFile> + </srcFiles> + </configuration> + </execution> + + <!-- Shutdown DB in order to be able to run unit tests --> + <execution> + <id>shutdown-database-sothat-test-can-run</id> + <phase>process-test-resources</phase> + <goals> + <goal>execute</goal> + </goals> + <configuration> + <driver>org.apache.derby.jdbc.EmbeddedDriver</driver> + <url>jdbc:derby:${pom.basedir}/target/test-classes/company;shutdown=true</url> + <skipOnConnectionError>true</skipOnConnectionError> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + +</project> diff --git a/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/java/org/apache/tuscany/sca/implementation/openjpa/JPAImplementation.java b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/java/org/apache/tuscany/sca/implementation/openjpa/JPAImplementation.java new file mode 100644 index 0000000000..c1ed6b4e58 --- /dev/null +++ b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/java/org/apache/tuscany/sca/implementation/openjpa/JPAImplementation.java @@ -0,0 +1,36 @@ +/* + * 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.openjpa; + +import java.util.Properties; + +import org.apache.openjpa.persistence.PersistenceUnitInfoImpl; +import org.apache.tuscany.sca.assembly.Implementation; + +public interface JPAImplementation extends Implementation { + + void setPersistenceUnitInfoImpl(PersistenceUnitInfoImpl buii); + + PersistenceUnitInfoImpl getPersistenceUnitInfoImpl(); + + void setDataSourceMeta(Properties p); + + Properties getDataSourceMeta(); +} diff --git a/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/java/org/apache/tuscany/sca/implementation/openjpa/JPAImplementationFactory.java b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/java/org/apache/tuscany/sca/implementation/openjpa/JPAImplementationFactory.java new file mode 100644 index 0000000000..a5812b26e4 --- /dev/null +++ b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/java/org/apache/tuscany/sca/implementation/openjpa/JPAImplementationFactory.java @@ -0,0 +1,24 @@ +/* + * 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.openjpa; + +public interface JPAImplementationFactory { + JPAImplementation createOpenJpaImplementation(); +} diff --git a/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/java/org/apache/tuscany/sca/implementation/openjpa/JPAImplementationProcessor.java b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/java/org/apache/tuscany/sca/implementation/openjpa/JPAImplementationProcessor.java new file mode 100644 index 0000000000..8ea83e7bfb --- /dev/null +++ b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/java/org/apache/tuscany/sca/implementation/openjpa/JPAImplementationProcessor.java @@ -0,0 +1,99 @@ +/* + * 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.openjpa; + +import java.util.Properties; + +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.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.openjpa.persistence.PersistenceUnitInfoImpl; +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.implementation.openjpa.impl.JPAImplementationFactoryImpl; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; + +public class JPAImplementationProcessor implements StAXArtifactProcessor<JPAImplementation> { + private final QName QNAME = new QName(Constants.SCA10_TUSCANY_NS, "implementation.data.pojo"); + private QName DS = new QName(Constants.SCA10_TUSCANY_NS, "datasource"); + + private JPAImplementationFactory jpaFactory; + private Log log = LogFactory.getLog(this.getClass()); + private StAXArtifactProcessor<PersistenceUnitInfoImpl> puiiProcessor; + + public JPAImplementationProcessor(ModelFactoryExtensionPoint modelFactories) { + AssemblyFactory assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); + JavaInterfaceFactory javaFactory = modelFactories.getFactory(JavaInterfaceFactory.class); + + this.jpaFactory = new JPAImplementationFactoryImpl(assemblyFactory, javaFactory); + this.puiiProcessor = new PersistenceUnitInfoImplProcessor(modelFactories); + } + + public Class<JPAImplementation> getModelType() { + return JPAImplementation.class; + } + + public QName getArtifactType() { + return QNAME; + } + + public JPAImplementation read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + assert QNAME.equals(reader.getName()); + JPAImplementation implementation = jpaFactory.createOpenJpaImplementation(); + + implementation.setPersistenceUnitInfoImpl(puiiProcessor.read(reader)); + Properties dsmeta = new Properties(); + do { + int event = reader.next(); + if (event == XMLStreamConstants.START_ELEMENT) { + if (!reader.getName().equals(DS)) { + dsmeta.setProperty(reader.getName().getLocalPart(), reader.getElementText()); + } + } else if (event == XMLStreamConstants.END_ELEMENT && reader.getName().equals(DS)) { + implementation.setDataSourceMeta(dsmeta); + break; + } + } while (true); + + return implementation; + + } + + public void write(JPAImplementation model, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + // TODO Auto-generated method stub + + } + + public void resolve(JPAImplementation model, ModelResolver resolver) throws ContributionResolveException { + + } + +} diff --git a/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/java/org/apache/tuscany/sca/implementation/openjpa/PersistenceUnitInfoImplProcessor.java b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/java/org/apache/tuscany/sca/implementation/openjpa/PersistenceUnitInfoImplProcessor.java new file mode 100644 index 0000000000..d6e8276f25 --- /dev/null +++ b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/java/org/apache/tuscany/sca/implementation/openjpa/PersistenceUnitInfoImplProcessor.java @@ -0,0 +1,109 @@ +/* + * 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.openjpa; + +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.openjpa.persistence.PersistenceUnitInfoImpl; +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; + +public class PersistenceUnitInfoImplProcessor implements StAXArtifactProcessor<PersistenceUnitInfoImpl> { + private QName P_U = new QName(Constants.SCA10_TUSCANY_NS, "persistence-unit"); + private QName BrokerFactory = new QName(Constants.SCA10_TUSCANY_NS, "jpa.BrokerFactory"); + private QName CLASS = new QName(Constants.SCA10_TUSCANY_NS, "class"); + private QName TRAN_MD = new QName(Constants.SCA10_TUSCANY_NS, "jpa.TransactionMode"); + private QName LOG = new QName(Constants.SCA10_TUSCANY_NS, "jpa.Log"); + private QName SYNCHRON = new QName(Constants.SCA10_TUSCANY_NS, "jpa.jdbc.SynchronizeMappings"); + + public PersistenceUnitInfoImplProcessor(ModelFactoryExtensionPoint modelFactories) { + + } + + public QName getArtifactType() { + // TODO Auto-generated method stub + return null; + } + + + public PersistenceUnitInfoImpl read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + + PersistenceUnitInfoImpl _info = new PersistenceUnitInfoImpl(); + + while (true) { + int event = reader.next(); + switch (event) { + + case XMLStreamConstants.START_ELEMENT: + QName qn = reader.getName(); + /* + * if (qn.equals(BrokerFactory)) { + * _info.setProperty("openjpa.BrokerFactory", reader + * .getElementText()); } + */ + if (qn.equals(CLASS)) { + _info.addManagedClassName(reader.getElementText()); + + } else if (qn.equals(P_U)) { + _info.setPersistenceUnitName(reader.getAttributeValue(null, "name")); + } else { + _info.setProperty(qn.getLocalPart(), reader.getElementText()); + } /* + * else if (qn.equals(LOG)) { + * _info.setProperty("openjpa.Log", + * reader.getElementText()); } else if + * (qn.equals(SYNCHRON)) { + * _info.setProperty("openjpa.jdbc.SynchronizeMappings", + * reader.getElementText()); } + */ + break; + case XMLStreamConstants.END_ELEMENT: + if (reader.getName().equals(P_U)) + return _info; + } + } + } + + public void write(PersistenceUnitInfoImpl model, XMLStreamWriter writer) throws ContributionWriteException, + XMLStreamException { + // TODO Auto-generated method stub + + } + + public Class<PersistenceUnitInfoImpl> getModelType() { + // TODO Auto-generated method stub + return null; + } + + public void resolve(PersistenceUnitInfoImpl model, ModelResolver resolver) throws ContributionResolveException { + // TODO Auto-generated method stub + + } + +} diff --git a/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyBrokerFactory.java b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyBrokerFactory.java new file mode 100644 index 0000000000..c4b14a1a90 --- /dev/null +++ b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyBrokerFactory.java @@ -0,0 +1,100 @@ +/* + * 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.openjpa; + +import javax.sql.XAConnection; +import javax.transaction.TransactionManager; + +import org.apache.derby.jdbc.*; +import org.apache.openjpa.conf.OpenJPAConfiguration; +import org.apache.openjpa.kernel.AbstractBrokerFactory; +import org.apache.openjpa.kernel.StoreManager; +import org.apache.openjpa.lib.conf.ConfigurationProvider; +import java.util.*; +import org.apache.commons.logging.*; +import org.apache.openjpa.jdbc.meta.MappingTool; +import org.apache.openjpa.jdbc.conf.*; +import org.apache.openjpa.meta.*; + +public class TuscanyBrokerFactory extends AbstractBrokerFactory { + private Log log = LogFactory.getLog(this.getClass()); + protected TuscanyBrokerFactory(OpenJPAConfiguration conf) { + super(conf); + if (buildSchema != null && buildSchema.equals("buildSchema")) { + MappingTool tool = new MappingTool((JDBCConfiguration) conf, + (String) buildSchema, false); + Collection classes = meta.loadPersistentTypes(false, this + .getClass().getClassLoader()); + for (Iterator itr = classes.iterator(); itr.hasNext();) { + tool.run((Class) itr.next()); + } + log + .info("creating database and tables accroding to class mappings..."); + tool.record(); + } + } + + private XAConnection xaconn; + + @Override + protected StoreManager newStoreManager() { + try { + if (xaconn == null) { + if (cp.getProperties().get("dbtype").equals("Derby")) { + EmbeddedXADataSource xads = new EmbeddedXADataSource(); + xads.setDatabaseName((String)cp.getProperties().get("dbname")); + + xaconn = xads.getXAConnection(); + } + + System.out.println("------------TuscanyBrokerFactory.newStoreManager...."); + + } + return new TuscanyStoreManager(xaconn); + + } catch (Exception ex) { + ex.printStackTrace(); + throw new RuntimeException(ex); + } + } + + private static TransactionManager tm; + private static ConfigurationProvider cp; + private static Object buildSchema; + private static MetaDataRepository meta; + + public static TuscanyBrokerFactory newInstance(ConfigurationProvider _cp) { + tm = (TransactionManager)_cp.getProperties().get("TransactionManager"); + EmbeddedDataSource ds2 = null; + if (_cp.getProperties().get("dbtype").equals("Derby")) { + ds2 = new EmbeddedDataSource(); + ds2.setDatabaseName((String) _cp.getProperties().get("dbname")); + ds2.setCreateDatabase((String) _cp.getProperties().get("dbcreate")); + } + TuscanyJDBCConfigurationImpl conf = new TuscanyJDBCConfigurationImpl(tm, ds2); + _cp.setInto(conf); + buildSchema = _cp.getProperties().get( + "openjpa.jdbc.SynchronizeMappings"); + + meta = conf.getMetaDataRepositoryInstance(); + cp = _cp; + return new TuscanyBrokerFactory(conf); + } +} diff --git a/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyBrokerImpl.java b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyBrokerImpl.java new file mode 100644 index 0000000000..f5972142de --- /dev/null +++ b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyBrokerImpl.java @@ -0,0 +1,37 @@ +/* + * 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.openjpa; + +import javax.transaction.TransactionManager; + +import org.apache.openjpa.ee.ManagedRuntime; +import org.apache.openjpa.kernel.BrokerImpl; + +public class TuscanyBrokerImpl extends BrokerImpl { + private TransactionManager tm; + + public TuscanyBrokerImpl(TransactionManager tm) { + this.tm = tm; + } + + public ManagedRuntime getManagedRuntime() { + return new TuscanyManagerRuntime(tm); + } +} diff --git a/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyJDBCConfigurationImpl.java b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyJDBCConfigurationImpl.java new file mode 100644 index 0000000000..78de14cc1c --- /dev/null +++ b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyJDBCConfigurationImpl.java @@ -0,0 +1,58 @@ +/* + * 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.openjpa; + +import javax.sql.DataSource; +import javax.transaction.TransactionManager; + +import org.apache.openjpa.ee.ManagedRuntime; +import org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl; +import org.apache.openjpa.jdbc.sql.DBDictionary; +import org.apache.openjpa.jdbc.sql.DerbyDictionary; +import org.apache.openjpa.kernel.StoreContext; +import org.apache.openjpa.lib.conf.Configurations; + +public class TuscanyJDBCConfigurationImpl extends JDBCConfigurationImpl { + private TransactionManager tm; + + public TuscanyJDBCConfigurationImpl(TransactionManager tm,DataSource _ds) { + this.tm = tm; + ds2 = _ds; + } + public ManagedRuntime getManagedRuntimeInstance() { + return new TuscanyManagerRuntime(tm); + } + + public Object getConnectionFactory() { + return null; + } + + public DBDictionary getDBDictionaryInstance() { + DerbyDictionary dd = new DerbyDictionary(); + Configurations.configureInstance(dd, this, "", ""); + return dd; + } + private DataSource ds2; + @Override + public DataSource getDataSource2(StoreContext ctx) { + + return ds2; + } +} diff --git a/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyManagerRuntime.java b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyManagerRuntime.java new file mode 100644 index 0000000000..2fb35f83a1 --- /dev/null +++ b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyManagerRuntime.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.openjpa; +import javax.transaction.SystemException; +import javax.transaction.TransactionManager; + +import org.apache.openjpa.ee.ManagedRuntime; + +public class TuscanyManagerRuntime implements ManagedRuntime{ + public TuscanyManagerRuntime(TransactionManager tm){ + this.tm = tm; + } + public Throwable getRollbackCause() throws Exception { + // TODO Auto-generated method stub + return null; + } + + public Object getTransactionKey() throws Exception, SystemException { + // TODO Auto-generated method stub + return "Geng"; + } + private TransactionManager tm; + public TransactionManager getTransactionManager() throws Exception { + + + return tm; + } + + public void setRollbackOnly(Throwable cause) throws Exception { + // TODO Auto-generated method stub + + } + +} diff --git a/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyStoreManager.java b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyStoreManager.java new file mode 100644 index 0000000000..441ba666d7 --- /dev/null +++ b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyStoreManager.java @@ -0,0 +1,49 @@ +/* + * 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.openjpa; + +import java.sql.Connection; +import java.sql.SQLException; + +import javax.sql.XAConnection; + +import org.apache.openjpa.jdbc.kernel.JDBCStoreManager; + +public class TuscanyStoreManager extends JDBCStoreManager { + private XAConnection xaconn; + + public TuscanyStoreManager(XAConnection xaconn) { + this.xaconn = xaconn; + } + + protected _RefCountConnection connectInternal() throws SQLException { + Connection conn = xaconn.getConnection(); + // conn.setAutoCommit(false); + _RefCountConnection rc = new _RefCountConnection(conn); + return rc; + } + + class _RefCountConnection extends RefCountConnection { + public _RefCountConnection(Connection conn) { + + super(conn); + } + } +} diff --git a/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/java/org/apache/tuscany/sca/implementation/openjpa/impl/JPAImplementationFactoryImpl.java b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/java/org/apache/tuscany/sca/implementation/openjpa/impl/JPAImplementationFactoryImpl.java new file mode 100644 index 0000000000..2a7d1abd70 --- /dev/null +++ b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/java/org/apache/tuscany/sca/implementation/openjpa/impl/JPAImplementationFactoryImpl.java @@ -0,0 +1,39 @@ +/* + * 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.openjpa.impl; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.implementation.openjpa.*; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; + +public class JPAImplementationFactoryImpl implements JPAImplementationFactory { + private AssemblyFactory assemblyFactory; + private JavaInterfaceFactory javaFactory; + + public JPAImplementationFactoryImpl(AssemblyFactory aF, JavaInterfaceFactory javaIF) { + this.assemblyFactory = aF; + this.javaFactory = javaIF; + } + + public JPAImplementation createOpenJpaImplementation() { + return new JPAImplementationImpl(assemblyFactory, javaFactory); + } + +} diff --git a/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/java/org/apache/tuscany/sca/implementation/openjpa/impl/JPAImplementationImpl.java b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/java/org/apache/tuscany/sca/implementation/openjpa/impl/JPAImplementationImpl.java new file mode 100644 index 0000000000..055ecd4a4d --- /dev/null +++ b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/java/org/apache/tuscany/sca/implementation/openjpa/impl/JPAImplementationImpl.java @@ -0,0 +1,119 @@ +/* + * 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.openjpa.impl; + +import java.util.Collections; +import java.util.List; +import java.util.Properties; + +import javax.persistence.EntityManager; + +import org.apache.openjpa.persistence.PersistenceUnitInfoImpl; +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.ConstrainingType; +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.implementation.openjpa.JPAImplementation; +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; + +public class JPAImplementationImpl implements JPAImplementation { + private Service jpaService; + private PersistenceUnitInfoImpl puii; + private Properties dsmeta; + + public void setPersistenceUnitInfoImpl(PersistenceUnitInfoImpl puii) { + this.puii = puii; + } + + public PersistenceUnitInfoImpl getPersistenceUnitInfoImpl() { + return this.puii; + } + + public void setDataSourceMeta(Properties p) { + dsmeta = p; + } + + public Properties getDataSourceMeta() { + return dsmeta; + } + + JPAImplementationImpl(AssemblyFactory assemblyFactory, JavaInterfaceFactory javaFactory) { + + jpaService = assemblyFactory.createService(); + jpaService.setName("EntityManager"); + JavaInterface javaInterface; + try { + javaInterface = javaFactory.createJavaInterface(EntityManager.class); + } catch (InvalidInterfaceException e) { + throw new IllegalArgumentException(e); + } + JavaInterfaceContract interfaceContract = javaFactory.createJavaInterfaceContract(); + interfaceContract.setInterface(javaInterface); + jpaService.setInterfaceContract(interfaceContract); + } + + public boolean isUnresolved() { + // TODO Auto-generated method stub + return false; + } + + public void setUnresolved(boolean unresolved) { + // TODO Auto-generated method stub + + } + + public ConstrainingType getConstrainingType() { + // TODO Auto-generated method stub + return null; + } + + public List<Property> getProperties() { + // TODO Auto-generated method stub + return Collections.emptyList(); + } + + public List<Reference> getReferences() { + return Collections.emptyList(); + } + + public List<Service> getServices() { + return Collections.singletonList(jpaService); + } + + public String getURI() { + // TODO Auto-generated method stub + return null; + } + + public void setConstrainingType(ConstrainingType constrainingType) { + // TODO Auto-generated method stub + + } + + public void setURI(String uri) { + // TODO Auto-generated method stub + + } + +} diff --git a/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/java/org/apache/tuscany/sca/implementation/openjpa/provider/JPAImplementationProvider.java b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/java/org/apache/tuscany/sca/implementation/openjpa/provider/JPAImplementationProvider.java new file mode 100644 index 0000000000..5a863a8ae7 --- /dev/null +++ b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/java/org/apache/tuscany/sca/implementation/openjpa/provider/JPAImplementationProvider.java @@ -0,0 +1,96 @@ +/* + * 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.openjpa.provider; + +import java.util.HashMap; +import java.util.Map; + +import javax.persistence.EntityManagerFactory; +import javax.transaction.TransactionManager; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.openjpa.kernel.Bootstrap; +import org.apache.openjpa.kernel.BrokerFactory; +import org.apache.openjpa.persistence.JPAFacadeHelper; +import org.apache.openjpa.persistence.PersistenceUnitInfoImpl; +import org.apache.openjpa.persistence.PersistenceProductDerivation.ConfigurationProviderImpl; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.implementation.openjpa.JPAImplementation; +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; + +public class JPAImplementationProvider implements ImplementationProvider { + private RuntimeComponent component; + private JPAImplementation implementation; + private EntityManagerFactory emf; + private TransactionManager tm; + + public JPAImplementationProvider(RuntimeComponent component, + JPAImplementation implementation, + ExtensionPointRegistry extensionPoints) { + this.component = component; + this.implementation = implementation; + tm = (TransactionManager)extensionPoints.getExtensionPoint(org.apache.geronimo.transaction.manager.XAWork.class); + + initEntityManager(); + } + + private void initEntityManager() { + Map map = new HashMap(); + map.put("TransactionManager", tm); + PersistenceUnitInfoImpl _info = implementation.getPersistenceUnitInfoImpl(); + _info.fromUserProperties(map); + ConfigurationProviderImpl cp = new ConfigurationProviderImpl(); + cp.addProperties(_info.toOpenJPAProperties()); + cp.addProperties(implementation.getDataSourceMeta()); + + BrokerFactory factory = Bootstrap.newBrokerFactory(cp, null); + + emf = JPAFacadeHelper.toEntityManagerFactory(factory); + + } + + private Log log = LogFactory.getLog(this.getClass()); + + public Invoker createInvoker(RuntimeComponentService service, Operation operation) { + + return new JPAInvoker(operation, emf, tm); + } + + public void start() { + // TODO Auto-generated method stub + + } + + public void stop() { + // TODO Auto-generated method stub + + } + + public boolean supportsOneWayInvocation() { + // TODO Auto-generated method stub + return false; + } + +} diff --git a/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/java/org/apache/tuscany/sca/implementation/openjpa/provider/JPAImplementationProviderFactory.java b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/java/org/apache/tuscany/sca/implementation/openjpa/provider/JPAImplementationProviderFactory.java new file mode 100644 index 0000000000..e1e821113c --- /dev/null +++ b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/java/org/apache/tuscany/sca/implementation/openjpa/provider/JPAImplementationProviderFactory.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.openjpa.provider; + +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.implementation.openjpa.JPAImplementation; +import org.apache.tuscany.sca.provider.ImplementationProvider; +import org.apache.tuscany.sca.provider.ImplementationProviderFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +public class JPAImplementationProviderFactory implements ImplementationProviderFactory<JPAImplementation> { + private ExtensionPointRegistry extensionPointRegistry; + + public JPAImplementationProviderFactory(ExtensionPointRegistry extensionPoints) { + extensionPointRegistry = extensionPoints; + } + + public ImplementationProvider createImplementationProvider(RuntimeComponent component, + JPAImplementation implementation) { + return new JPAImplementationProvider(component, implementation, extensionPointRegistry); + } + + public Class<JPAImplementation> getModelType() { + return JPAImplementation.class; + } + +} diff --git a/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/java/org/apache/tuscany/sca/implementation/openjpa/provider/JPAInvoker.java b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/java/org/apache/tuscany/sca/implementation/openjpa/provider/JPAInvoker.java new file mode 100644 index 0000000000..8b74209d3e --- /dev/null +++ b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/java/org/apache/tuscany/sca/implementation/openjpa/provider/JPAInvoker.java @@ -0,0 +1,63 @@ +/* + * 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.openjpa.provider; + +import java.lang.reflect.Method; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.transaction.TransactionManager; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.java.impl.JavaInterfaceUtil; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; + +public class JPAInvoker implements Invoker { + private Operation operation; + private TransactionManager tm; + + public JPAInvoker(Operation operation, EntityManagerFactory emf, TransactionManager tm) { + this.operation = operation; + this.tm = tm; + this.emf = emf; + } + + private Log log = LogFactory.getLog(this.getClass()); + private EntityManagerFactory emf; + + public Message invoke(Message msg) { + try { + tm.begin(); + Method method = JavaInterfaceUtil.findMethod(EntityManager.class, operation); + Object r = method.invoke(emf.createEntityManager(), (Object[])msg.getBody()); + tm.commit(); + log.info(method); + msg.setBody(r); + return msg; + } catch (Exception ex) { + throw new RuntimeException(ex); + + } + } + +} diff --git a/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..8c82832e01 --- /dev/null +++ b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/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.openjpa.JPAImplementationProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#implementation.data.pojo,model=org.apache.tuscany.sca.implementation.openjpa.JPAImplementation
\ No newline at end of file diff --git a/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.openjpa.OpenJpaImplementationFactory b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.openjpa.OpenJpaImplementationFactory new file mode 100644 index 0000000000..13067543c9 --- /dev/null +++ b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.openjpa.OpenJpaImplementationFactory @@ -0,0 +1,18 @@ +# 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.
+
+org.apache.tuscany.sca.implementation.openjpa.impl.JPAImplementationFactoryImpl
\ No newline at end of file diff --git a/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory new file mode 100644 index 0000000000..fb62ff853b --- /dev/null +++ b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/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.openjpa.provider.JPAImplementationProviderFactory;model=org.apache.tuscany.sca.implementation.openjpa.JPAImplementation
\ No newline at end of file diff --git a/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/test/java/company/Company.java b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/test/java/company/Company.java new file mode 100644 index 0000000000..3ea6e65c0d --- /dev/null +++ b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/test/java/company/Company.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 company; + +import javax.persistence.*; + +@Entity +public class Company { + @Id private int id; + @Basic private String name; + + public int getId() { + return id; + } + + public void setId(int i) { + id = i; + } + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + + public String toString() { + return "Company (" + getId() + ") is is " + getName(); + } +} diff --git a/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/test/java/company/CompanyCollection.java b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/test/java/company/CompanyCollection.java new file mode 100644 index 0000000000..b74f53aa8b --- /dev/null +++ b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/test/java/company/CompanyCollection.java @@ -0,0 +1,25 @@ +/* + * 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 company; + +import org.apache.tuscany.sca.implementation.data.collection.Collection; + +public interface CompanyCollection extends Collection<String, Company> { + +} diff --git a/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/test/java/company/CompanyCollectionImpl.java b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/test/java/company/CompanyCollectionImpl.java new file mode 100644 index 0000000000..385defeb0b --- /dev/null +++ b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/test/java/company/CompanyCollectionImpl.java @@ -0,0 +1,100 @@ +/* + * 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 company; + +import java.util.Iterator; +import java.util.List; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.EntityTransaction; +import javax.persistence.Persistence; +import javax.persistence.Query; + +import org.apache.tuscany.sca.implementation.data.collection.Entry; +import org.apache.tuscany.sca.implementation.data.collection.NotFoundException; + +public class CompanyCollectionImpl implements CompanyCollection { + EntityManagerFactory emf = null; + EntityManager em = null; + + public CompanyCollectionImpl() { + System.out.println(">>>"); + try { + emf = Persistence.createEntityManagerFactory("company-openJPA"); + em = emf.createEntityManager(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void delete(String arg0) throws NotFoundException { + // TODO Auto-generated method stub + + } + + public Company get(String arg0) throws NotFoundException { + // TODO Auto-generated method stub + return null; + } + + public Entry<String, Company>[] getAll() { + EntityTransaction tx = em.getTransaction(); + try { + tx.begin(); + + Query q = em.createQuery("SELECT c FROM company c"); + List results = q.getResultList(); + Iterator iter = results.iterator(); + while (iter.hasNext()) { + Company company = (Company)iter.next(); + + System.out.println(company); + } + + tx.commit(); + } catch(Exception e) { + e.printStackTrace(); + } finally { + if (tx.isActive()) { + tx.rollback(); + } + + em.close(); + } + + return null; + } + + public String post(String arg0, Company arg1) { + // TODO Auto-generated method stub + return null; + } + + public void put(String arg0, Company arg1) throws NotFoundException { + // TODO Auto-generated method stub + + } + + public Entry<String, Company>[] query(String arg0) { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/test/java/org/apache/tuscany/sca/implementation/openjpa/CompanyCollectionTestCase.java b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/test/java/org/apache/tuscany/sca/implementation/openjpa/CompanyCollectionTestCase.java new file mode 100644 index 0000000000..bc9fbb3543 --- /dev/null +++ b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/test/java/org/apache/tuscany/sca/implementation/openjpa/CompanyCollectionTestCase.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.openjpa; + +import junit.framework.TestCase; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import company.CompanyCollection; +import company.CompanyCollectionImpl; + +public class CompanyCollectionTestCase extends TestCase { + private Log log = LogFactory.getLog(this.getClass()); + private CompanyCollection collection = null; + + public void setUp() { + collection = new CompanyCollectionImpl(); + } + + public void testGetAll() { + collection.getAll(); + } + + public void tearDown() { + + } +} diff --git a/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/test/java/org/apache/tuscany/sca/implementation/openjpa/CompanyTestCase.java b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/test/java/org/apache/tuscany/sca/implementation/openjpa/CompanyTestCase.java new file mode 100644 index 0000000000..1c4d6fb254 --- /dev/null +++ b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/test/java/org/apache/tuscany/sca/implementation/openjpa/CompanyTestCase.java @@ -0,0 +1,80 @@ +/* + * 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.openjpa; + +import junit.framework.*; +import org.apache.tuscany.sca.host.embedded.*; +import org.apache.commons.logging.*; + +import company.*; + +import javax.persistence.*; +import java.util.*; + +public class CompanyTestCase extends TestCase { + private EntityManager em; + private Log log = LogFactory.getLog(this.getClass()); + private SCADomain domain; + + public void setUp() { + domain = SCADomain.newInstance("openjpa.composite"); + em = domain.getService(EntityManager.class, "CompanyServiceComponent"); + + } + + public void testAccess() { + Company company = new Company(); + int id = new Random().nextInt(); + + company.setId(id); + company.setName("Company " + id); + + em.persist(company); + log.info(em.find(Company.class, id)); + + Query q = em.createQuery("select company from Company company"); + q.setMaxResults(5); + log.info("There are " + q.getResultList().size() + " Company in the database now"); + } + + public void testRollback() { + try { + Company company1 = new Company(); + Company company2 = new Company(); + + int id = new Random().nextInt(); + + company1.setId(id); + company1.setName("Company " + id); + em.persist(company1); + + company2.setId(id); + company2.setName("Company " + id); + em.persist(company2); + + } catch (RuntimeException ex) { + log.info("An expected exception occured, Tuscany is rolling back..."); + } + } + + public void tearDown() { + em.close(); + domain.close(); + } +} diff --git a/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/test/resources/META-INF/orm.xml b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/test/resources/META-INF/orm.xml new file mode 100644 index 0000000000..75e329964f --- /dev/null +++ b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/test/resources/META-INF/orm.xml @@ -0,0 +1,36 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!-- + * 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. +--> + +<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd" + version="1.0"> + <entity class="company.Company" name="company"> + <table name="COMPANY"/> + <attributes> + <id name="id"> + <generated-value strategy="TABLE"/> + </id> + <basic name="name"> + <column name="NAME" length="30"/> + </basic> + </attributes> + </entity> +</entity-mappings>
\ No newline at end of file diff --git a/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/test/resources/META-INF/persistence.xml b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/test/resources/META-INF/persistence.xml new file mode 100644 index 0000000000..302fbfe845 --- /dev/null +++ b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/test/resources/META-INF/persistence.xml @@ -0,0 +1,40 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!-- + * 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. +--> + +<persistence xmlns="http://java.sun.com/xml/ns/persistence" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/persistence + http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0"> + + <persistence-unit name="company-openJPA"> + <!--mapping-file>orm.xml</mapping-file--> + <class>company.Company</class> + + <properties> + <property name="openjpa.ConnectionDriverName" value="org.apache.derby.jdbc.EmbeddedDriver"/> + <property name="openjpa.ConnectionURL" value="jdbc:derby:target/test-classes/company"/> + <property name="openjpa.ConnectionUserName" value=""/> + <property name="openjpa.ConnectionPassword" value=""/> + + <property name="openjpa.Log" value="DefaultLevel=TRACE, Tool=TRACE"/> + </properties> + </persistence-unit> + +</persistence>
\ No newline at end of file diff --git a/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/test/resources/company.composite b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/test/resources/company.composite new file mode 100755 index 0000000000..fd164d2519 --- /dev/null +++ b/sandbox/lresende/sca-1.x/modules/implementation-data-pojo/src/test/resources/company.composite @@ -0,0 +1,47 @@ +<?xml version="1.0" encoding="ASCII"?> +<!-- + * 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. +--> + +<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" + xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0" + targetNamespace="http://sample/openjpa" + name="company"> + + <component name="CompanyServiceComponent"> + <tuscany:implementation.data.pojo> + + <tuscany:persistence-unit name="company"> + <tuscany:openjpa.BrokerFactory>org.apache.tuscany.sca.implementation.openjpa.TuscanyBrokerFactory</tuscany:openjpa.BrokerFactory> + <tuscany:openjpa.TransactionMode>managed</tuscany:openjpa.TransactionMode> + <tuscany:openjpa.Log>DefaultLevel=WARN,SQL=TRACE</tuscany:openjpa.Log> + <tuscany:openjpa.jdbc.SynchronizeMappings>buildSchema</tuscany:openjpa.jdbc.SynchronizeMappings> + + <tuscany:class>company.Company</tuscany:class> + </tuscany:persistence-unit> + + <tuscany:connectionInfo> + <tuscany:connectionProperties + driverClass="org.apache.derby.jdbc.EmbeddedDriver" + databaseURL="jdbc:derby:target/test-classes/company; create = true" + loginTimeout="600000"/> + </tuscany:connectionInfo> + </tuscany:implementation.data.pojo> + </component> + +</composite> |