Author: rmannibucau
Date: Thu Jun 21 09:29:35 2012
New Revision: 1352476
URL: http://svn.apache.org/viewvc?rev=1352476&view=rev
Log:
TOMEE-251 extracting openejb integration with jpa provider to be able to import
it in a webapp if it provides the jpa provider
Added:
openejb/trunk/openejb/container/openejb-jpa-integration/
openejb/trunk/openejb/container/openejb-jpa-integration/pom.xml
openejb/trunk/openejb/container/openejb-jpa-integration/src/
openejb/trunk/openejb/container/openejb-jpa-integration/src/main/
openejb/trunk/openejb/container/openejb-jpa-integration/src/main/java/
openejb/trunk/openejb/container/openejb-jpa-integration/src/main/java/org/
openejb/trunk/openejb/container/openejb-jpa-integration/src/main/java/org/apache/
openejb/trunk/openejb/container/openejb-jpa-integration/src/main/java/org/apache/openejb/
openejb/trunk/openejb/container/openejb-jpa-integration/src/main/java/org/apache/openejb/jpa/
openejb/trunk/openejb/container/openejb-jpa-integration/src/main/java/org/apache/openejb/jpa/integration/
openejb/trunk/openejb/container/openejb-jpa-integration/src/main/java/org/apache/openejb/jpa/integration/MakeTxLookup.java
openejb/trunk/openejb/container/openejb-jpa-integration/src/test/
openejb/trunk/openejb/container/openejb-jpa-integration/src/test/java/
Removed:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/MakeTxLookup.java
Modified:
openejb/trunk/openejb/container/openejb-core/pom.xml
openejb/trunk/openejb/container/pom.xml
Modified: openejb/trunk/openejb/container/openejb-core/pom.xml
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/pom.xml?rev=1352476&r1=1352475&r2=1352476&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/pom.xml (original)
+++ openejb/trunk/openejb/container/openejb-core/pom.xml Thu Jun 21 09:29:35
2012
@@ -327,13 +327,6 @@
token="@DATE-REPLACED-BY-MAVEN@" value="${DSTAMP}"/>
<replace file="target/classes/openejb-version.properties"
token="@TIME-REPLACED-BY-MAVEN@" value="${TSTAMP}"/>
- <property name="compile_classpath"
refid="maven.compile.classpath"/>
- <java classname="org.apache.openejb.util.MakeTxLookup">
- <arg value="${project.build.directory}"/>
- <classpath>
- <pathelement path="${compile_classpath}"/>
- </classpath>
- </java>
</target>
</configuration>
</execution>
@@ -382,6 +375,11 @@
</dependency>
<dependency>
<groupId>org.apache.openejb</groupId>
+ <artifactId>openejb-jpa-integration</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.openejb</groupId>
<artifactId>javaee-api</artifactId>
</dependency>
<!-- required for endorsed dir support -->
Added: openejb/trunk/openejb/container/openejb-jpa-integration/pom.xml
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-jpa-integration/pom.xml?rev=1352476&view=auto
==============================================================================
--- openejb/trunk/openejb/container/openejb-jpa-integration/pom.xml (added)
+++ openejb/trunk/openejb/container/openejb-jpa-integration/pom.xml Thu Jun 21
09:29:35 2012
@@ -0,0 +1,67 @@
+<?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 xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>container</artifactId>
+ <groupId>org.apache.openejb</groupId>
+ <version>4.1.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>openejb-jpa-integration</artifactId>
+ <name>OpenEJB :: Container :: Core</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.xbean</groupId>
+ <artifactId>xbean-asm-shaded</artifactId>
+ <version>${xbeanVersion}</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <version>1.2.1</version>
+ <executions>
+ <execution>
+ <id>generate-integration</id>
+ <phase>process-classes</phase>
+ <goals>
+ <goal>java</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+
<mainClass>org.apache.openejb.jpa.integration.MakeTxLookup</mainClass>
+ <classpathScope>compile</classpathScope>
+ <arguments>
+ <argument>${project.build.directory}</argument>
+ </arguments>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Added:
openejb/trunk/openejb/container/openejb-jpa-integration/src/main/java/org/apache/openejb/jpa/integration/MakeTxLookup.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-jpa-integration/src/main/java/org/apache/openejb/jpa/integration/MakeTxLookup.java?rev=1352476&view=auto
==============================================================================
---
openejb/trunk/openejb/container/openejb-jpa-integration/src/main/java/org/apache/openejb/jpa/integration/MakeTxLookup.java
(added)
+++
openejb/trunk/openejb/container/openejb-jpa-integration/src/main/java/org/apache/openejb/jpa/integration/MakeTxLookup.java
Thu Jun 21 09:29:35 2012
@@ -0,0 +1,246 @@
+/*
+ * 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.openejb.jpa.integration;
+
+import org.apache.xbean.asm.ClassWriter;
+import org.apache.xbean.asm.Label;
+import org.apache.xbean.asm.MethodVisitor;
+import org.apache.xbean.asm.Opcodes;
+import org.apache.xbean.asm.Type;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+public class MakeTxLookup implements Opcodes {
+
+ public static final String HIBERNATE_FACTORY =
"org.apache.openejb.hibernate.TransactionManagerLookup";
+ public static final String HIBERNATE_NEW_FACTORY =
"org.apache.openejb.hibernate.OpenEJBJtaPlatform";
+ public static final String TOPLINK_FACTORY =
"org.apache.openejb.toplink.JTATransactionController";
+ public static final String ECLIPSELINK_FACTORY =
"org.apache.openejb.eclipselink.JTATransactionController";
+
+ public static void main(String[] args) throws Exception {
+
+ File file = new File(args[0]);
+
+ createHibernteStrategy(file);
+ createNewHibernateStrategy(file);
+ createTopLinkStrategy(file);
+ createEclipseLinkStrategy(file);
+ }
+
+ private static void createNewHibernateStrategy(File basedir) throws
Exception {
+ ClassWriter cw = new ClassWriter(0);
+ MethodVisitor mv;
+
+ cw.visit(V1_6, ACC_PUBLIC + ACC_SUPER,
"org/apache/openejb/hibernate/OpenEJBJtaPlatform", null,
"org/hibernate/service/jta/platform/internal/AbstractJtaPlatform", null);
+
+ {
+ mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
+ mv.visitCode();
+ mv.visitVarInsn(ALOAD, 0);
+ mv.visitMethodInsn(INVOKESPECIAL,
"org/hibernate/service/jta/platform/internal/AbstractJtaPlatform", "<init>",
"()V");
+ mv.visitInsn(RETURN);
+ mv.visitMaxs(1, 1);
+ mv.visitEnd();
+ }
+ {
+ mv = cw.visitMethod(ACC_PROTECTED, "locateTransactionManager",
"()Ljavax/transaction/TransactionManager;", null, null);
+ mv.visitCode();
+ mv.visitMethodInsn(INVOKESTATIC, "org/apache/openejb/OpenEJB",
"getTransactionManager", "()Ljavax/transaction/TransactionManager;");
+ mv.visitInsn(ARETURN);
+ mv.visitMaxs(1, 1);
+ mv.visitEnd();
+ }
+ {
+ mv = cw.visitMethod(ACC_PROTECTED, "locateUserTransaction",
"()Ljavax/transaction/UserTransaction;", null, null);
+ mv.visitCode();
+ Label l0 = new Label();
+ Label l1 = new Label();
+ Label l2 = new Label();
+ mv.visitTryCatchBlock(l0, l1, l2, "javax/naming/NamingException");
+ mv.visitLabel(l0);
+ mv.visitMethodInsn(INVOKESTATIC,
"org/apache/openejb/loader/SystemInstance", "get",
"()Lorg/apache/openejb/loader/SystemInstance;");
+
mv.visitLdcInsn(Type.getType("Lorg/apache/openejb/spi/ContainerSystem;"));
+ mv.visitMethodInsn(INVOKEVIRTUAL,
"org/apache/openejb/loader/SystemInstance", "getComponent",
"(Ljava/lang/Class;)Ljava/lang/Object;");
+ mv.visitTypeInsn(CHECKCAST,
"org/apache/openejb/spi/ContainerSystem");
+ mv.visitMethodInsn(INVOKEINTERFACE,
"org/apache/openejb/spi/ContainerSystem", "getJNDIContext",
"()Ljavax/naming/Context;");
+ mv.visitLdcInsn("comp/UserTransaction");
+ mv.visitMethodInsn(INVOKEINTERFACE, "javax/naming/Context",
"lookup", "(Ljava/lang/String;)Ljava/lang/Object;");
+ mv.visitTypeInsn(CHECKCAST, "javax/transaction/UserTransaction");
+ mv.visitLabel(l1);
+ mv.visitInsn(ARETURN);
+ mv.visitLabel(l2);
+ mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new
Object[]{"javax/naming/NamingException"});
+ mv.visitVarInsn(ASTORE, 1);
+ mv.visitInsn(ACONST_NULL);
+ mv.visitInsn(ARETURN);
+ mv.visitMaxs(2, 2);
+ mv.visitEnd();
+ }
+ cw.visitEnd();
+
+ String factory = HIBERNATE_NEW_FACTORY;
+ String classFilePath = factory.replace('.', '/');
+ write(basedir, cw, classFilePath);
+ }
+
+ private static void createHibernteStrategy(File baseDir) throws Exception {
+
+ String factory = HIBERNATE_FACTORY;
+
+ String classFilePath = factory.replace('.', '/');
+
+ String sourceFileName = factory.substring(factory.lastIndexOf('.') +
1, factory.length()) + ".java";
+
+ ClassWriter cw = new ClassWriter(0);
+ MethodVisitor mv;
+
+ cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, classFilePath, null,
"java/lang/Object", new
String[]{"org/hibernate/transaction/TransactionManagerLookup"});
+
+ cw.visitSource(sourceFileName, null);
+
+ {
+ mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
+ mv.visitCode();
+ mv.visitVarInsn(ALOAD, 0);
+ mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>",
"()V");
+ mv.visitInsn(RETURN);
+ mv.visitMaxs(1, 1);
+ mv.visitEnd();
+ }
+ {
+ mv = cw.visitMethod(ACC_PUBLIC, "getTransactionManager",
"(Ljava/util/Properties;)Ljavax/transaction/TransactionManager;", null, new
String[]{"org/hibernate/HibernateException"});
+ mv.visitCode();
+ mv.visitMethodInsn(INVOKESTATIC, "org/apache/openejb/OpenEJB",
"getTransactionManager", "()Ljavax/transaction/TransactionManager;");
+ mv.visitInsn(ARETURN);
+ mv.visitMaxs(1, 2);
+ mv.visitEnd();
+ }
+ {
+ mv = cw.visitMethod(ACC_PUBLIC, "getUserTransactionName",
"()Ljava/lang/String;", null, null);
+ mv.visitCode();
+ mv.visitLdcInsn("java:comp/UserTransaction");
+ mv.visitInsn(ARETURN);
+ mv.visitMaxs(1, 1);
+ mv.visitEnd();
+ }
+ {
+ mv = cw.visitMethod(ACC_PUBLIC, "getTransactionIdentifier",
"(Ljavax/transaction/Transaction;)Ljava/lang/Object;", null, null);
+ mv.visitCode();
+ mv.visitVarInsn(ALOAD, 1);
+ mv.visitInsn(ARETURN);
+ mv.visitMaxs(1, 2);
+ mv.visitEnd();
+ }
+ cw.visitEnd();
+
+
+ write(baseDir, cw, classFilePath);
+ }
+
+ private static void createTopLinkStrategy(File baseDir) throws Exception {
+
+ String factory = TOPLINK_FACTORY;
+
+ String classFilePath = factory.replace('.', '/');
+
+ String sourceFileName = factory.substring(factory.lastIndexOf('.') +
1, factory.length()) + ".java";
+
+
+ ClassWriter cw = new ClassWriter(0);
+ MethodVisitor mv;
+
+ cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, classFilePath, null,
"oracle/toplink/essentials/transaction/JTATransactionController", null);
+
+ cw.visitSource(sourceFileName, null);
+
+ {
+ mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
+ mv.visitCode();
+ mv.visitVarInsn(ALOAD, 0);
+ mv.visitMethodInsn(INVOKESPECIAL,
"oracle/toplink/essentials/transaction/JTATransactionController", "<init>",
"()V");
+ mv.visitInsn(RETURN);
+ mv.visitMaxs(1, 1);
+ mv.visitEnd();
+ }
+ {
+ mv = cw.visitMethod(ACC_PROTECTED, "acquireTransactionManager",
"()Ljavax/transaction/TransactionManager;", null, new
String[]{"java/lang/Exception"});
+ mv.visitCode();
+ mv.visitMethodInsn(INVOKESTATIC, "org/apache/openejb/OpenEJB",
"getTransactionManager", "()Ljavax/transaction/TransactionManager;");
+ mv.visitInsn(ARETURN);
+ mv.visitMaxs(1, 1);
+ mv.visitEnd();
+ }
+ cw.visitEnd();
+
+
+ write(baseDir, cw, classFilePath);
+ }
+
+ private static void createEclipseLinkStrategy(File baseDir) throws
Exception {
+
+ String factory = ECLIPSELINK_FACTORY;
+
+ String classFilePath = factory.replace('.', '/');
+
+ String sourceFileName = factory.substring(factory.lastIndexOf('.') +
1, factory.length()) + ".java";
+
+
+ ClassWriter cw = new ClassWriter(0);
+ MethodVisitor mv;
+
+ cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, classFilePath, null,
"org/eclipse/persistence/transaction/JTATransactionController", null);
+
+ cw.visitSource(sourceFileName, null);
+
+ {
+ mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
+ mv.visitCode();
+ mv.visitVarInsn(ALOAD, 0);
+ mv.visitMethodInsn(INVOKESPECIAL,
"org/eclipse/persistence/transaction/JTATransactionController", "<init>",
"()V");
+ mv.visitInsn(RETURN);
+ mv.visitMaxs(1, 1);
+ mv.visitEnd();
+ }
+ {
+ mv = cw.visitMethod(ACC_PROTECTED, "acquireTransactionManager",
"()Ljavax/transaction/TransactionManager;", null, new
String[]{"java/lang/Exception"});
+ mv.visitCode();
+ mv.visitMethodInsn(INVOKESTATIC, "org/apache/openejb/OpenEJB",
"getTransactionManager", "()Ljavax/transaction/TransactionManager;");
+ mv.visitInsn(ARETURN);
+ mv.visitMaxs(1, 1);
+ mv.visitEnd();
+ }
+ cw.visitEnd();
+
+
+ write(baseDir, cw, classFilePath);
+ }
+
+ private static void write(File file, ClassWriter cw, String classFileName)
throws IOException {
+ classFileName = "classes/" + classFileName + ".class";
+
+ for (String part : classFileName.split("/")) file = new File(file,
part);
+
+ file.getParentFile().mkdirs();
+
+ FileOutputStream out = new FileOutputStream(file);
+ out.write(cw.toByteArray());
+ out.close();
+ }
+
+}
Modified: openejb/trunk/openejb/container/pom.xml
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/pom.xml?rev=1352476&r1=1352475&r2=1352476&view=diff
==============================================================================
--- openejb/trunk/openejb/container/pom.xml (original)
+++ openejb/trunk/openejb/container/pom.xml Thu Jun 21 09:29:35 2012
@@ -36,5 +36,6 @@
<module>openejb-jee-accessors</module>
<module>openejb-junit</module>
<module>openejb-jsf</module>
+ <module>openejb-jpa-integration</module>
</modules>
</project>
\ No newline at end of file