tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblev...@apache.org
Subject svn commit: r682528 - in /openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb: config/AppInfoBuilder.java util/MakeTxLookup.java
Date Mon, 04 Aug 2008 22:14:00 GMT
Author: dblevins
Date: Mon Aug  4 15:14:00 2008
New Revision: 682528

URL: http://svn.apache.org/viewvc?rev=682528&view=rev
Log:
OPENEJB-880: Automatically set toplink.target-server for TopLink
OPENEJB-881: Automatically set eclipselink.target-server for EclipseLink

Modified:
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/MakeTxLookup.java

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java?rev=682528&r1=682527&r2=682528&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java
(original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java
Mon Aug  4 15:14:00 2008
@@ -38,6 +38,7 @@
 import org.apache.openejb.util.Logger;
 import org.apache.openejb.util.LogCategory;
 import org.apache.openejb.util.Messages;
+import org.apache.openejb.util.MakeTxLookup;
 import org.apache.openejb.jee.oejb3.EjbDeployment;
 import org.apache.openejb.jee.jpa.unit.Persistence;
 import org.apache.openejb.jee.jpa.unit.PersistenceUnit;
@@ -469,17 +470,21 @@
                     }
                 }
 
-                if ("org.hibernate.ejb.HibernatePersistence".equals(info.provider)){
 
-                    // The result is that OpenEJB-specific configuration can be avoided when
-                    // using OpenEJB + Hibernate.  A second benefit is that if another vendor
-                    // is used in production, the value will automatically be reset for using
-                    // OpenEJB in the test environment.  Ensuring the strategy starts with
-                    // "org.hibernate.transaction" allows for a custom lookup strategy to
be
-                    // used and not overridden.
+                // The result is that OpenEJB-specific configuration can be avoided when
+                // using OpenEJB + Hibernate or another vendor.  A second benefit is that
+                // if another vendor is used in production, the value will automatically
+                // be reset for using OpenEJB in the test environment.  Ensuring the strategy
+                // doesn't start with "org.hibernate.transaction" allows for a custom lookup
+                // strategy to be used and not overridden.
+
+                // DMB: This whole block could be a map, but I left it this way just
+                // in case we decided we wanted to do other custom handing for the
+                // providers listed.
+                if ("org.hibernate.ejb.HibernatePersistence".equals(info.provider)){
 
                     String lookupProperty = "hibernate.transaction.manager_lookup_class";
-                    String openejbLookupClass = "org.apache.openejb.hibernate.TransactionManagerLookup";
+                    String openejbLookupClass = MakeTxLookup.HIBERNATE_FACTORY;
 
                     String className = info.properties.getProperty(lookupProperty);
 
@@ -487,6 +492,28 @@
                         info.properties.setProperty(lookupProperty, openejbLookupClass);
                         logger.debug("Adjusting PersistenceUnit(name="+info.name+") property
to "+lookupProperty+"="+openejbLookupClass);
                     }
+                } else if ("oracle.toplink.essentials.PersistenceProvider".equals(info.provider)){
+
+                    String lookupProperty = "toplink.target-server";
+                    String openejbLookupClass = MakeTxLookup.TOPLINK_FACTORY;
+
+                    String className = info.properties.getProperty(lookupProperty);
+
+                    if (className == null || className.startsWith("oracle.toplink.transaction")){
+                        info.properties.setProperty(lookupProperty, openejbLookupClass);
+                        logger.debug("Adjusting PersistenceUnit(name="+info.name+") property
to "+lookupProperty+"="+openejbLookupClass);
+                    }
+                } else if ("org.eclipse.persistence.jpa.PersistenceProvider".equals(info.provider)){
+
+                    String lookupProperty = "eclipselink.target-server";
+                    String openejbLookupClass = MakeTxLookup.ECLIPSELINK_FACTORY;
+
+                    String className = info.properties.getProperty(lookupProperty);
+
+                    if (className == null || className.startsWith("org.eclipse.persistence.transaction")){
+                        info.properties.setProperty(lookupProperty, openejbLookupClass);
+                        logger.debug("Adjusting PersistenceUnit(name="+info.name+") property
to "+lookupProperty+"="+openejbLookupClass);
+                    }
                 }
 
                 // Persistence Unit Root Url

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/MakeTxLookup.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/MakeTxLookup.java?rev=682528&r1=682527&r2=682528&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/MakeTxLookup.java
(original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/MakeTxLookup.java
Mon Aug  4 15:14:00 2008
@@ -16,40 +16,43 @@
  */
 package org.apache.openejb.util;
 
-import org.objectweb.asm.AnnotationVisitor;
 import org.objectweb.asm.ClassWriter;
-import org.objectweb.asm.FieldVisitor;
 import org.objectweb.asm.MethodVisitor;
 import org.objectweb.asm.Opcodes;
 
 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 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]);
 
-        String[] path = {"classes", "org", "apache", "openejb", "hibernate", "TransactionManagerLookup.class"};
-        for (String s : path) file = new File(file, s);
+        File file = new File(args[0]);
 
-        file.getParentFile().mkdirs();
-        
-        FileOutputStream out = new FileOutputStream(file);
-        out.write(dump());
-        out.close();
+        createHibernteStrategy(file);
+        createTopLinkStrategy(file);
+        createEclipseLinkStrategy(file);
     }
 
-    public static byte[] dump() throws Exception {
+    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(false);
-        FieldVisitor fv;
         MethodVisitor mv;
-        AnnotationVisitor av0;
 
-        cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, "org/apache/openejb/hibernate/TransactionManagerLookup",
null, "java/lang/Object", new String[]{"org/hibernate/transaction/TransactionManagerLookup"});
+        cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, classFilePath, null, "java/lang/Object", new
String[]{"org/hibernate/transaction/TransactionManagerLookup"});
 
-        cw.visitSource("TransactionManagerLookup.java", null);
+        cw.visitSource(sourceFileName, null);
 
         {
             mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
@@ -78,6 +81,98 @@
         }
         cw.visitEnd();
 
-        return cw.toByteArray();
+
+        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(false);
+        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, "org/apache/openejb/util/ToplinkJTATransactionController",
"<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(false);
+        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/apache/openejb/util/ToplinkJTATransactionController",
"<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();
+    }
+
 }



Mime
View raw message