openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mprud...@apache.org
Subject svn commit: r470996 - in /incubator/openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/ openjpa-kernel/src/main/java/org/apache/openjpa/meta/ openjpa-kernel/src/main/resources/org/apache/openjpa/meta/ openjpa-persistence/src/mai...
Date Fri, 03 Nov 2006 21:10:40 GMT
Author: mprudhom
Date: Fri Nov  3 13:10:39 2006
New Revision: 470996

URL: http://svn.apache.org/viewvc?view=rev&rev=470996
Log:
OPENJPA-74: Fixed multiple problems with named queries: 1. They were not being parsed as part
of the orm.xml file, since we were incorrectly looking for an attribute named 'query' (when
it really should have been a sub-element named 'query'). 2. Looking for a named query did
not force resolution of all metadatas. 3. An NPE was being thrown when a JPQL query was created
with a null filter

Modified:
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
    incubator/openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/meta/localizer.properties
    incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/MetaDataTag.java
    incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java?view=diff&rev=470996&r1=470995&r2=470996
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java
(original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java
Fri Nov  3 13:10:39 2006
@@ -1628,6 +1628,9 @@
         }
 
         private static final JPQLNode parse(String jpql) {
+            if (jpql == null)
+                jpql = "";
+
             try {
                 return (JPQLNode) new JPQL(jpql).parseQuery();
             } catch (Error e) {

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java?view=diff&rev=470996&r1=470995&r2=470996
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
(original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
Fri Nov  3 13:10:39 2006
@@ -1461,9 +1461,36 @@
     public synchronized QueryMetaData getQueryMetaData(Class cls, String name,
         ClassLoader envLoader, boolean mustExist) {
         QueryMetaData meta = getQueryMetaDataInternal(cls, name, envLoader);
-        if (meta == null && mustExist)
-            throw new MetaDataException(_loc.get("no-named-query", cls, name));
+        if (meta == null) {
+            // load all the metadatas for all the known classes so that
+            // query names are seen and registered
+            resolveAll(envLoader);
+            meta = getQueryMetaDataInternal(cls, name, envLoader);
+        }
+
+        if (meta == null && mustExist) {
+            if (cls == null) {
+                throw new MetaDataException(_loc.get
+                    ("no-named-query-null-class",
+                        getPersistentTypeNames(false, envLoader), name));
+            } else {
+                throw new MetaDataException(_loc.get("no-named-query",
+                    cls, name));
+            }
+        }
+
         return meta;
+    }
+
+    /** 
+     * Resolve all known metadata classes. 
+     */
+    private void resolveAll(ClassLoader envLoader) {
+        Collection types = loadPersistentTypes(false, envLoader);
+        for (Iterator i = types.iterator(); i.hasNext(); ) {
+            Class c = (Class) i.next();
+            getMetaData(c, envLoader, false);
+        }
     }
 
     /**

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/meta/localizer.properties
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/meta/localizer.properties?view=diff&rev=470996&r1=470995&r2=470996
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/meta/localizer.properties
(original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/meta/localizer.properties
Fri Nov  3 13:10:39 2006
@@ -204,6 +204,8 @@
 	\t<class name | .java file | .class file>+
 no-named-query: There is no named query defined for the class "{0}" with \
 	the name "{1}".
+no-named-query-null-class: There is no query with the name "{1}" defined for \
+    any of the known persistent classes: {0}.
 no-named-sequence: Could not locate the sequence with name "{0}".  It is \
 	possible that the metadata file containing the sequence has not been \
 	parsed yet.  Make sure to use a persistent class whose metadata is in \
@@ -274,4 +276,4 @@
     using Ant, please see the <properties> or <propertiesFile> attributes \
     of the task''s nested <config> element. This can also occur if your \
     OpenJPA distribution jars are corrupt, or if your security policy is \
-    overly strict.
\ No newline at end of file
+    overly strict.

Modified: incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/MetaDataTag.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/MetaDataTag.java?view=diff&rev=470996&r1=470995&r2=470996
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/MetaDataTag.java
(original)
+++ incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/MetaDataTag.java
Fri Nov  3 13:10:39 2006
@@ -42,6 +42,7 @@
     MAP_KEY,
     NATIVE_QUERIES,
     NATIVE_QUERY,
+    QUERY_STRING,
     ORDER_BY,
     QUERIES,
     QUERY,

Modified: incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java?view=diff&rev=470996&r1=470995&r2=470996
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java
(original)
+++ incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java
Fri Nov  3 13:10:39 2006
@@ -119,6 +119,7 @@
         _elems.put("named-query", QUERY);
         _elems.put("named-native-query", NATIVE_QUERY);
         _elems.put("query-hint", QUERY_HINT);
+        _elems.put("query", QUERY_STRING);
 
         _elems.put("flush-mode", FLUSH_MODE);
         _elems.put("sequence-generator", SEQ_GENERATOR);
@@ -442,6 +443,9 @@
                 case NATIVE_QUERY:
                     ret = startNamedNativeQuery(attrs);
                     break;
+                case QUERY_STRING:
+                    ret = startQueryString(attrs);
+                    break;
                 case SEQ_GENERATOR:
                     ret = startSequenceGenerator(attrs);
                     break;
@@ -489,6 +493,9 @@
                 case NATIVE_QUERY:
                     endNamedNativeQuery();
                     break;
+                case QUERY_STRING:
+                    endQueryString();
+                    break;
                 case SEQ_GENERATOR:
                     endSequenceGenerator();
                     break;
@@ -553,6 +560,9 @@
                 case NATIVE_QUERY:
                     ret = startNamedNativeQuery(attrs);
                     break;
+                case QUERY_STRING:
+                    ret = startQueryString(attrs);
+                    break;
                 case SEQ_GENERATOR:
                     ret = startSequenceGenerator(attrs);
                     break;
@@ -640,6 +650,9 @@
                 case NATIVE_QUERY:
                     endNamedNativeQuery();
                     break;
+                case QUERY_STRING:
+                    endQueryString();
+                    break;
                 case SEQ_GENERATOR:
                     endSequenceGenerator();
                     break;
@@ -1366,6 +1379,17 @@
     protected void endNamedQuery()
         throws SAXException {
         popElement();
+    }
+
+    protected boolean startQueryString(Attributes attrs)
+        throws SAXException {
+        return true;
+    }
+
+    protected void endQueryString()
+        throws SAXException {
+        QueryMetaData meta = (QueryMetaData) currentElement();
+        meta.setQueryString(currentText());
     }
 
     /**



Mime
View raw message