tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickmcgu...@apache.org
Subject svn commit: r675925 - in /openejb/trunk/openejb3: ./ container/openejb-core/src/main/java/org/apache/openejb/config/ container/openejb-core/src/main/java/org/apache/openejb/core/cmp/jpa/ container/openejb-core/src/test/java/org/apache/openejb/core/cmp/...
Date Fri, 11 Jul 2008 11:57:53 GMT
Author: rickmcguire
Date: Fri Jul 11 04:57:52 2008
New Revision: 675925

URL: http://svn.apache.org/viewvc?rev=675925&view=rev
Log:
OPENEJB-856 Upgrade to OpenJPA 1.1.0


Modified:
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/CmpJpaConversion.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/jpa/JpaCmpEngine.java
    openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/JpaTestObject.java
    openejb/trunk/openejb3/pom.xml

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/CmpJpaConversion.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/CmpJpaConversion.java?rev=675925&r1=675924&r2=675925&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/CmpJpaConversion.java
(original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/CmpJpaConversion.java
Fri Jul 11 04:57:52 2008
@@ -82,7 +82,8 @@
 
     private static final String CMP_PERSISTENCE_UNIT_NAME = "cmp";
 
-    private static final Set<String> ENHANCEED_FIELDS = Collections.unmodifiableSet(new
TreeSet<String>(Arrays.asList(
+    // A specific set of fields that get marked as transient in the superclass mappings 
+    private static final Set<String> ENHANCED_FIELDS = Collections.unmodifiableSet(new
TreeSet<String>(Arrays.asList(
             "pcInheritedFieldCount",
             "pcFieldNames",
             "pcFieldTypes",
@@ -685,7 +686,7 @@
                     }
                 }
             } catch (ClassNotFoundException e) {
-                // todo throw exception
+                throw (IllegalStateException)new IllegalStateException("Could not find entity
primary key class " + bean.getPrimKeyClass()).initCause(e);
             }
         }
 
@@ -725,11 +726,16 @@
             mapping.addField(new AttributeOverride(fieldName));
             primaryKeyFields.add(fieldName);
         } else if ("java.lang.Object".equals(bean.getPrimKeyClass())) {
+            // a primary field type of Object is an automatically generated 
+            // pk field.  Mark it as such and add it to the mapping.  
             String fieldName = "OpenEJB_pk";
             Id field = new Id(fieldName);
             field.setGeneratedValue(new GeneratedValue(GenerationType.AUTO));
             mapping.addField(field);
         } else if (bean.getPrimKeyClass() != null) {
+            // we have a primary key class.  We need to define the mappings between the key
class fields 
+            // and the bean's managed fields. 
+            
             Class<?> pkClass = null;
             try {
                 pkClass = classLoader.loadClass(bean.getPrimKeyClass());
@@ -737,6 +743,8 @@
                 for (java.lang.reflect.Field pkField : pkClass.getFields()) {
                     String fieldName = pkField.getName();
                     int modifiers = pkField.getModifiers();
+                    // the primary key fields must be public, non-static, must be defined
as a CMP field, 
+                    // AND must also exist in the class hierarchy (not enforced by mapFields());

                     if (Modifier.isPublic(modifiers) && !Modifier.isStatic(modifiers)
&& allFields.contains(fieldName)) {
                         superclass = superclassByField.get(fieldName);
                         if (superclass == null) {
@@ -751,7 +759,7 @@
                     superclass.setIdClass(new IdClass(bean.getPrimKeyClass()));
                 }
             } catch (ClassNotFoundException e) {
-                // todo throw exception
+                throw (IllegalStateException)new IllegalStateException("Could not find entity
primary key class " + bean.getPrimKeyClass()).initCause(e);
             }
         }
 
@@ -783,25 +791,41 @@
         return ejbClass;
     }
 
+    /**
+     * Build a mapping between a bean's CMP fields and the 
+     * particular subclass in the inheritance hierarchy that 
+     * defines the field. 
+     * 
+     * @param clazz  The bean implementation class.
+     * @param persistantFields
+     *               The set of container-managed fields.
+     * 
+     * @return A map of fieldname-to-defining class relationships. 
+     */
     private Map<String, MappedSuperclass> mapFields(Class clazz, Set<String>
persistantFields) {
         persistantFields = new TreeSet<String>(persistantFields);
         Map<String,MappedSuperclass> fields = new TreeMap<String,MappedSuperclass>();
 
+        // spin down the class hierarchy until we've either processed all of the fields
+        // or we've reached the Object class. 
         while (!persistantFields.isEmpty() && !clazz.equals(Object.class)) {
+            // This is a single target for the relationship mapping for each 
+            // class in the hierarchy. 
             MappedSuperclass superclass = new MappedSuperclass(clazz.getName());
             for (java.lang.reflect.Field field : clazz.getDeclaredFields()) {
                 String fieldName = field.getName();
+                // if this is one of bean's persistence fields, create the mapping 
                 if (persistantFields.contains(fieldName)) {
                     fields.put(fieldName, superclass);
                     persistantFields.remove(fieldName);
-                } else if (!ENHANCEED_FIELDS.contains(fieldName)){
+                } else if (!ENHANCED_FIELDS.contains(fieldName)){
+                    // these are fields we need to identify as transient for the persistence
engine. 
                     Transient transientField = new Transient(fieldName);
                     superclass.addField(transientField);
                 }
             }
             clazz = clazz.getSuperclass();
         }
-
         return fields;
     }
 

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/jpa/JpaCmpEngine.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/jpa/JpaCmpEngine.java?rev=675925&r1=675924&r2=675925&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/jpa/JpaCmpEngine.java
(original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/jpa/JpaCmpEngine.java
Fri Jul 11 04:57:52 2008
@@ -143,9 +143,6 @@
             KeyGenerator kg = deploymentInfo.getKeyGenerator();
             Object primaryKey = kg.getPrimaryKey(bean);
 
-            // add to transaction cache
-            getTransactionCache().put(deploymentInfo.getCmpImplClass(), primaryKey, bean);
-
             return primaryKey;
         } finally {
             creating.get().remove(bean);
@@ -159,14 +156,9 @@
             CoreDeploymentInfo deploymentInfo = callContext.getDeploymentInfo();
             Class<?> beanClass = deploymentInfo.getCmpImplClass();
 
-            // First check the transaction cache
-            Object bean = getTransactionCache().get(beanClass, primaryKey);
-            if (bean == null) {
-                // Try to load it from the entity manager
-                EntityManager entityManager = getEntityManager(deploymentInfo);
-                bean = entityManager.find(beanClass, primaryKey);
-            }
-            return bean;
+            // Try to load it from the entity manager
+            EntityManager entityManager = getEntityManager(deploymentInfo);
+            return entityManager.find(beanClass, primaryKey);
         } finally {
             commitTransaction(startedTx, "load");
         }
@@ -195,16 +187,10 @@
             EntityManager entityManager = getEntityManager(deploymentInfo);
             Object primaryKey = callContext.getPrimaryKey();
 
-            // First check the transaction cache
-            Object bean = getTransactionCache().get(beanClass, primaryKey);
-            if (bean == null) {
                 // Try to load it from the entity manager
-                bean = entityManager.find(beanClass, primaryKey);
-            }
-
+            Object bean = entityManager.find(beanClass, primaryKey);
             // remove the bean
             entityManager.remove(bean);
-            getTransactionCache().remove(beanClass, primaryKey);
         } finally {
             commitTransaction(startedTx, "remove");
         }
@@ -372,16 +358,6 @@
         }
     }
 
-    // todo remove when OpenJPA fixes the new-remove-new-find bug
-    private TransactionCache getTransactionCache() {
-        TransactionCache transactionCache = (TransactionCache) synchronizationRegistry.getResource(TransactionCache.class);
-        if (transactionCache == null) {
-            transactionCache = new TransactionCache();
-            synchronizationRegistry.putResource(TransactionCache.class, transactionCache);
-        }
-        return transactionCache;
-    }
-
     private static class TransactionCache {
         private final Map<Class,Map<Object,Object>> cache = new HashMap<Class,Map<Object,Object>>();
 

Modified: openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/JpaTestObject.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/JpaTestObject.java?rev=675925&r1=675924&r2=675925&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/JpaTestObject.java
(original)
+++ openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/JpaTestObject.java
Fri Jul 11 04:57:52 2008
@@ -173,8 +173,8 @@
 
         // Find and verify
         dain = entityManager.find(Person.class, "dain");
-        // assertNotNull(dain); // <<<<<<< FAILS
-        // assertEquals("dain", dain.getName());
+        assertNotNull(dain); // <<<<<<< FAILS
+        assertEquals("dain", dain.getName());
 
         commitTx();
     }

Modified: openejb/trunk/openejb3/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/pom.xml?rev=675925&r1=675924&r2=675925&view=diff
==============================================================================
--- openejb/trunk/openejb3/pom.xml (original)
+++ openejb/trunk/openejb3/pom.xml Fri Jul 11 04:57:52 2008
@@ -717,7 +717,7 @@
       <dependency>
         <groupId>org.apache.openjpa</groupId>
         <artifactId>openjpa</artifactId>
-        <version>1.0.1</version>
+        <version>1.1.0</version>
         <exclusions>
           <exclusion>
             <groupId>org.apache.openjpa</groupId>



Mime
View raw message