openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From awh...@apache.org
Subject svn commit: r472193 - in /incubator/openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ openjpa-persistence/src/main/java/org/apache/openjpa/persistence/ openjpa-persis...
Date Tue, 07 Nov 2006 18:37:33 GMT
Author: awhite
Date: Tue Nov  7 10:37:33 2006
New Revision: 472193

URL: http://svn.apache.org/viewvc?view=rev&rev=472193
Log:
Fix recently-introduced bugs in conversion between JPA facades and underlying
components.


Modified:
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/DiscriminatorMappingInfo.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ValueMapDiscriminatorStrategy.java
    incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/OpenJPAPersistence.java
    incubator/openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/DiscriminatorMappingInfo.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/DiscriminatorMappingInfo.java?view=diff&rev=472193&r1=472192&r2=472193
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/DiscriminatorMappingInfo.java
(original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/DiscriminatorMappingInfo.java
Tue Nov  7 10:37:33 2006
@@ -79,7 +79,7 @@
             }
         }
         if ("null".equalsIgnoreCase(_value))
-            return (Discriminator.NULL);
+            return Discriminator.NULL;
 
         // strip quotes
         if (_value.length() > 0 && _value.charAt(0) == '\'')

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ValueMapDiscriminatorStrategy.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ValueMapDiscriminatorStrategy.java?view=diff&rev=472193&r1=472192&r2=472193
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ValueMapDiscriminatorStrategy.java
(original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ValueMapDiscriminatorStrategy.java
Tue Nov  7 10:37:33 2006
@@ -93,9 +93,8 @@
         if (cls != null)
             return cls;
         throw new ClassNotFoundException(_loc.get("unknown-discrim-value",
-            new Object[]{ str,
-                disc.getClassMapping().getDescribedType().getName(),
-                new TreeSet(_vals.keySet()) }).getMessage());
+            new Object[]{ str, disc.getClassMapping().getDescribedType().
+            getName(), new TreeSet(_vals.keySet()) }).getMessage());
     }
 
     /**
@@ -123,6 +122,8 @@
             throw new MetaDataException(_loc.get("no-discrim-value",
                 disc.getClassMapping()));
 
+        // we set the value before mapping to use to calculate the template
+        // column's java type
         disc.setValue(val);
         super.map(adapt);
     }

Modified: incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/OpenJPAPersistence.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/OpenJPAPersistence.java?view=diff&rev=472193&r1=472192&r2=472193
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/OpenJPAPersistence.java
(original)
+++ incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/OpenJPAPersistence.java
Tue Nov  7 10:37:33 2006
@@ -85,8 +85,17 @@
     public static BrokerFactory toBrokerFactory(EntityManagerFactory emf) {
         if (emf == null)
             return null;
-        emf = (EntityManagerFactory) 
-            ((OpenJPAEntityManagerFactory) emf).getUserObject(EMF_KEY);        
+        if (!(emf instanceof EntityManagerFactoryImpl)) {
+            Class c = emf.getClass();
+            try {
+                // either cast here may fail
+                emf = (EntityManagerFactoryImpl) ((OpenJPAEntityManagerFactory)
+                    emf).getUserObject(EMF_KEY);
+            } catch (ClassCastException cce) {
+                throw new ArgumentException(_loc.get
+                    ("cant-convert-brokerfactory", c), null, null, false);
+            }
+        }
         return ((EntityManagerFactoryImpl) emf).getBrokerFactory();
     }
 
@@ -122,8 +131,18 @@
     public static Broker toBroker(EntityManager em) {
         if (em == null)
             return null;
-        em = (EntityManager) ((OpenJPAEntityManager) em).getUserObject(EM_KEY);
-        return (em == null) ? null : ((EntityManagerImpl) em).getBroker();
+        if (!(em instanceof EntityManagerImpl)) {
+            Class c = em.getClass();
+            try {
+                // either cast here may fail
+                em = (EntityManagerImpl) ((OpenJPAEntityManager) em).
+                    getUserObject(EM_KEY);
+            } catch (ClassCastException cce) {
+                throw new ArgumentException(_loc.get("cant-convert-broker", c),
+                    null, null, false);
+            }
+        }
+        return ((EntityManagerImpl) em).getBroker();
     }
 
     /**

Modified: incubator/openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties?view=diff&rev=472193&r1=472192&r2=472193
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties
(original)
+++ incubator/openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties
Tue Nov  7 10:37:33 2006
@@ -90,6 +90,10 @@
     to "{1}"
 unrecognized-provider: WARNING: Found unrecognized persistence provider "{0}" \
     in place of OpenJPA provider.  This provider's properties will not be used.
+cant-convert-brokerfactory: Unable to convert EntityManagerFactory of type \
+    "{0}" into a BrokerFactory.
+cant-convert-broker: Unable to convert EntityManager of type "{0}" into a \
+    Broker.
 EntityManagerFactory-name: EntityManagerFactory implementation
 EntityManagerFactory-desc: Allows extension of standard \
     org.apache.openjpa.persistence.EntityManagerFactoryImpl for custom behavior.



Mime
View raw message