Author: dain
Date: Mon Aug 13 17:15:51 2007
New Revision: 565584

URL: http://svn.apache.org/viewvc?view=rev&rev=565584
Log:
Tests to show unenhanced class bugs with OpenJPA

Added:
    
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/ComplexId.java
    
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/ComplexStandalone.java
    
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/ComplexSubclass.java
    
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/ComplexSuperclass.java
    
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/GeneratedStandalone.java
    
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/GeneratedSubclass.java
    
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/GeneratedSuperclass.java
    
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/ManyStandalone.java
    
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/OneStandalone.java
    
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/UnenhancedTest.java
    
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/UnenhancedUnits.java
Removed:
    
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/JpaEnhancedTest.java

Added: 
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/ComplexId.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/ComplexId.java?view=auto&rev=565584
==============================================================================
--- 
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/ComplexId.java
 (added)
+++ 
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/ComplexId.java
 Mon Aug 13 17:15:51 2007
@@ -0,0 +1,42 @@
+/**
+ *
+ * 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;
+
+public class ComplexId {
+    public String firstId;
+    public String secondId;
+
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        ComplexId complexId = (ComplexId) o;
+
+        if (secondId != null ? !secondId.equals(complexId.secondId) : 
complexId.secondId != null) return false;
+        if (firstId != null ? !firstId.equals(complexId.firstId) : 
complexId.firstId != null) return false;
+
+        return true;
+    }
+
+    public int hashCode() {
+        int result;
+        result = (firstId != null ? firstId.hashCode() : 0);
+        result = 31 * result + (secondId != null ? secondId.hashCode() : 0);
+        return result;
+    }
+}

Added: 
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/ComplexStandalone.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/ComplexStandalone.java?view=auto&rev=565584
==============================================================================
--- 
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/ComplexStandalone.java
 (added)
+++ 
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/ComplexStandalone.java
 Mon Aug 13 17:15:51 2007
@@ -0,0 +1,61 @@
+/**
+ *
+ * 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 javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.IdClass;
+
[EMAIL PROTECTED]
[EMAIL PROTECTED](ComplexId.class)
+public class ComplexStandalone {
+    @Id
+    public String firstId;
+    @Id
+    public String secondId;
+
+
+    public ComplexStandalone() {
+    }
+
+    public ComplexStandalone(String firstId, String secondId) {
+        this.firstId = firstId;
+        this.secondId = secondId;
+    }
+
+    public void initializeIds(String firstId, String secondId) {
+        this.firstId = firstId;
+        this.secondId = secondId;
+    }
+
+    public String getFirstId() {
+        return firstId;
+    }
+
+    public void setFirstId(String firstId) {
+        this.firstId = firstId;
+    }
+
+    public String getSecondId() {
+        return secondId;
+    }
+
+    public void setSecondId(String secondId) {
+        this.secondId = secondId;
+    }
+}

Added: 
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/ComplexSubclass.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/ComplexSubclass.java?view=auto&rev=565584
==============================================================================
--- 
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/ComplexSubclass.java
 (added)
+++ 
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/ComplexSubclass.java
 Mon Aug 13 17:15:51 2007
@@ -0,0 +1,30 @@
+/**
+ *
+ * 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 javax.persistence.Entity;
+
[EMAIL PROTECTED]
+public class ComplexSubclass extends ComplexSuperclass {
+    public ComplexSubclass() {
+    }
+
+    public ComplexSubclass(String firstId, String secondId) {
+        super(firstId, secondId);
+    }
+}

Added: 
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/ComplexSuperclass.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/ComplexSuperclass.java?view=auto&rev=565584
==============================================================================
--- 
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/ComplexSuperclass.java
 (added)
+++ 
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/ComplexSuperclass.java
 Mon Aug 13 17:15:51 2007
@@ -0,0 +1,61 @@
+/**
+ *
+ * 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 javax.persistence.Id;
+import javax.persistence.IdClass;
+import javax.persistence.MappedSuperclass;
+
[EMAIL PROTECTED]
[EMAIL PROTECTED](ComplexId.class)
+public class ComplexSuperclass {
+    @Id
+    public String firstId;
+    @Id
+    public String secondId;
+
+
+    public ComplexSuperclass() {
+    }
+
+    public ComplexSuperclass(String firstId, String secondId) {
+        this.firstId = firstId;
+        this.secondId = secondId;
+    }
+
+    public void initializeIds(String firstId, String secondId) {
+        this.firstId = firstId;
+        this.secondId = secondId;
+    }
+
+    public String getFirstId() {
+        return firstId;
+    }
+
+    public void setFirstId(String firstId) {
+        this.firstId = firstId;
+    }
+
+    public String getSecondId() {
+        return secondId;
+    }
+
+    public void setSecondId(String secondId) {
+        this.secondId = secondId;
+    }
+}

Added: 
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/GeneratedStandalone.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/GeneratedStandalone.java?view=auto&rev=565584
==============================================================================
--- 
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/GeneratedStandalone.java
 (added)
+++ 
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/GeneratedStandalone.java
 Mon Aug 13 17:15:51 2007
@@ -0,0 +1,36 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.openejb.core.cmp.jpa;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
[EMAIL PROTECTED]
+public class GeneratedStandalone {
+    @Id
+    @GeneratedValue
+    public Long id;
+
+    public GeneratedStandalone() {
+    }
+
+    public Object getId() {
+        return id;
+    }
+}

Added: 
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/GeneratedSubclass.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/GeneratedSubclass.java?view=auto&rev=565584
==============================================================================
--- 
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/GeneratedSubclass.java
 (added)
+++ 
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/GeneratedSubclass.java
 Mon Aug 13 17:15:51 2007
@@ -0,0 +1,27 @@
+/**
+ *
+ * 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 javax.persistence.MappedSuperclass;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Entity;
+
[EMAIL PROTECTED]
+public class GeneratedSubclass extends GeneratedSuperclass {
+}

Added: 
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/GeneratedSuperclass.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/GeneratedSuperclass.java?view=auto&rev=565584
==============================================================================
--- 
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/GeneratedSuperclass.java
 (added)
+++ 
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/GeneratedSuperclass.java
 Mon Aug 13 17:15:51 2007
@@ -0,0 +1,36 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.openejb.core.cmp.jpa;
+
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.MappedSuperclass;
+
[EMAIL PROTECTED]
+public class GeneratedSuperclass {
+    @Id
+    @GeneratedValue
+    public Long id;
+
+    public GeneratedSuperclass() {
+    }
+
+    public Object getId() {
+        return id;
+    }
+}

Added: 
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/ManyStandalone.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/ManyStandalone.java?view=auto&rev=565584
==============================================================================
--- 
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/ManyStandalone.java
 (added)
+++ 
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/ManyStandalone.java
 Mon Aug 13 17:15:51 2007
@@ -0,0 +1,50 @@
+/**
+ *
+ * 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 javax.persistence.Entity;
+import javax.persistence.ManyToOne;
+import javax.persistence.Id;
+
[EMAIL PROTECTED]
+public class ManyStandalone {
+    @Id
+    private long id;
+
+    @ManyToOne
+    private OneStandalone one;
+
+    public ManyStandalone() {
+    }
+
+    public ManyStandalone(long id) {
+        this.id = id;
+    }
+
+    public long getId() {
+        return id;
+    }
+
+    public OneStandalone getOne() {
+        return one;
+    }
+
+    public void setOne(OneStandalone one) {
+        this.one = one;
+    }
+}

Added: 
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/OneStandalone.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/OneStandalone.java?view=auto&rev=565584
==============================================================================
--- 
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/OneStandalone.java
 (added)
+++ 
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/OneStandalone.java
 Mon Aug 13 17:15:51 2007
@@ -0,0 +1,51 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.openejb.core.cmp.jpa;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+import java.util.ArrayList;
+import java.util.Collection;
+
[EMAIL PROTECTED]
+public class OneStandalone {
+    @Id
+    private long id;
+    @OneToMany
+    private Collection<ManyStandalone> many = new ArrayList<ManyStandalone>();
+
+    public OneStandalone() {
+    }
+
+    public OneStandalone(long id) {
+        this.id = id;
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public Collection<ManyStandalone> getMany() {
+        return many;
+    }
+
+    public void setMany(Collection<ManyStandalone> many) {
+        this.many = many;
+    }
+}

Added: 
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/UnenhancedTest.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/UnenhancedTest.java?view=auto&rev=565584
==============================================================================
--- 
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/UnenhancedTest.java
 (added)
+++ 
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/UnenhancedTest.java
 Mon Aug 13 17:15:51 2007
@@ -0,0 +1,403 @@
+/**
+ *
+ * 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 junit.framework.TestCase;
+import org.apache.commons.dbcp.BasicDataSource;
+import org.apache.geronimo.transaction.manager.GeronimoTransactionManager;
+import org.apache.openejb.core.TemporaryClassLoader;
+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.resource.SharedLocalConnectionManager;
+import org.apache.openejb.resource.jdbc.JdbcManagedConnectionFactory;
+
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.spi.PersistenceProvider;
+import javax.persistence.spi.PersistenceUnitTransactionType;
+import javax.sql.DataSource;
+import javax.transaction.TransactionManager;
+import javax.transaction.TransactionSynchronizationRegistry;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.instrument.ClassFileTransformer;
+import java.lang.instrument.IllegalClassFormatException;
+import java.lang.instrument.Instrumentation;
+import java.lang.reflect.InvocationTargetException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.security.ProtectionDomain;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.HashMap;
+import java.util.Properties;
+
+public class UnenhancedTest extends TestCase {
+    private static final String PERSISTENCE_PROVIDER = 
"org.apache.openjpa.persistence.PersistenceProviderImpl";
+
+    private GeronimoTransactionManager transactionManager;
+    private DataSource jtaDs;
+    private DataSource nonJtaDs;
+    private EntityManagerFactory entityManagerFactory;
+
+    private boolean enhance;
+
+    public void setUp() throws Exception {
+        super.setUp();
+
+        // setup tx mgr
+        transactionManager = new GeronimoTransactionManager();
+        
SystemInstance.get().setComponent(TransactionSynchronizationRegistry.class, 
transactionManager);
+
+        // Put tx mgr into SystemInstance so OpenJPA can find it
+        SystemInstance.get().setComponent(TransactionManager.class, 
transactionManager);
+
+        // init databases
+        jtaDs = createJtaDataSource(transactionManager);
+        nonJtaDs = createNonJtaDataSource();
+    }
+
+    public void tearDown() throws Exception {
+        if (entityManagerFactory != null && entityManagerFactory.isOpen()) {
+            entityManagerFactory.close();
+        }
+
+        if (nonJtaDs != null) {
+            Connection connection = nonJtaDs.getConnection();
+            Statement statement = connection.createStatement();
+            statement.execute("SHUTDOWN");
+            close(statement);
+            close(connection);
+        }
+
+        nonJtaDs = null;
+        jtaDs = null;
+
+        // diable any enhancers we added
+        enhance = false;
+
+        super.tearDown();
+    }
+
+    public void testEnhancedComplexIdJta() throws Exception {
+        runTest("complexId", PersistenceUnitTransactionType.JTA, true);
+    }
+
+    public void testEnhancedComplexIdResourceLocal() throws Exception {
+        runTest("complexId", PersistenceUnitTransactionType.RESOURCE_LOCAL, 
true);
+    }
+
+    public void testUnenhancedComplexIdJta() throws Exception {
+        runTest("complexId", PersistenceUnitTransactionType.JTA, false);
+    }
+
+    public void testUnenhancedComplexIdResourceLocal() throws Exception {
+        runTest("complexId", PersistenceUnitTransactionType.RESOURCE_LOCAL, 
false);
+    }
+
+    public void testEnhancedComplexIdSubclassJta() throws Exception {
+        runTest("complexIdSubclass", PersistenceUnitTransactionType.JTA, true);
+    }
+
+    public void testEnhancedComplexIdSubclassResourceLocal() throws Exception {
+        runTest("complexIdSubclass", 
PersistenceUnitTransactionType.RESOURCE_LOCAL, true);
+    }
+
+    // todo OpenJPA
+    public void XtestUnenhancedComplexIdSubclassJta() throws Exception {
+        runTest("complexIdSubclass", PersistenceUnitTransactionType.JTA, 
false);
+    }
+
+    // todo OpenJPA
+    public void XtestUnenhancedComplexIdSubclassResourceLocal() throws 
Exception {
+        runTest("complexIdSubclass", 
PersistenceUnitTransactionType.RESOURCE_LOCAL, false);
+    }
+
+    public void testEnhancedGeneratedIdJta() throws Exception {
+        runTest("generatedId", PersistenceUnitTransactionType.JTA, true);
+    }
+
+    public void testEnhancedGeneratedIdResourceLocal() throws Exception {
+        runTest("generatedId", PersistenceUnitTransactionType.RESOURCE_LOCAL, 
true);
+    }
+
+    // todo OpenJPA
+    public void XtestUnenhancedGeneratedIdJta() throws Exception {
+        runTest("generatedId", PersistenceUnitTransactionType.JTA, false);
+    }
+
+    // todo OpenJPA
+    public void XtestUnenhancedGeneratedIdResourceLocal() throws Exception {
+        runTest("generatedId", PersistenceUnitTransactionType.RESOURCE_LOCAL, 
false);
+    }
+
+    public void testEnhancedGeneratedIdSubclassJta() throws Exception {
+        runTest("generatedIdSubclass", PersistenceUnitTransactionType.JTA, 
true);
+    }
+
+    public void testEnhancedGeneratedIdSubclassResourceLocal() throws 
Exception {
+        runTest("generatedIdSubclass", 
PersistenceUnitTransactionType.RESOURCE_LOCAL, true);
+    }
+
+    // todo OpenJPA
+    public void XtestUnenhancedGeneratedIdSubclassJta() throws Exception {
+        runTest("generatedIdSubclass", PersistenceUnitTransactionType.JTA, 
false);
+    }
+
+    // todo OpenJPA
+    public void XtestUnenhancedGeneratedIdSubclassResourceLocal() throws 
Exception {
+        runTest("generatedIdSubclass", 
PersistenceUnitTransactionType.RESOURCE_LOCAL, false);
+    }
+
+    public void testEnhancedCollectionJta() throws Exception {
+        runTest("collection", PersistenceUnitTransactionType.JTA, true);
+    }
+
+    public void testEnhancedCollectionResourceLocal() throws Exception {
+        runTest("collection", PersistenceUnitTransactionType.RESOURCE_LOCAL, 
true);
+    }
+
+    // todo OpenJPA
+    public void XtestUnenhancedCollectionJta() throws Exception {
+        runTest("collection", PersistenceUnitTransactionType.JTA, false);
+    }
+
+    // todo OpenJPA
+    public void XtestUnenhancedCollectionResourceLocal() throws Exception {
+        runTest("collection", PersistenceUnitTransactionType.RESOURCE_LOCAL, 
false);
+    }
+
+    private void runTest(String methodName, PersistenceUnitTransactionType 
transactionType, boolean enhance) throws Exception {
+        this.enhance = enhance;
+
+        ClassLoader loader = new 
FilteredChildFirstClassLoader(getClass().getClassLoader(), 
"org.apache.openejb.core.cmp.jpa");
+
+        PersistenceClassLoaderHandler persistenceClassLoaderHandler = new 
PersistenceClassLoaderHandler() {
+            public void addTransformer(ClassLoader classLoader, 
ClassFileTransformer classFileTransformer) {
+                Instrumentation instrumentation = Agent.getInstrumentation();
+                if (instrumentation != null) {
+                    instrumentation.addTransformer(new 
ControllableTransformer(classFileTransformer));
+                }
+            }
+
+            public ClassLoader getNewTempClassLoader(ClassLoader classLoader) {
+                return new TemporaryClassLoader(classLoader);
+            }
+        };
+
+        PersistenceUnitInfoImpl unitInfo = new 
PersistenceUnitInfoImpl(persistenceClassLoaderHandler);
+        unitInfo.setPersistenceUnitName("CMP");
+        unitInfo.setPersistenceProviderClassName(PERSISTENCE_PROVIDER);
+        unitInfo.setClassLoader(loader);
+        unitInfo.setExcludeUnlistedClasses(false);
+        unitInfo.setJtaDataSource(jtaDs);
+        unitInfo.setNonJtaDataSource(nonJtaDs);
+        
unitInfo.addManagedClassName("org.apache.openejb.core.cmp.jpa.ComplexSuperclass");
+        
unitInfo.addManagedClassName("org.apache.openejb.core.cmp.jpa.ComplexSubclass");
+        
unitInfo.addManagedClassName("org.apache.openejb.core.cmp.jpa.ComplexStandalone");
+        
unitInfo.addManagedClassName("org.apache.openejb.core.cmp.jpa.GeneratedStandalone");
+        
unitInfo.addManagedClassName("org.apache.openejb.core.cmp.jpa.GeneratedSuperclass");
+        
unitInfo.addManagedClassName("org.apache.openejb.core.cmp.jpa.GeneratedSubclass");
+        
unitInfo.addManagedClassName("org.apache.openejb.core.cmp.jpa.OneStandalone");
+        
unitInfo.addManagedClassName("org.apache.openejb.core.cmp.jpa.ManyStandalone");
+
+        // Handle Properties
+        Properties properties = new Properties();
+        properties.setProperty("openjpa.jdbc.SynchronizeMappings", 
"buildSchema(SchemaAction='add,deleteTableContents',ForeignKeys=true)");
+        properties.setProperty("openjpa.Log", "DefaultLevel=WARN");
+        unitInfo.setProperties(properties);
+
+        unitInfo.setTransactionType(transactionType);
+
+        
unitInfo.getManagedClassNames().add("org.apache.openejb.core.cmp.jpa.Employee");
+
+        PersistenceProvider persistenceProvider = (PersistenceProvider) 
getClass().getClassLoader().loadClass(PERSISTENCE_PROVIDER).newInstance();
+        entityManagerFactory = 
persistenceProvider.createContainerEntityManagerFactory(unitInfo, new 
HashMap());
+
+
+        // create the test object (via reflection)
+        Object testObject = 
loader.loadClass("org.apache.openejb.core.cmp.jpa.UnenhancedUnits").newInstance();
+        set(testObject, "TransactionManager", TransactionManager.class, 
transactionManager);
+        set(testObject, "EntityManagerFactory", EntityManagerFactory.class, 
entityManagerFactory);
+
+
+        // invoke the test (via reflection)
+        Thread.currentThread().setContextClassLoader(loader);
+        invoke(testObject, "setUp");
+        try {
+            invoke(testObject, methodName);
+        } finally {
+            invoke(testObject, "tearDown");
+        }
+    }
+
+    private DataSource createJtaDataSource(TransactionManager 
transactionManager) throws Exception {
+        JdbcManagedConnectionFactory mcf = new 
JdbcManagedConnectionFactory("org.hsqldb.jdbcDriver", 
"jdbc:hsqldb:mem:JpaTest", "sa", "", false);
+
+        SharedLocalConnectionManager connectionManager = new 
SharedLocalConnectionManager(transactionManager);
+
+        DataSource connectionFactory = (DataSource) 
mcf.createConnectionFactory(connectionManager);
+        return connectionFactory;
+    }
+
+    private DataSource createNonJtaDataSource() throws Exception {
+        BasicDataSource ds = new BasicDataSource();
+        ds.setDriverClassName("org.hsqldb.jdbcDriver");
+        ds.setUrl("jdbc:hsqldb:mem:JpaTest");
+        ds.setUsername("sa");
+        ds.setPassword("");
+        ds.setMaxActive(100);
+        ds.setMaxWait(10000);
+        ds.setTestOnBorrow(true);
+        return ds;
+    }
+
+    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 static void invoke(Object instance, String methodName) throws 
Exception {
+        try {
+            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 {
+                throw 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) {
+        }
+    }
+
+    private class ControllableTransformer implements ClassFileTransformer {
+        private final ClassFileTransformer transformer;
+
+
+        public ControllableTransformer(ClassFileTransformer transformer) {
+            this.transformer = transformer;
+        }
+
+
+        public byte[] transform(ClassLoader loader, String className, Class<?> 
classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) 
throws IllegalClassFormatException {
+            if (enhance) {
+                return transformer.transform(loader, className, 
classBeingRedefined, protectionDomain, classfileBuffer);
+            } else {
+                return null;
+            }
+        }
+    }
+
+    public class FilteredChildFirstClassLoader extends URLClassLoader {
+        protected String packagePrefix;
+
+        public FilteredChildFirstClassLoader(ClassLoader parent, String 
packagePrefix) {
+            super(new URL[0], parent);
+            this.packagePrefix = packagePrefix;
+        }
+
+        public Class loadClass(String name) throws ClassNotFoundException {
+            return loadClass(name, false);
+        }
+
+        protected synchronized Class loadClass(String name, boolean resolve) 
throws ClassNotFoundException {
+            // see if we've already loaded it
+            Class c = findLoadedClass(name);
+            if (c != null) {
+                return c;
+            }
+
+            if (!name.startsWith(packagePrefix)) {
+                return Class.forName(name, resolve, getParent());
+            }
+
+            String resourceName = name.replace('.', '/') + ".class";
+            InputStream in = getResourceAsStream(resourceName);
+            if (in == null) {
+                throw new ClassNotFoundException(name);
+            }
+
+            // 80% of class files are smaller then 6k
+            ByteArrayOutputStream bout = new ByteArrayOutputStream(8 * 1024);
+
+            // copy the input stream into a byte array
+            byte[] bytes = new byte[0];
+            try {
+                byte[] buf = new byte[4 * 1024];
+                for (int count = -1; (count = in.read(buf)) >= 0;) {
+                    bout.write(buf, 0, count);
+                }
+                bytes = bout.toByteArray();
+            } catch (IOException e) {
+                throw new ClassNotFoundException(name, e);
+            }
+
+            // define the package
+            int packageEndIndex = name.lastIndexOf('.');
+            if (packageEndIndex != -1) {
+                String packageName = name.substring(0, packageEndIndex);
+                if (getPackage(packageName) == null) {
+                    definePackage(packageName, null, null, null, null, null, 
null, null);
+                }
+            }
+
+            // define the class
+            try {
+                return defineClass(name, bytes, 0, bytes.length);
+            } catch (SecurityException e) {
+                // possible prohibited package: defer to the parent
+                return super.loadClass(name, resolve);
+            }
+        }
+    }
+}

Added: 
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/UnenhancedUnits.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/UnenhancedUnits.java?view=auto&rev=565584
==============================================================================
--- 
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/UnenhancedUnits.java
 (added)
+++ 
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/UnenhancedUnits.java
 Mon Aug 13 17:15:51 2007
@@ -0,0 +1,280 @@
+/**
+ *
+ * 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 junit.framework.Assert;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityTransaction;
+import javax.transaction.Status;
+import javax.transaction.TransactionManager;
+import java.util.Collection;
+
+public class UnenhancedUnits extends Assert {
+    private EntityManagerFactory entityManagerFactory;
+    private TransactionManager transactionManager;
+
+    private EntityManager entityManager;
+    private EntityTransaction transaction;
+
+    public void setTransactionManager(TransactionManager transactionManager) {
+        this.transactionManager = transactionManager;
+    }
+
+    public void setEntityManagerFactory(EntityManagerFactory 
entityManagerFactory) {
+        this.entityManagerFactory = entityManagerFactory;
+    }
+
+    public void setUp() throws Exception {
+    }
+
+    public void tearDown() throws Exception {
+        if (entityManager != null && entityManager.isOpen()) {
+            if (transaction != null) {
+                try {
+                    if (transaction.getRollbackOnly()) {
+                        transaction.rollback();
+                    } else {
+                        transaction.commit();
+                    }
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            } else {
+                try {
+                    if (transactionManager.getStatus() != 
Status.STATUS_NO_TRANSACTION) {
+                        transactionManager.rollback();
+                    }
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            }
+            entityManager.close();
+        }
+
+        entityManager = null;
+        entityManagerFactory = null;
+        transactionManager = null;
+    }
+
+    public void complexId() throws Exception {
+        beginTx();
+
+        // constructor
+        ComplexStandalone complex = new ComplexStandalone("first", "second");
+
+        // em should not know about our entity
+        assertFalse(entityManager.contains(complex));
+
+        // persist the entity
+        entityManager.persist(complex);
+
+        // em should now be aware of our entity
+        assertTrue(entityManager.contains(complex));
+
+        commitTx();
+    }
+
+    public void complexIdSubclass() throws Exception {
+        beginTx();
+
+        // create entity
+        ComplexSuperclass complex = new ComplexSubclass();
+        complex.firstId = "first";
+        complex.secondId = "second";
+
+        // em should not know about our entity
+        assertFalse(entityManager.contains(complex));
+
+        // persist the entity
+        entityManager.persist(complex);
+
+        // em should now be aware of our entity
+        assertTrue(entityManager.contains(complex));
+
+        commitTx();
+    }
+
+    public void generatedId() throws Exception {
+        beginTx();
+
+        // constructor
+        GeneratedStandalone generated = new GeneratedStandalone();
+
+        // entity should not have an id yet
+        assertNull("generated.getId() is not null", generated.getId());
+
+        // em should not know about our entity
+        assertFalse(entityManager.contains(generated));
+
+        // persist the entity
+        entityManager.persist(generated);
+        entityManager.flush();
+
+        // entity should now have an id
+        assertNotNull("generated.getId() is null", generated.getId());
+
+        // em should now be aware of our entity
+        assertTrue(entityManager.contains(generated));
+
+        commitTx();
+    }
+
+    public void generatedIdSubclass() throws Exception {
+        beginTx();
+
+        // constructor
+        GeneratedSuperclass generated = new GeneratedSubclass();
+
+        // entity should not have an id yet
+        assertNull("generated.getId() is not null", generated.getId());
+
+        // em should not know about our entity
+        assertFalse(entityManager.contains(generated));
+
+        // persist the entity
+        entityManager.persist(generated);
+        entityManager.flush();
+
+        // entity should now have an id
+        assertNotNull("generated.getId() is null", generated.getId());
+
+        // em should now be aware of our entity
+        assertTrue(entityManager.contains(generated));
+
+        commitTx();
+    }
+
+    public void collection() throws Exception {
+        beginTx();
+
+        OneStandalone one = new OneStandalone(1000);
+
+        ManyStandalone manyA = new ManyStandalone(1);
+        one.getMany().add(manyA);
+        manyA.setOne(one);
+
+        ManyStandalone manyB = new ManyStandalone(2);
+        one.getMany().add(manyB);
+        manyB.setOne(one);
+
+        ManyStandalone manyC = new ManyStandalone(3);
+        one.getMany().add(manyC);
+        manyC.setOne(one);
+
+        // em should not know about our entities
+        assertFalse(entityManager.contains(one));
+        assertFalse(entityManager.contains(manyA));
+        assertFalse(entityManager.contains(manyB));
+        assertFalse(entityManager.contains(manyC));
+
+        // persist the entity
+        entityManager.persist(one);
+        entityManager.persist(manyA);
+        entityManager.persist(manyB);
+        entityManager.persist(manyC);
+        entityManager.flush();
+
+        // em should now be aware of our entity
+        assertTrue(entityManager.contains(one));
+        assertTrue(entityManager.contains(manyA));
+        assertTrue(entityManager.contains(manyB));
+        assertTrue(entityManager.contains(manyC));
+
+        commitTx();
+
+        one = null;
+        manyA = null;
+        manyB = null;
+        manyC = null;
+
+        beginTx();
+
+        // reload one
+        one = entityManager.find(OneStandalone.class, 1000);
+        assertNotNull("one is null", one);
+
+        // verify one.getMany()
+        assertNotNull("one.getMany() is null", one.getMany());
+        Collection<ManyStandalone> many = one.getMany();
+        assertEquals(3, many.size());
+
+        // reload the many
+        manyA = entityManager.find(ManyStandalone.class, 1);
+        assertNotNull("manyA is null", manyA);
+        manyB = entityManager.find(ManyStandalone.class, 2);
+        assertNotNull("manyB is null", manyA);
+        manyC = entityManager.find(ManyStandalone.class, 3);
+        assertNotNull("manyc is null", manyA);
+
+        // verify many.getOne()
+        assertNotNull("manyA.getOne() is null", manyA.getOne());
+        assertEquals(one, manyA.getOne());
+        assertNotNull("manyB.getOne() is null", manyB.getOne());
+        assertEquals(one, manyB.getOne());
+        assertNotNull("manyC.getOne() is null", manyC.getOne());
+        assertEquals(one, manyC.getOne());
+
+        // verify collection contains each many
+        assertTrue(many.contains(manyA));
+        assertTrue(many.contains(manyB));
+        assertTrue(many.contains(manyC));
+
+        commitTx();
+    }
+
+    private void beginTx() throws Exception {
+        entityManager = entityManagerFactory.createEntityManager();
+
+        try {
+            transaction = entityManager.getTransaction();
+        } catch (Exception e) {
+            // must be JTA
+        }
+
+        log("BEGIN_TX");
+        if (transaction == null) {
+            transactionManager.begin();
+            entityManager.joinTransaction();
+        } else {
+            transaction.begin();
+        }
+    }
+
+    private void commitTx() throws Exception {
+        log("  BEFORE_COMMIT_TX");
+        try {
+            if (transaction == null) {
+                transactionManager.commit();
+            } else {
+                transaction.commit();
+            }
+        } finally {
+            if (entityManager != null && entityManager.isOpen()) {
+                entityManager.close();
+            }
+            entityManager = null;
+            log("AFTER_COMMIT_TX");
+        }
+    }
+
+    public void log(String msg) {
+//        System.out.println(msg);
+    }
+}


Reply via email to