You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by da...@apache.org on 2006/12/30 02:40:08 UTC

svn commit: r491149 [2/3] - in /incubator/openejb/trunk/openejb3: assembly/openejb-standalone/src/main/resources/ container/ container/openejb-core/ container/openejb-core/src/main/java/org/apache/openejb/alt/config/ container/openejb-core/src/main/jav...

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/JpaTest.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/JpaTest.java?view=diff&rev=491149&r1=491148&r2=491149
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/JpaTest.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/JpaTest.java Fri Dec 29 17:40:06 2006
@@ -17,46 +17,44 @@
  */
 package org.apache.openejb.core.cmp.jpa;
 
+import java.lang.instrument.ClassFileTransformer;
+import java.lang.instrument.Instrumentation;
+import java.lang.reflect.InvocationTargetException;
+import java.security.ProtectionDomain;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.HashMap;
+import java.util.Properties;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.spi.PersistenceProvider;
+import javax.persistence.spi.PersistenceUnitTransactionType;
+import javax.sql.DataSource;
+import javax.transaction.TransactionManager;
+
 import junit.framework.TestCase;
 import org.apache.commons.dbcp.BasicDataSource;
 import org.apache.geronimo.transaction.manager.GeronimoTransactionManager;
+import org.apache.openejb.javaagent.Agent;
 import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.persistence.PersistenceClassLoaderHandler;
 import org.apache.openejb.persistence.PersistenceUnitInfoImpl;
+import org.apache.openejb.core.TemporaryClassLoader;
 import org.apache.openejb.resource.SharedLocalConnectionManager;
 import org.apache.openejb.resource.jdbc.JdbcManagedConnectionFactory;
-import org.apache.openejb.test.entity.cmp2.Employee;
-import org.apache.openejb.test.entity.cmr.onetoone.ABean_JPA;
-import org.apache.openejb.test.entity.cmr.onetoone.BBean_JPA;
-import org.apache.openjpa.event.AbstractLifecycleListener;
-import org.apache.openjpa.event.LifecycleEvent;
-import org.apache.openjpa.persistence.OpenJPAEntityManager;
 import org.apache.openjpa.persistence.PersistenceProviderImpl;
-
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.EntityTransaction;
-import javax.persistence.spi.PersistenceProvider;
-import javax.persistence.spi.PersistenceUnitTransactionType;
-import javax.sql.DataSource;
-import javax.transaction.TransactionManager;
-import javax.transaction.Status;
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Properties;
+import org.objectweb.asm.ClassAdapter;
+import org.objectweb.asm.ClassReader;
+import org.objectweb.asm.ClassVisitor;
+import org.objectweb.asm.ClassWriter;
+import static org.objectweb.asm.Opcodes.ACC_PRIVATE;
+import static org.objectweb.asm.Opcodes.ACC_TRANSIENT;
 
 public class JpaTest extends TestCase {
     private PersistenceUnitTransactionType transactionType;
-    private EntityTransaction transaction;
     private TransactionManager transactionManager;
-    private EntityManager entityManager;
     private DataSource jtaDs;
     private DataSource nonJtaDs;
-    private int davidPk;
     private EntityManagerFactory entityManagerFactory;
 
     public void setUp() throws Exception {
@@ -74,7 +72,11 @@
         initializeDatabase(jtaDs);
     }
 
-    protected void tearDown() throws Exception {
+    public void tearDown() throws Exception {
+        if (entityManagerFactory != null && entityManagerFactory.isOpen()) {
+            entityManagerFactory.close();
+        }
+
         if (nonJtaDs != null) {
             Connection connection = nonJtaDs.getConnection();
             Statement statement = connection.createStatement();
@@ -83,170 +85,77 @@
             close(connection);
         }
 
-        if (entityManager != null && entityManager.isOpen()) {
-            if (transactionType == PersistenceUnitTransactionType.RESOURCE_LOCAL) {
-                try {
-                    entityManager.getTransaction().commit();
-                } catch (Exception e) {
-                    e.printStackTrace();
-                }
-            } else {
-                try {
-                    if (transactionManager.getStatus() != Status.STATUS_NO_TRANSACTION) {
-                        transactionManager.rollback();
-                    }
-                } catch (Exception e) {
-                    e.printStackTrace();
-                }
-            }
-            entityManager.close();
-        }
-        if (entityManagerFactory != null && entityManagerFactory.isOpen()) {
-            entityManagerFactory.close();
-        }
         nonJtaDs = null;
         jtaDs = null;
-        entityManager = null;
+
         super.tearDown();
     }
 
     public void testJta() throws Exception {
         transactionType = PersistenceUnitTransactionType.JTA;
-        jpaLifecycle();
+        entityManagerFactory = createEntityManagerFactory();
+
+        Object jpaTestObject = getClass().getClassLoader().loadClass("org.apache.openejb.core.cmp.jpa.JpaTestObject").newInstance();
+        set(jpaTestObject, "EntityManagerFactory", EntityManagerFactory.class, entityManagerFactory);
+        set(jpaTestObject, "TransactionManager", TransactionManager.class, transactionManager);
+        set(jpaTestObject, "NonJtaDs", DataSource.class, nonJtaDs);
+
+        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+        invoke(jpaTestObject, "setUp");
+        try {
+            invoke(jpaTestObject, "jpaLifecycle");
+        } finally {
+            invoke(jpaTestObject, "tearDown");
+        }
     }
 
     public void testResourceLocal() throws Exception {
         transactionType = PersistenceUnitTransactionType.RESOURCE_LOCAL;
-        jpaLifecycle();
-    }
-
-    public void jpaLifecycle() throws Exception {
-        createEntityManagerFactory();
-
-        beginTx();
-        assertTrue(entityManager.isOpen());
-
-        Employee david = entityManager.find(Employee.class, davidPk);
-        assertTrue(entityManager.contains(david));
-
-        assertEquals(david.id, davidPk);
-        assertEquals(david.firstName, "David");
-        assertEquals(david.lastName, "Blevins");
-        commitTx();
-
-        beginTx();
-
-        david = entityManager.find(Employee.class, davidPk);
-        assertTrue(entityManager.contains(david));
-
-        assertEquals(david.id, davidPk);
-        assertEquals(david.firstName, "David");
-        assertEquals(david.lastName, "Blevins");
-
-        commitTx();
-        beginTx();
-
-        david = (Employee) entityManager.createQuery("select e from Employee e where e.firstName='David'").getSingleResult();
-        assertTrue(entityManager.contains(david));
-
-        assertEquals(david.id, davidPk);
-        assertEquals(david.firstName, "David");
-        assertEquals(david.lastName, "Blevins");
-
-        commitTx();
-        beginTx();
+        entityManagerFactory = createEntityManagerFactory();
 
-        david = entityManager.find(Employee.class, davidPk);
-        entityManager.remove(david);
-        assertFalse(entityManager.contains(david));
-        david = entityManager.find(Employee.class, davidPk);
-        assertNull(david);
+        Object jpaTestObject = getClass().getClassLoader().loadClass("org.apache.openejb.core.cmp.jpa.JpaTestObject").newInstance();
+        set(jpaTestObject, "EntityManagerFactory", EntityManagerFactory.class, entityManagerFactory);
+        set(jpaTestObject, "NonJtaDs", DataSource.class, nonJtaDs);
 
-        commitTx();
-        beginTx();
-
-        Employee dain = new Employee();
-        dain.firstName = "Dain";
-        dain.lastName = "Sundstrom";
-        assertFalse(entityManager.contains(dain));
-
-        entityManager.persist(dain);
-
-        // extract primary key seems to require a flush followed by a merge
-        entityManager.flush();
-        dain = entityManager.merge(dain);
-        int dainId = dain.id;
-
-        assertTrue(entityManager.contains(dain));
-
-        commitTx();
-
-
-        beginTx();
-
-        dain = entityManager.find(Employee.class, dainId);
-        assertTrue(entityManager.contains(dain));
-
-        assertEquals(dain.id, dainId);
-        assertEquals(dain.firstName, "Dain");
-        assertEquals(dain.lastName, "Sundstrom");
-
-        commitTx();
-        beginTx();
-
-        dain = (Employee) entityManager.createQuery("select e from Employee e").getSingleResult();
-        assertTrue(entityManager.contains(dain));
-
-        assertEquals(dain.id, dainId);
-        assertEquals(dain.firstName, "Dain");
-        assertEquals(dain.lastName, "Sundstrom");
-        commitTx();
-
-        beginTx();
-        ABean_JPA a = new ABean_JPA();
-        a.setField1(2);
-        entityManager.persist(a);
-        BBean_JPA b = new BBean_JPA();
-        b.setField1(22);
-        entityManager.persist(b);
-        commitTx();
-
-        beginTx();
-        b = entityManager.find(BBean_JPA.class, 22);
-        a = entityManager.find(ABean_JPA.class, 2);
-        a.OpenEJB_addCmr("b", b);
-        b.OpenEJB_addCmr("a", a);
-        commitTx();
-
-//        dump();
-        
-        beginTx();
-        b = entityManager.find(BBean_JPA.class, 22);
-        assertNotNull(b);
-        assertEquals(new Integer(22), b.getField1());
-//        a = (ABean_JPA) b.OpenEJB_getCmr("a");
-//        assertNotNull(a);
-//        assertEquals(new Integer(2), a.getField1());
-        commitTx();
+        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+        invoke(jpaTestObject, "setUp");
+        try {
+            invoke(jpaTestObject, "jpaLifecycle");
+        } finally {
+            invoke(jpaTestObject, "tearDown");
+        }
     }
 
-    private void createEntityManager() {
-        entityManager = entityManagerFactory.createEntityManager();
+    private EntityManagerFactory createEntityManagerFactory() {
+        PersistenceClassLoaderHandler persistenceClassLoaderHandler = new PersistenceClassLoaderHandler() {
+            public void addTransformer(ClassLoader classLoader, ClassFileTransformer classFileTransformer) {
+                Instrumentation instrumentation = Agent.getInstrumentation();
+                instrumentation.addTransformer(classFileTransformer);
+            }
 
-        OpenJPAEntityManager openjpaEM = (OpenJPAEntityManager) entityManager;
-        openjpaEM.addLifecycleListener(new OpenJPALifecycleListener(), (Class[])null);
-    }
+            public ClassLoader getNewTempClassLoader(ClassLoader classLoader) {
+                return new TemporaryClassLoader(classLoader);
+            }
+        };
 
-    private void createEntityManagerFactory() {
-        PersistenceUnitInfoImpl unitInfo = new PersistenceUnitInfoImpl();
+        Agent.getInstrumentation().addTransformer(new ClassFileTransformer() {
+            public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) {
+                if (!className.equals("org/apache/openejb/core/cmp/jpa/Employee")) {
+                    return null;
+                }
+                byte[] newBytes = addNewField(classfileBuffer);
+                return newBytes;
+            }
+        });
+
+        PersistenceUnitInfoImpl unitInfo = new PersistenceUnitInfoImpl(persistenceClassLoaderHandler);
         unitInfo.setPersistenceUnitName("CMP");
         unitInfo.setPersistenceProviderClassName(PersistenceProviderImpl.class.getName());
         unitInfo.setClassLoader(getClass().getClassLoader());
         unitInfo.setExcludeUnlistedClasses(false);
         unitInfo.setJtaDataSource(jtaDs);
         unitInfo.setNonJtaDataSource(nonJtaDs);
-
-        unitInfo.setMappingFileNames(Collections.singletonList("META-INF/jpa.mapping.xml"));
+        unitInfo.addManagedClassName("org.apache.openejb.core.cmp.jpa.Employee");
 
         // Handle Properties
         Properties properties = new Properties();
@@ -255,41 +164,38 @@
         unitInfo.setTransactionType(transactionType);
 
         PersistenceProvider persistenceProvider = new PersistenceProviderImpl();
-        entityManagerFactory = persistenceProvider.createContainerEntityManagerFactory(unitInfo, new HashMap());
-    }
+        EntityManagerFactory emf = persistenceProvider.createContainerEntityManagerFactory(unitInfo, new HashMap());
 
-    private void beginTx() throws Exception {
-        createEntityManager();
-
-        String msg = "BEGIN_TX";
-        log(msg);
-        if (transactionType == PersistenceUnitTransactionType.JTA) {
-            transactionManager.begin();
-            entityManager.joinTransaction();
-        } else {
-            transaction = entityManager.getTransaction();
-            transaction.begin();
-        }
+        return emf;
     }
 
-    private void log(String msg) {
-//        System.out.println(msg);
+    private static void set(Object instance, String parameterName, Class type, Object value) throws Exception {
+        try {
+            instance.getClass().getMethod("set" + parameterName, type).invoke(instance, value);
+        } catch (InvocationTargetException e) {
+            Throwable cause = e.getCause();
+            if (cause instanceof Exception) {
+                throw (Exception) cause;
+            } else if (cause instanceof Error) {
+                throw (Error) cause;
+            } else {
+                throw e;
+            }
+        }
     }
 
-    private void commitTx() throws Exception {
-        log("  BEFORE_COMMIT_TX");
+    private static void invoke(Object instance, String methodName) throws Exception {
         try {
-            if (transactionType == PersistenceUnitTransactionType.JTA) {
-                transactionManager.commit();
+            instance.getClass().getMethod(methodName).invoke(instance);
+        } catch (InvocationTargetException e) {
+            Throwable cause = e.getCause();
+            if (cause instanceof Exception) {
+                throw (Exception) cause;
+            } else if (cause instanceof Error) {
+                throw (Error) cause;
             } else {
-                transaction.commit();
-            }
-        } finally {
-            if (entityManager != null && entityManager.isOpen()) {
-                entityManager.close();
+                throw e;
             }
-            entityManager = null;
-            log("AFTER_COMMIT_TX");
         }
     }
 
@@ -298,32 +204,16 @@
         execute(dataSource, "INSERT INTO employee (first_name, last_name) VALUES ('David', 'Blevins')");
 
         createTable(dataSource, "OneToOneA", "CREATE TABLE OneToOneA(A1 INTEGER, A2 VARCHAR(50))");
-        createTable(dataSource, "OneToOneB"," CREATE TABLE OneToOneB(B1 INTEGER, B2 VARCHAR(50), B3 INTEGER, B4 VARCHAR(50), FKA1 INTEGER)");
+        createTable(dataSource, "OneToOneB", " CREATE TABLE OneToOneB(B1 INTEGER, B2 VARCHAR(50), B3 INTEGER, B4 VARCHAR(50), FKA1 INTEGER)");
         execute(dataSource, "INSERT INTO OneToOneA(A1, A2) VALUES(1, 'value1')");
         execute(dataSource, "INSERT INTO OneToOneA(A1, A2) VALUES(2, 'value2')");
         execute(dataSource, "INSERT INTO OneToOneB(B1, B2, FKA1) VALUES(11, 'value11', 1)");
-
-//        dump();
-
-        // get the pk for the inserted row
-        Connection connection = null;
-        Statement statement = null;
-        try {
-            connection = dataSource.getConnection();
-            statement = connection.createStatement();
-            ResultSet resultSet = statement.executeQuery("select * from employee");
-            resultSet.next();
-            davidPk = resultSet.getInt("id");
-        } finally {
-            close(statement);
-            close(connection);
-        }
     }
 
-    private void createTable(DataSource dataSource, String tableName, String create) throws java.sql.SQLException {
-        try{
-            execute(dataSource, "DROP TABLE "  + tableName);
-        } catch (Exception e){
+    private void createTable(DataSource dataSource, String tableName, String create) throws SQLException {
+        try {
+            execute(dataSource, "DROP TABLE " + tableName);
+        } catch (Exception e) {
             // not concerned
         }
         execute(dataSource, create);
@@ -357,7 +247,7 @@
     }
 
 
-    public boolean execute(DataSource ds, String statement) throws java.sql.SQLException {
+    public boolean execute(DataSource ds, String statement) throws SQLException {
         boolean retval;
         Connection connection = null;
         try {
@@ -377,152 +267,47 @@
         return retval;
     }
 
-    private class OpenJPALifecycleListener extends AbstractLifecycleListener {
-        protected void eventOccurred(LifecycleEvent event) {
-            int type = event.getType();
-            switch (type) {
-                case LifecycleEvent.BEFORE_PERSIST:
-                    log("  BEFORE_PERSIST");
-                    break;
-                case LifecycleEvent.AFTER_PERSIST:
-                    log("  AFTER_PERSIST");
-                    break;
-                case LifecycleEvent.AFTER_LOAD:
-                    log("  AFTER_LOAD");
-                    break;
-                case LifecycleEvent.BEFORE_STORE:
-                    log("  BEFORE_STORE");
-                    break;
-                case LifecycleEvent.AFTER_STORE:
-                    log("  AFTER_STORE");
-                    break;
-                case LifecycleEvent.BEFORE_CLEAR:
-                    log("  BEFORE_CLEAR");
-                    break;
-                case LifecycleEvent.AFTER_CLEAR:
-                    log("  AFTER_CLEAR");
-                    break;
-                case LifecycleEvent.BEFORE_DELETE:
-                    log("  BEFORE_DELETE");
-                    break;
-                case LifecycleEvent.AFTER_DELETE:
-                    log("  AFTER_DELETE");
-                    break;
-                case LifecycleEvent.BEFORE_DIRTY:
-                    log("  BEFORE_DIRTY");
-                    break;
-                case LifecycleEvent.AFTER_DIRTY:
-                    log("  AFTER_DIRTY");
-                    break;
-                case LifecycleEvent.BEFORE_DIRTY_FLUSHED:
-                    log("  BEFORE_DIRTY_FLUSHED");
-                    break;
-                case LifecycleEvent.AFTER_DIRTY_FLUSHED:
-                    log("  AFTER_DIRTY_FLUSHED");
-                    break;
-                case LifecycleEvent.BEFORE_DETACH:
-                    log("  BEFORE_DETACH");
-                    break;
-                case LifecycleEvent.AFTER_DETACH:
-                    log("  AFTER_DETACH");
-                    break;
-                case LifecycleEvent.BEFORE_ATTACH:
-                    log("  BEFORE_ATTACH");
-                    break;
-                case LifecycleEvent.AFTER_ATTACH:
-                    log("  AFTER_ATTACH");
-                    break;
-                case LifecycleEvent.AFTER_REFRESH:
-                    log("  AFTER_REFRESH");
-                    break;
-                default:
-                    log("  default");
-                    break;
-            }
-            super.eventOccurred(event);
-        }
-
-        public void beforePersist(LifecycleEvent event) {
-            eventOccurred(event);
-        }
-
-        public void afterRefresh(LifecycleEvent event) {
-            eventOccurred(event);
-        }
-
-        public void beforeDetach(LifecycleEvent event) {
-            eventOccurred(event);
+    private static void close(Statement statement) {
+        if (statement == null) {
+            return;
         }
-
-        public void afterDetach(LifecycleEvent event) {
-            eventOccurred(event);
+        try {
+            statement.close();
+        } catch (SQLException e) {
         }
+    }
 
-        public void beforeAttach(LifecycleEvent event) {
-            eventOccurred(event);
+    private static void close(Connection connection) {
+        if (connection == null) {
+            return;
         }
-
-        public void afterAttach(LifecycleEvent event) {
-            eventOccurred(event);
+        try {
+            connection.close();
+        } catch (SQLException e) {
         }
     }
 
-    protected void dump() throws SQLException {
-        dumpTable(nonJtaDs, "employee");
-        dumpTable(nonJtaDs, "OneToOneA");
-        dumpTable(nonJtaDs, "OneToOneB");
-    }
+    public static byte[] addNewField(byte[] origBytes) {
+        ClassWriter classWriter = new ClassWriter(true);
 
-    public static void dumpTable(DataSource ds, String table) throws SQLException {
-        Connection connection = null;
-        Statement statement = null;
-        ResultSet resultSet = null;
-        try {
-            connection = ds.getConnection();
-            statement = connection.createStatement();
-            resultSet = statement.executeQuery("SELECT * FROM " + table);
-            ResultSetMetaData setMetaData = resultSet.getMetaData();
-            int columnCount = setMetaData.getColumnCount();
-            while(resultSet.next()) {
-                StringBuilder row = new StringBuilder();
-                for (int i = 1; i <= columnCount; i++) {
-                    if (i > 1) {
-                        row.append(", ");
-                    }
-                    String name = setMetaData.getColumnName(i);
-                    Object value = resultSet.getObject(i);
-                    row.append(name).append("=").append(value);
-                }
-                System.out.println(row);
-            }
-        } finally {
-            close(resultSet);
-            close(statement);
-            close(connection);
-        }
-    }
+        FieldAdderClassVisitor visitor = new FieldAdderClassVisitor(classWriter);
 
-    private static void close(ResultSet resultSet) {
-        if (resultSet == null) return;
-        try {
-            resultSet.close();
-        } catch (SQLException e) {
-        }
+        ClassReader classReader = new ClassReader(origBytes);
+        classReader.accept(visitor, false);
+
+        byte[] newBytes = classWriter.toByteArray();
+        return newBytes;
     }
 
-    private static void close(Statement statement) {
-        if (statement == null) return;
-        try {
-            statement.close();
-        } catch (SQLException e) {
+    public static class FieldAdderClassVisitor extends ClassAdapter {
+        public FieldAdderClassVisitor(ClassVisitor classVisitor) {
+            super(classVisitor);
         }
-    }
 
-    private static void close(Connection connection) {
-        if (connection == null) return;
-        try {
-            connection.close();
-        } catch (SQLException e) {
+        public void visitEnd() {
+            // add new private transient String newField${System.currentTimeMills()}
+            cv.visitField(ACC_PRIVATE + ACC_TRANSIENT, "newField"  + System.currentTimeMillis(), "Ljava/lang/String;", null, null);
+            cv.visitEnd();
         }
     }
 }

Added: incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/JpaTestObject.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/JpaTestObject.java?view=auto&rev=491149
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/JpaTestObject.java (added)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/JpaTestObject.java Fri Dec 29 17:40:06 2006
@@ -0,0 +1,416 @@
+/**
+ *
+ * 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.core.cmp.jpa;
+
+import org.apache.openjpa.event.AbstractLifecycleListener;
+import org.apache.openjpa.event.LifecycleEvent;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityTransaction;
+import javax.sql.DataSource;
+import javax.transaction.Status;
+import javax.transaction.TransactionManager;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+public class JpaTestObject extends junit.framework.Assert {
+    private EntityManagerFactory entityManagerFactory;
+    private TransactionManager transactionManager;
+    private DataSource nonJtaDs;
+
+    private EntityManager entityManager;
+    private EntityTransaction transaction;
+
+    public EntityManagerFactory getEntityManagerFactory() {
+        return entityManagerFactory;
+    }
+
+    public void setEntityManagerFactory(EntityManagerFactory entityManagerFactory) {
+        this.entityManagerFactory = entityManagerFactory;
+    }
+
+    public TransactionManager getTransactionManager() {
+        return transactionManager;
+    }
+
+    public void setTransactionManager(TransactionManager transactionManager) {
+        this.transactionManager = transactionManager;
+    }
+
+    public DataSource getNonJtaDs() {
+        return nonJtaDs;
+    }
+
+    public void setNonJtaDs(DataSource nonJtaDs) {
+        this.nonJtaDs = nonJtaDs;
+    }
+
+    public void setUp() throws Exception {
+    }
+
+    public void tearDown() throws Exception {
+        if (entityManager != null && entityManager.isOpen()) {
+            if (transactionManager == null) {
+                try {
+                    if (entityManager.getTransaction().getRollbackOnly()) {
+                        entityManager.getTransaction().rollback();
+                    } else {
+                        entityManager.getTransaction().commit();
+                    }
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            } else {
+                try {
+                    if (transactionManager.getStatus() != Status.STATUS_NO_TRANSACTION) {
+                        transactionManager.rollback();
+                    }
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            }
+            entityManager.close();
+        }
+
+        nonJtaDs = null;
+        entityManager = null;
+        entityManagerFactory = null;
+        transactionManager = null;
+    }
+
+    public void jpaLifecycle() throws Exception {
+        // get the pk for the inserted row
+        int davidPk = -1;
+        {
+            Connection connection = null;
+            Statement statement = null;
+            try {
+                connection = nonJtaDs.getConnection();
+                statement = connection.createStatement();
+                ResultSet resultSet = statement.executeQuery("select * from employee");
+                resultSet.next();
+                davidPk = resultSet.getInt("id");
+            } finally {
+                close(statement);
+                close(connection);
+            }
+        }
+
+        beginTx();
+        assertTrue(entityManager.isOpen());
+
+        Employee david = entityManager.find(Employee.class, davidPk);
+        assertTrue(entityManager.contains(david));
+
+        assertEquals(david.getId(), davidPk);
+        assertEquals(david.getFirstName(), "David");
+        assertEquals(david.getLastName(), "Blevins");
+        commitTx();
+
+        beginTx();
+
+        david = entityManager.find(Employee.class, davidPk);
+        assertTrue(entityManager.contains(david));
+
+        assertEquals(david.getId(), davidPk);
+        assertEquals(david.getFirstName(), "David");
+        assertEquals(david.getLastName(), "Blevins");
+
+        commitTx();
+        beginTx();
+
+        david = (Employee) entityManager.createQuery("select e from Employee e where e.firstName='David'").getSingleResult();
+        assertTrue(entityManager.contains(david));
+
+        assertEquals(david.getId(), davidPk);
+        assertEquals(david.getFirstName(), "David");
+        assertEquals(david.getLastName(), "Blevins");
+
+        commitTx();
+        beginTx();
+
+        david = entityManager.find(Employee.class, davidPk);
+        entityManager.remove(david);
+        assertFalse(entityManager.contains(david));
+        david = entityManager.find(Employee.class, davidPk);
+        assertNull(david);
+
+        commitTx();
+        beginTx();
+
+        Employee dain = new Employee();
+        dain.setFirstName("Dain");
+        dain.setLastName("Sundstrom");
+        assertFalse(entityManager.contains(dain));
+
+        entityManager.persist(dain);
+
+        // extract primary key seems to require a flush followed by a merge
+        entityManager.flush();
+        dain = entityManager.merge(dain);
+        int dainId = dain.getId();
+
+        assertTrue(entityManager.contains(dain));
+
+        commitTx();
+
+
+        beginTx();
+
+        dain = entityManager.find(Employee.class, dainId);
+        assertTrue(entityManager.contains(dain));
+
+        assertEquals(dain.getId(), dainId);
+        assertEquals(dain.getFirstName(), "Dain");
+        assertEquals(dain.getLastName(), "Sundstrom");
+
+        commitTx();
+        beginTx();
+
+        dain = (Employee) entityManager.createQuery("select e from Employee e").getSingleResult();
+        assertTrue(entityManager.contains(dain));
+
+        assertEquals(dain.getId(), dainId);
+        assertEquals(dain.getFirstName(), "Dain");
+        assertEquals(dain.getLastName(), "Sundstrom");
+        commitTx();
+
+//        beginTx();
+//        ABean_JPA a = new ABean_JPA();
+//        a.setField1(2);
+//        entityManager.persist(a);
+//        BBean_JPA b = new BBean_JPA();
+//        b.setField1(22);
+//        entityManager.persist(b);
+//        commitTx();
+//
+//        beginTx();
+//        b = entityManager.find(BBean_JPA.class, 22);
+//        a = entityManager.find(ABean_JPA.class, 2);
+//        a.OpenEJB_addCmr("b", b);
+//        b.OpenEJB_addCmr("a", a);
+//        commitTx();
+//
+////        dump();
+//
+//        beginTx();
+//        b = entityManager.find(BBean_JPA.class, 22);
+//        assertNotNull(b);
+//        assertEquals(new Integer(22), b.getField1());
+////        a = (ABean_JPA) b.OpenEJB_getCmr("a");
+////        assertNotNull(a);
+////        assertEquals(new Integer(2), a.getField1());
+//        commitTx();
+    }
+
+    private void createEntityManager() {
+        entityManager = entityManagerFactory.createEntityManager();
+
+        OpenJPAEntityManager openjpaEM = (OpenJPAEntityManager) entityManager;
+        openjpaEM.addLifecycleListener(new JpaTestObject.OpenJPALifecycleListener(), (Class[])null);
+    }
+
+    private void beginTx() throws Exception {
+        createEntityManager();
+
+        String msg = "BEGIN_TX";
+        log(msg);
+        if (transactionManager != null) {
+            transactionManager.begin();
+            entityManager.joinTransaction();
+        } else {
+            transaction = entityManager.getTransaction();
+            transaction.begin();
+        }
+    }
+
+    public void log(String msg) {
+//        System.out.println(msg);
+    }
+
+    private void commitTx() throws Exception {
+        log("  BEFORE_COMMIT_TX");
+        try {
+            if (transactionManager != null) {
+                transactionManager.commit();
+            } else {
+                transaction.commit();
+            }
+        } finally {
+            if (entityManager != null && entityManager.isOpen()) {
+                entityManager.close();
+            }
+            entityManager = null;
+            log("AFTER_COMMIT_TX");
+        }
+    }
+
+    private class OpenJPALifecycleListener extends AbstractLifecycleListener {
+        protected void eventOccurred(LifecycleEvent event) {
+            int type = event.getType();
+            switch (type) {
+                case LifecycleEvent.BEFORE_PERSIST:
+                    log("  BEFORE_PERSIST");
+                    break;
+                case LifecycleEvent.AFTER_PERSIST:
+                    log("  AFTER_PERSIST");
+                    break;
+                case LifecycleEvent.AFTER_LOAD:
+                    log("  AFTER_LOAD");
+                    break;
+                case LifecycleEvent.BEFORE_STORE:
+                    log("  BEFORE_STORE");
+                    break;
+                case LifecycleEvent.AFTER_STORE:
+                    log("  AFTER_STORE");
+                    break;
+                case LifecycleEvent.BEFORE_CLEAR:
+                    log("  BEFORE_CLEAR");
+                    break;
+                case LifecycleEvent.AFTER_CLEAR:
+                    log("  AFTER_CLEAR");
+                    break;
+                case LifecycleEvent.BEFORE_DELETE:
+                    log("  BEFORE_DELETE");
+                    break;
+                case LifecycleEvent.AFTER_DELETE:
+                    log("  AFTER_DELETE");
+                    break;
+                case LifecycleEvent.BEFORE_DIRTY:
+                    log("  BEFORE_DIRTY");
+                    break;
+                case LifecycleEvent.AFTER_DIRTY:
+                    log("  AFTER_DIRTY");
+                    break;
+                case LifecycleEvent.BEFORE_DIRTY_FLUSHED:
+                    log("  BEFORE_DIRTY_FLUSHED");
+                    break;
+                case LifecycleEvent.AFTER_DIRTY_FLUSHED:
+                    log("  AFTER_DIRTY_FLUSHED");
+                    break;
+                case LifecycleEvent.BEFORE_DETACH:
+                    log("  BEFORE_DETACH");
+                    break;
+                case LifecycleEvent.AFTER_DETACH:
+                    log("  AFTER_DETACH");
+                    break;
+                case LifecycleEvent.BEFORE_ATTACH:
+                    log("  BEFORE_ATTACH");
+                    break;
+                case LifecycleEvent.AFTER_ATTACH:
+                    log("  AFTER_ATTACH");
+                    break;
+                case LifecycleEvent.AFTER_REFRESH:
+                    log("  AFTER_REFRESH");
+                    break;
+                default:
+                    log("  default");
+                    break;
+            }
+            super.eventOccurred(event);
+        }
+
+        public void beforePersist(LifecycleEvent event) {
+            eventOccurred(event);
+        }
+
+        public void afterRefresh(LifecycleEvent event) {
+            eventOccurred(event);
+        }
+
+        public void beforeDetach(LifecycleEvent event) {
+            eventOccurred(event);
+        }
+
+        public void afterDetach(LifecycleEvent event) {
+            eventOccurred(event);
+        }
+
+        public void beforeAttach(LifecycleEvent event) {
+            eventOccurred(event);
+        }
+
+        public void afterAttach(LifecycleEvent event) {
+            eventOccurred(event);
+        }
+    }
+
+    protected void dump() throws SQLException {
+        JpaTestObject.dumpTable(nonJtaDs, "employee");
+        JpaTestObject.dumpTable(nonJtaDs, "OneToOneA");
+        JpaTestObject.dumpTable(nonJtaDs, "OneToOneB");
+    }
+
+    public static void dumpTable(DataSource ds, String table) throws SQLException {
+        Connection connection = null;
+        Statement statement = null;
+        ResultSet resultSet = null;
+        try {
+            connection = ds.getConnection();
+            statement = connection.createStatement();
+            resultSet = statement.executeQuery("SELECT * FROM " + table);
+            ResultSetMetaData setMetaData = resultSet.getMetaData();
+            int columnCount = setMetaData.getColumnCount();
+            while(resultSet.next()) {
+                StringBuilder row = new StringBuilder();
+                for (int i = 1; i <= columnCount; i++) {
+                    if (i > 1) {
+                        row.append(", ");
+                    }
+                    String name = setMetaData.getColumnName(i);
+                    Object value = resultSet.getObject(i);
+                    row.append(name).append("=").append(value);
+                }
+                System.out.println(row);
+            }
+        } finally {
+            JpaTestObject.close(resultSet);
+            JpaTestObject.close(statement);
+            JpaTestObject.close(connection);
+        }
+    }
+
+    private static void close(ResultSet resultSet) {
+        if (resultSet == null) return;
+        try {
+            resultSet.close();
+        } catch (SQLException e) {
+        }
+    }
+
+    private static void close(Statement statement) {
+        if (statement == null) return;
+        try {
+            statement.close();
+        } catch (SQLException e) {
+        }
+    }
+
+    private static void close(Connection connection) {
+        if (connection == null) return;
+        try {
+            connection.close();
+        } catch (SQLException e) {
+        }
+    }
+}

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/iTest.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/iTest.java?view=diff&rev=491149&r1=491148&r2=491149
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/iTest.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/iTest.java Fri Dec 29 17:40:06 2006
@@ -21,10 +21,8 @@
 import junit.framework.TestSuite;
 import org.apache.openejb.test.TestManager;
 import org.apache.openejb.test.entity.bmp.BmpLocalTestSuite;
-import org.apache.openejb.test.entity.cmp.CmpTestSuite;
 import org.apache.openejb.test.entity.cmp.CmpLocalTestSuite;
 import org.apache.openejb.test.entity.cmp2.Cmp2TestSuite;
-import org.apache.openejb.test.stateful.StatefulTestSuite;
 import org.apache.openejb.test.stateful.StatefulLocalTestSuite;
 import org.apache.openejb.test.stateless.StatelessLocalTestSuite;
 

Propchange: incubator/openejb/trunk/openejb3/container/openejb-javaagent/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Dec 29 17:40:06 2006
@@ -0,0 +1,10 @@
+*.iws
+*.ipr
+*.iml
+.classpath
+.project
+.settings
+*.log
+junit*.properties
+target
+bin

Added: incubator/openejb/trunk/openejb3/container/openejb-javaagent/DISCLAIMER.txt
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-javaagent/DISCLAIMER.txt?view=auto&rev=491149
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-javaagent/DISCLAIMER.txt (added)
+++ incubator/openejb/trunk/openejb3/container/openejb-javaagent/DISCLAIMER.txt Fri Dec 29 17:40:06 2006
@@ -0,0 +1,7 @@
+OpenEJB is an effort undergoing incubation at the Apache Software Foundation
+(ASF), sponsored by the Geronimo 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.
\ No newline at end of file

Added: incubator/openejb/trunk/openejb3/container/openejb-javaagent/LICENSE.txt
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-javaagent/LICENSE.txt?view=auto&rev=491149
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-javaagent/LICENSE.txt (added)
+++ incubator/openejb/trunk/openejb3/container/openejb-javaagent/LICENSE.txt Fri Dec 29 17:40:06 2006
@@ -0,0 +1,202 @@
+
+                                 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.

Added: incubator/openejb/trunk/openejb3/container/openejb-javaagent/NOTICE.txt
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-javaagent/NOTICE.txt?view=auto&rev=491149
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-javaagent/NOTICE.txt (added)
+++ incubator/openejb/trunk/openejb3/container/openejb-javaagent/NOTICE.txt Fri Dec 29 17:40:06 2006
@@ -0,0 +1,11 @@
+   =========================================================================
+   ==  NOTICE file corresponding to the section 4 d of                    ==
+   ==  the Apache License, Version 2.0,                                   ==
+   ==  in this case for the Apache OpenEJB distribution.                  ==
+   =========================================================================
+
+   This product includes software developed by
+   The Apache Software Foundation (http://www.apache.org/).
+
+   Please read the different LICENSE files present in the licenses directory of
+   this distribution.
\ No newline at end of file

Added: incubator/openejb/trunk/openejb3/container/openejb-javaagent/pom.xml
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-javaagent/pom.xml?view=auto&rev=491149
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-javaagent/pom.xml (added)
+++ incubator/openejb/trunk/openejb3/container/openejb-javaagent/pom.xml Fri Dec 29 17:40:06 2006
@@ -0,0 +1,52 @@
+<?xml version="1.0"?>
+<!--
+
+    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>
+  <parent>
+    <artifactId>container</artifactId>
+    <groupId>org.apache.openejb</groupId>
+    <version>3.0-incubating-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>openejb-javaagent</artifactId>
+  <name>OpenEJB :: Container :: Java Agent</name>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jar-plugin</artifactId>
+        <configuration>
+          <archive>
+            <manifestEntries>
+              <Premain-Class>org.apache.openejb.javaagent.Agent</Premain-Class>
+              <!--<Boot-Class-Path></Boot-Class-Path>-->
+              <!--<Can-Redefine-Classes>true</Can-Redefine-Classes>-->
+            </manifestEntries>
+          </archive>
+        </configuration>
+      </plugin>
+      <plugin>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <configuration>
+          <source>1.5</source>
+          <target>1.5</target>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Added: incubator/openejb/trunk/openejb3/container/openejb-javaagent/src/main/java/org/apache/openejb/javaagent/Agent.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-javaagent/src/main/java/org/apache/openejb/javaagent/Agent.java?view=auto&rev=491149
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-javaagent/src/main/java/org/apache/openejb/javaagent/Agent.java (added)
+++ incubator/openejb/trunk/openejb3/container/openejb-javaagent/src/main/java/org/apache/openejb/javaagent/Agent.java Fri Dec 29 17:40:06 2006
@@ -0,0 +1,38 @@
+/**
+ *
+ * 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.javaagent;
+
+import java.lang.instrument.Instrumentation;
+
+public class Agent {
+    private static String agentArgs;
+    private static Instrumentation instrumentation;
+
+    public static void premain(String agentArgs, Instrumentation instrumentation) {
+        Agent.agentArgs = agentArgs;
+        Agent.instrumentation = instrumentation;
+    }
+
+    public static String getAgentArgs() {
+        return agentArgs;
+    }
+
+    public static Instrumentation getInstrumentation() {
+        return instrumentation;
+    }
+}

Modified: incubator/openejb/trunk/openejb3/container/openejb-persistence/pom.xml
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-persistence/pom.xml?view=diff&rev=491149&r1=491148&r2=491149
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-persistence/pom.xml (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-persistence/pom.xml Fri Dec 29 17:40:06 2006
@@ -70,6 +70,14 @@
   </build>
   <dependencies>
     <dependency>
+      <groupId>asm</groupId>
+      <artifactId>asm</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>asm</groupId>
+      <artifactId>asm-commons</artifactId>
+    </dependency>
+    <dependency>
       <groupId>org.apache.geronimo.specs</groupId>
       <artifactId>geronimo-jpa_3.0_spec</artifactId>
     </dependency>

Added: incubator/openejb/trunk/openejb3/container/openejb-persistence/src/main/java/org/apache/openejb/persistence/PersistenceClassLoaderHandler.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-persistence/src/main/java/org/apache/openejb/persistence/PersistenceClassLoaderHandler.java?view=auto&rev=491149
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-persistence/src/main/java/org/apache/openejb/persistence/PersistenceClassLoaderHandler.java (added)
+++ incubator/openejb/trunk/openejb3/container/openejb-persistence/src/main/java/org/apache/openejb/persistence/PersistenceClassLoaderHandler.java Fri Dec 29 17:40:06 2006
@@ -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 org.apache.openejb.persistence;
+
+import java.lang.instrument.ClassFileTransformer;
+
+public interface PersistenceClassLoaderHandler {
+    void addTransformer(ClassLoader classLoader, ClassFileTransformer classFileTransformer);
+    ClassLoader getNewTempClassLoader(ClassLoader classLoader);
+}

Modified: incubator/openejb/trunk/openejb3/container/openejb-persistence/src/main/java/org/apache/openejb/persistence/PersistenceDeployer.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-persistence/src/main/java/org/apache/openejb/persistence/PersistenceDeployer.java?view=diff&rev=491149&r1=491148&r2=491149
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-persistence/src/main/java/org/apache/openejb/persistence/PersistenceDeployer.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-persistence/src/main/java/org/apache/openejb/persistence/PersistenceDeployer.java Fri Dec 29 17:40:06 2006
@@ -28,13 +28,11 @@
 import java.net.URL;
 import java.util.Enumeration;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 
 public class PersistenceDeployer {
-
     public static final String PERSISTENCE_SCHEMA = "http://java.sun.com/xml/ns/persistence";
 
     public static final String PROVIDER_PROP = "javax.persistence.provider";
@@ -45,19 +43,40 @@
 
     public static final String NON_JTADATASOURCE_PROP = "javax.persistence.nonJtaDataSource";
 
-    private String providerEnv = null;
-
-    private String transactionTypeEnv = null;
-
-    private String jtaDataSourceEnv = null;
-
-    private String nonJtaDataSourceEnv = null;
+    /**
+     * Used to resolve jta and non-jta data cource names for actual DataSource objects.
+     */
     private final DataSourceResolver dataSourceResolver;
 
-    public PersistenceDeployer(DataSourceResolver dataSourceResolver) {
+    /**
+     * External handler which handles adding a runtime ClassTransformer to the classloader.
+     */
+    private final PersistenceClassLoaderHandler persistenceClassLoaderHandler;
+
+    /**
+     * If set, overrides the persistence provider class name in the persistence.xml.
+     */
+    private String providerEnv;
+
+    /**
+     * If set, overrides the transaction type in the persistence.xml.
+     */
+    private String transactionTypeEnv;
+
+    /**
+     * If set, overrides the jta data source class name in the persistence.xml.
+     */
+    private String jtaDataSourceEnv;
+
+    /**
+     * If set, overrides the non-jta data source class name in the persistence.xml.
+     */
+    private String nonJtaDataSourceEnv;
 
+    public PersistenceDeployer(DataSourceResolver dataSourceResolver, PersistenceClassLoaderHandler persistenceClassLoaderHandler) {
         loadSystemProps();
         this.dataSourceResolver = dataSourceResolver;
+        this.persistenceClassLoaderHandler = persistenceClassLoaderHandler;
     }
 
     private void loadSystemProps() {
@@ -68,17 +87,15 @@
     }
 
     public Map<String, EntityManagerFactory> loadPersistence(ClassLoader cl, URL url) throws PersistenceDeployerException {
-
         try {
-
-            Map<String, EntityManagerFactory> factories = new HashMap();
+            Map<String, EntityManagerFactory> factories = new HashMap<String, EntityManagerFactory>();
 
             org.apache.openejb.persistence.dd.Persistence persistence = JaxbPersistenceFactory.getPersistence(url);
 
             List<PersistenceUnit> persistenceUnits = persistence.getPersistenceUnit();
 
             for (PersistenceUnit pu : persistenceUnits) {
-                PersistenceUnitInfoImpl unitInfo = new PersistenceUnitInfoImpl();
+                PersistenceUnitInfoImpl unitInfo = new PersistenceUnitInfoImpl(persistenceClassLoaderHandler);
                 unitInfo.setPersistenceUnitName(pu.getName());
                 if (providerEnv != null) {
                     unitInfo.setPersistenceProviderClassName(providerEnv);
@@ -108,12 +125,14 @@
                 unitInfo.setMappingFileNames(pu.getMappingFile());
 
                 // Handle Properties
-                List<org.apache.openejb.persistence.dd.Property> puiProperties = pu.getProperties().getProperty();
-                Properties properties = new Properties();
-                for (org.apache.openejb.persistence.dd.Property property : puiProperties) {
-                    properties.put(property.getName(), property.getValue());
+                org.apache.openejb.persistence.dd.Properties puiProperties = pu.getProperties();
+                if (puiProperties != null) {
+                    Properties properties = new Properties();
+                    for (org.apache.openejb.persistence.dd.Property property : puiProperties.getProperty()) {
+                        properties.put(property.getName(), property.getValue());
+                    }
+                    unitInfo.setProperties(properties);
                 }
-                unitInfo.setProperties(properties);
 
                 // Persistence Unit Transaction Type
                 if (transactionTypeEnv != null) {
@@ -142,14 +161,11 @@
                 String rootUrlPath = url.toExternalForm().replaceFirst("!?META-INF/persistence.xml$","");
                 unitInfo.setPersistenceUnitRootUrl(new URL(rootUrlPath));
 
-                // TODO - What do we do here?
-                // unitInfo.setNewTempClassLoader(???);
-
                 String persistenceProviderClassName = unitInfo.getPersistenceProviderClassName();
                 if (persistenceProviderClassName == null){
                     continue;
                 }
-                Class clazz = (Class) cl.loadClass(persistenceProviderClassName);
+                Class clazz = cl.loadClass(persistenceProviderClassName);
                 PersistenceProvider persistenceProvider = (PersistenceProvider) clazz.newInstance();
                 EntityManagerFactory emf = persistenceProvider.createContainerEntityManagerFactory(unitInfo, new HashMap());
 
@@ -186,15 +202,13 @@
     
     public Map<String, EntityManagerFactory> deploy(List<URL> urls,ClassLoader cl) throws PersistenceDeployerException {
 
-        Map<String, EntityManagerFactory> factoryList = new HashMap<String, EntityManagerFactory>();
+        Map<String, EntityManagerFactory> factories = new HashMap<String, EntityManagerFactory>();
         // Read the persistence.xml files      
-        
-        Iterator<URL> iter = urls.iterator();
-        while (iter.hasNext()) {
-            URL url = iter.next();            
-            factoryList.putAll(loadPersistence(cl, url));               
+
+        for (URL url : urls) {
+            factories.putAll(loadPersistence(cl, url));
         }        
-        return factoryList;
+        return factories;
     }
 
 

Modified: incubator/openejb/trunk/openejb3/container/openejb-persistence/src/main/java/org/apache/openejb/persistence/PersistenceUnitInfoImpl.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-persistence/src/main/java/org/apache/openejb/persistence/PersistenceUnitInfoImpl.java?view=diff&rev=491149&r1=491148&r2=491149
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-persistence/src/main/java/org/apache/openejb/persistence/PersistenceUnitInfoImpl.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-persistence/src/main/java/org/apache/openejb/persistence/PersistenceUnitInfoImpl.java Fri Dec 29 17:40:06 2006
@@ -17,173 +17,245 @@
 package org.apache.openejb.persistence;
 
 import java.io.File;
+import java.lang.instrument.ClassFileTransformer;
+import java.lang.instrument.IllegalClassFormatException;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.security.ProtectionDomain;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Properties;
-
 import javax.persistence.spi.ClassTransformer;
 import javax.persistence.spi.PersistenceUnitInfo;
 import javax.persistence.spi.PersistenceUnitTransactionType;
 import javax.sql.DataSource;
 
 public class PersistenceUnitInfoImpl implements PersistenceUnitInfo {
-    private String persistenceUnitName = null;
-
-    private String persistenceProviderClassName = null;
-
+    /**
+     * External handler which handles adding a runtime ClassTransformer to the classloader.
+     */
+    private final PersistenceClassLoaderHandler persistenceClassLoaderHandler;
+
+    /**
+     * Name of this persistence unit.  The JPA specification has restrictions on the
+     * uniqueness of this name.
+     */
+    private String persistenceUnitName;
+
+    /**
+     * Name of the persistence provider implementation class.
+     */
+    private String persistenceProviderClassName;
+
+    /**
+     * Does this persistence unti participate in JTA transactions or does it manage
+     * resource local tranactions using the JDBC APIs.
+     */
     private PersistenceUnitTransactionType transactionType = PersistenceUnitTransactionType.JTA;
 
-    private DataSource jtaDataSource = null;
-
-    private DataSource nonJtaDataSource = null;
+    /**
+     * Data source used by jta persistence units for accessing transactional data.
+     */
+    private DataSource jtaDataSource;
+
+    /**
+     * Data source used by non-jta persistence units and by jta persistence units for
+     * non-transactional operations such as accessing a primary key table or sequence.
+     */
+    private DataSource nonJtaDataSource;
+
+    /**
+     * Names if the entity-mapping.xml files relative to to the persistenceUnitRootUrl.
+     */
+    private final List<String> mappingFileNames = new ArrayList<String>();
+
+    /**
+     * The jar file locations that make up this persistence unit.
+     */
+    private final List<URL> jarFileUrls = new ArrayList<URL>();
+
+    /**
+     * Location of the root of the persistent unit.  The directory in which
+     * META-INF/persistence.xml is located.
+     */
+    private URL persistenceUnitRootUrl;
+
+    /**
+     * List of the managed entity classes.
+     */
+    private final List<String> managedClassNames = new ArrayList<String>();
+
+    /**
+     * Should class not listed in the persistence unit be managed by the EntityManager?
+     */
+    private boolean excludeUnlistedClasses;
+
+    /**
+     * JPA provider properties for this persistence unit.
+     */
+    private Properties properties;
+
+    /**
+     * Class loader used by JPA to load Entity classes.
+     */
+    private ClassLoader classLoader;
 
-    private List<String> mappingFileNames = null;
-
-    private List<URL> jarFileUrls = null;
-
-    private URL persistenceUnitRootUrl = null;
-
-    private List<String> managedClassNames = null;
+    public PersistenceUnitInfoImpl() {
+        this.persistenceClassLoaderHandler = null;
+    }
 
-    private boolean excludeUnlistedClasses = false;
+    public PersistenceUnitInfoImpl(PersistenceClassLoaderHandler persistenceClassLoaderHandler) {
+        this.persistenceClassLoaderHandler = persistenceClassLoaderHandler;
+    }
 
-    private Properties vendorProperties = null;
+    public String getPersistenceUnitName() {
+        return persistenceUnitName;
+    }
 
-    private ClassLoader classLoader = null;
-    
-    private ClassLoader tempClassLoader = null;
+    public void setPersistenceUnitName(String persistenceUnitName) {
+        this.persistenceUnitName = persistenceUnitName;
+    }
 
-    public void setExcludeUnlistedClasses(boolean excludeUnlistedClasses) {
-        this.excludeUnlistedClasses = excludeUnlistedClasses;
+    public String getPersistenceProviderClassName() {
+        return persistenceProviderClassName;
     }
 
-    public void setProperties(Properties vendorProperties) {
-        this.vendorProperties = vendorProperties;
+    public void setPersistenceProviderClassName(String persistenceProviderClassName) {
+        this.persistenceProviderClassName = persistenceProviderClassName;
     }
 
-    public void setClassLoader(ClassLoader classLoader) {
-        this.classLoader = classLoader;
+    public PersistenceUnitTransactionType getTransactionType() {
+        return transactionType;
     }
 
-    public void setJarFileUrls(List<String> jarFiles) throws MalformedURLException {
-        if (jarFileUrls == null) {
-            jarFileUrls = new ArrayList<URL>();
-        }
+    public void setTransactionType(PersistenceUnitTransactionType transactionType) {
+        this.transactionType = transactionType;
+    }
 
-        for (String jarFile : jarFiles) {
-            jarFileUrls.add((new File(jarFile)).toURL());
-        }
+    public DataSource getJtaDataSource() {
+        return jtaDataSource;
     }
 
     public void setJtaDataSource(DataSource jtaDataSource) {
         this.jtaDataSource = jtaDataSource;
     }
 
-    public void setManagedClassNames(List<String> managedClassNames) {
-        this.managedClassNames = managedClassNames;
+    public DataSource getNonJtaDataSource() {
+        return nonJtaDataSource;
     }
 
-    public void addManagedClassName(String className) {
-        if (managedClassNames == null) {
-            managedClassNames = new ArrayList<String>();
-        }
-        managedClassNames.add(className);
+    public void setNonJtaDataSource(DataSource nonJtaDataSource) {
+        this.nonJtaDataSource = nonJtaDataSource;
+    }
+
+    public List<String> getMappingFileNames() {
+        return mappingFileNames;
     }
 
     public void setMappingFileNames(List<String> mappingFileNames) {
-        this.mappingFileNames = mappingFileNames;
+        if (mappingFileNames == null) {
+            throw new NullPointerException("mappingFileNames is null");
+        }
+        this.mappingFileNames.clear();
+        this.mappingFileNames.addAll(mappingFileNames);
     }
 
     public void addMappingFileName(String mappingFileName) {
-        if (mappingFileNames == null) {
-            mappingFileNames = new ArrayList<String>();
+        if (mappingFileName == null) {
+            throw new NullPointerException("mappingFileName is null");
         }
         mappingFileNames.add(mappingFileName);
     }
 
-    public void setNonJtaDataSource(DataSource nonJtaDataSource) {
-        this.nonJtaDataSource = nonJtaDataSource;
+    public List<URL> getJarFileUrls() {
+        return jarFileUrls;
     }
 
-    public void setPersistenceProviderClassName(
-            String persistenceProviderClassName) {
-        this.persistenceProviderClassName = persistenceProviderClassName;
+    public void setJarFileUrls(List<String> jarFiles) throws MalformedURLException {
+        if (jarFiles == null) {
+            throw new NullPointerException("jarFiles is null");
+        }
+        for (String jarFile : jarFiles) {
+            jarFileUrls.add((new File(jarFile)).toURL());
+        }
     }
 
-    public void setPersistenceUnitName(String persistenceUnitName) {
-        this.persistenceUnitName = persistenceUnitName;
+    public URL getPersistenceUnitRootUrl() {
+        return persistenceUnitRootUrl;
     }
 
     public void setPersistenceUnitRootUrl(URL persistenceUnitRootUrl) {
         this.persistenceUnitRootUrl = persistenceUnitRootUrl;
     }
 
-    public void setTransactionType(
-            PersistenceUnitTransactionType transactionType) {
-        this.transactionType = transactionType;
-    }
-    
-    void setNewTempClassLoader(ClassLoader tempClassLoader) {
-        this.tempClassLoader = tempClassLoader;
-    }
-
-    public String getPersistenceUnitName() {
-        return persistenceUnitName;
+    public List<String> getManagedClassNames() {
+        return managedClassNames;
     }
 
-    public String getPersistenceProviderClassName() {
-        return persistenceProviderClassName;
+    public void setManagedClassNames(List<String> managedClassNames) {
+        if (managedClassNames == null) {
+            throw new NullPointerException("managedClassNames is null");
+        }
+        this.managedClassNames.clear();
+        this.managedClassNames.addAll(managedClassNames);
     }
 
-    public PersistenceUnitTransactionType getTransactionType() {
-        return transactionType;
+    public void addManagedClassName(String className) {
+        managedClassNames.add(className);
     }
 
-    public DataSource getJtaDataSource() {
-        return jtaDataSource;
+    public boolean excludeUnlistedClasses() {
+        return excludeUnlistedClasses;
     }
 
-    public DataSource getNonJtaDataSource() {
-        return nonJtaDataSource;
+    public void setExcludeUnlistedClasses(boolean excludeUnlistedClasses) {
+        this.excludeUnlistedClasses = excludeUnlistedClasses;
     }
 
-    public List<String> getMappingFileNames() {
-        return mappingFileNames;
+    public Properties getProperties() {
+        return properties;
     }
 
-    public List<URL> getJarFileUrls() {
-        return jarFileUrls;
+    public void setProperties(Properties properties) {
+        this.properties = properties;
     }
 
-    public URL getPersistenceUnitRootUrl() {
-        return persistenceUnitRootUrl;
+    public ClassLoader getClassLoader() {
+        return classLoader;
     }
 
-    public List<String> getManagedClassNames() {
-        return managedClassNames;
+    public void setClassLoader(ClassLoader classLoader) {
+        this.classLoader = classLoader;
     }
 
-    public boolean excludeUnlistedClasses() {
-        return excludeUnlistedClasses;
+    public void addTransformer(ClassTransformer classTransformer) {
+        if (persistenceClassLoaderHandler != null) {
+            PersistenceClassFileTransformer classFileTransformer = new PersistenceClassFileTransformer(classTransformer);
+            persistenceClassLoaderHandler.addTransformer(classLoader, classFileTransformer);
+        }
     }
 
-    public Properties getProperties() {
-        return vendorProperties;
+    public ClassLoader getNewTempClassLoader() {
+        if (persistenceClassLoaderHandler != null) {
+            return persistenceClassLoaderHandler.getNewTempClassLoader(classLoader);
+        } else {
+            return null;
+        }
     }
 
-    public ClassLoader getClassLoader() {
-        return classLoader;
-    }
+    public static class PersistenceClassFileTransformer implements ClassFileTransformer {
+        private final ClassTransformer classTransformer;
 
-    public void addTransformer(ClassTransformer arg0) {
-        // TODO - Need something to do here
-    }
+        public PersistenceClassFileTransformer(ClassTransformer classTransformer) {
+            this.classTransformer = classTransformer;
+        }
 
-    public ClassLoader getNewTempClassLoader() {
-        // TODO - This probably isn't correct and may need changing
-        return tempClassLoader;
+        public byte[] transform(ClassLoader classLoader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {
+            byte[] bytes = classTransformer.transform(classLoader, className.replace('/', '.'), classBeingRedefined, protectionDomain, classfileBuffer);
+            if ("org/apache/openejb/test/entity/cmp/BasicCmpBean".equals(className)) {
+                System.out.println("Transformed BasicCmpBean");
+            }
+            return bytes;
+        }
     }
-    
 }

Modified: incubator/openejb/trunk/openejb3/container/openejb-persistence/src/test/java/org/apache/openejb/persistence/OpenJpaProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-persistence/src/test/java/org/apache/openejb/persistence/OpenJpaProviderTest.java?view=diff&rev=491149&r1=491148&r2=491149
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-persistence/src/test/java/org/apache/openejb/persistence/OpenJpaProviderTest.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-persistence/src/test/java/org/apache/openejb/persistence/OpenJpaProviderTest.java Fri Dec 29 17:40:06 2006
@@ -35,7 +35,7 @@
         // @see http://publib.boulder.ibm.com/infocenter/cscv/v10r1/index.jsp?topic=/com.ibm.cloudscape.doc/cdevdvlp25889.html
         System.setProperty("derby.system.home", "target");
 
-        PersistenceDeployer deployer = new PersistenceDeployer(new TestDataSourceResolver());
+        PersistenceDeployer deployer = new PersistenceDeployer(new TestDataSourceResolver(), null);
 
         Map<String, EntityManagerFactory> map = deployer.deploy(Thread.currentThread().getContextClassLoader());
 

Modified: incubator/openejb/trunk/openejb3/container/openejb-persistence/src/test/java/org/apache/openejb/persistence/PersistenceTest.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-persistence/src/test/java/org/apache/openejb/persistence/PersistenceTest.java?view=diff&rev=491149&r1=491148&r2=491149
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-persistence/src/test/java/org/apache/openejb/persistence/PersistenceTest.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-persistence/src/test/java/org/apache/openejb/persistence/PersistenceTest.java Fri Dec 29 17:40:06 2006
@@ -51,7 +51,7 @@
             ClassLoader cl = this.getClass().getClassLoader();
 
             // Get a EntityManagerFactory list
-            PersistenceDeployer pm = new PersistenceDeployer(new GlobalJndiDataSourceResolver(null));
+            PersistenceDeployer pm = new PersistenceDeployer(new GlobalJndiDataSourceResolver(null), null);
             Map<String, EntityManagerFactory> factories = pm.deploy(cl);
             for (Map.Entry<String, EntityManagerFactory> entry : factories.entrySet()) {
                 // Store EntityManagerFactory in the JNDI

Modified: incubator/openejb/trunk/openejb3/container/pom.xml
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/pom.xml?view=diff&rev=491149&r1=491148&r2=491149
==============================================================================
--- incubator/openejb/trunk/openejb3/container/pom.xml (original)
+++ incubator/openejb/trunk/openejb3/container/pom.xml Fri Dec 29 17:40:06 2006
@@ -30,6 +30,7 @@
   <modules>
     <module>openejb-core</module>
     <module>openejb-loader</module>
+    <module>openejb-javaagent</module>
     <module>openejb-jee</module>
     <module>openejb-persistence</module>
   </modules>

Propchange: incubator/openejb/trunk/openejb3/examples/ejb-injection/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Dec 29 17:40:06 2006
@@ -0,0 +1,10 @@
+*.iws
+*.ipr
+*.iml
+.classpath
+.project
+.settings
+*.log
+junit*.properties
+target
+bin

Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/pom.xml
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/pom.xml?view=diff&rev=491149&r1=491148&r2=491149
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/pom.xml (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/pom.xml Fri Dec 29 17:40:06 2006
@@ -53,6 +53,8 @@
         <version>2.2.1</version>
     </dependency>
   </dependencies>
+
+<!--
   <build>
     <plugins>
       <plugin>
@@ -64,7 +66,7 @@
               <tasks>
                 <java classname="org.apache.openjpa.enhance.PCEnhancer">
                   <arg value="-p"/>
-                  <arg value="${basedir}/src/temp-persistence.xml"/>
+                  <arg value="${basedir}/src/main/resources/META-INF/persistence.xml"/>
                   <classpath>
                     <path refid="maven.dependency.classpath"/>
                     <path refid="maven.compile.classpath"/>
@@ -80,5 +82,6 @@
       </plugin>
     </plugins>
   </build>
+-->
 
 </project>