openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r686419 - in /openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/meta/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/ openjpa-persistence/src/main/java/org/apache/openjpa/persistence/ openjpa-persis...
Date Fri, 15 Aug 2008 23:36:16 GMT
Author: ppoddar
Date: Fri Aug 15 16:36:16 2008
New Revision: 686419

URL: http://svn.apache.org/viewvc?rev=686419&view=rev
Log:
OPENJPA-111: Modified tests to use correct binding parameter. Added methods in MetaDataRepository
to look for NamedQuery only by name without defining class information.

Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/SimpleEntity.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/SimpleEntity2.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestDupNamedQuery.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java
    openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties
    openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/TestQuery.java

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java?rev=686419&r1=686418&r2=686419&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
Fri Aug 15 16:36:16 2008
@@ -1618,10 +1618,15 @@
         ClassLoader envLoader) {
         if (name == null)
             return null;
-
+        QueryMetaData qm = null;
+        if (cls == null) {
+        	qm = searchQueryMetaDataByName(name);
+        	if (qm != null)
+        		return qm;
+        }
         // check cache
         Object key = getQueryKey(cls, name);
-        QueryMetaData qm = (QueryMetaData) _queries.get(key);
+        qm = (QueryMetaData) _queries.get(key);
         if (qm != null)
             return qm;
 
@@ -1694,6 +1699,18 @@
             return false;
         return _queries.remove(getQueryKey(cls, name)) != null;
     }
+    
+    /**
+     * Searches all cached query metadata by name. 
+     */
+    public QueryMetaData searchQueryMetaDataByName(String name) {
+    	for (Object key : _queries.keySet()) {
+    		if (key instanceof QueryKey)
+    			if (StringUtils.equals(((QueryKey)key).name, name))
+    				return (QueryMetaData)_queries.get(key);
+    	}
+    	return null;
+    }
 
     /**
      * Return a unique key for a given QueryMetaData.

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/SimpleEntity.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/SimpleEntity.java?rev=686419&r1=686418&r2=686419&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/SimpleEntity.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/SimpleEntity.java
Fri Aug 15 16:36:16 2008
@@ -33,11 +33,11 @@
 import javax.persistence.SqlResultSetMapping;
 import javax.persistence.Table;
 
-@NamedQuery(name="FindXTwo", query="select s from simple s where s.name = :fname")
+@NamedQuery(name="FindXTwo", query="select s from simple s where s.name = ?1")
 
 @NamedQueries( {
-    @NamedQuery(name="FindOne", query="select s from simple s where s.name = :fname"),
-    @NamedQuery(name="FindOne", query="select s from simple s where s.name = :fname"),
+    @NamedQuery(name="FindOne", query="select s from simple s where s.name = ?1"),
+    @NamedQuery(name="FindOne", query="select s from simple s where s.name = ?1"),
     @NamedQuery(name="FindAll", query="select s from simple s")
 })
 

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/SimpleEntity2.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/SimpleEntity2.java?rev=686419&r1=686418&r2=686419&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/SimpleEntity2.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/SimpleEntity2.java
Fri Aug 15 16:36:16 2008
@@ -27,11 +27,11 @@
 import javax.persistence.NamedQuery;
 import javax.persistence.Table;
 
-@NamedQuery(name="FindXTwo", query="select s from simple2 s where s.name = :fname")
+@NamedQuery(name="FindXTwo", query="select s from simple2 s where s.name = ?1")
 
 @NamedQueries( {
-    @NamedQuery(name="FindOne", query="select s from simple2 s where s.name = :fname"),
-    @NamedQuery(name="Find2One", query="select s from simple2 s where s.name = :fname"),
+    @NamedQuery(name="FindOne", query="select s from simple2 s where s.name = ?1"),
+    @NamedQuery(name="Find2One", query="select s from simple2 s where s.name = ?1"),
     @NamedQuery(name="Find2All", query="select s from simple2 s")
 })
 

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestDupNamedQuery.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestDupNamedQuery.java?rev=686419&r1=686418&r2=686419&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestDupNamedQuery.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestDupNamedQuery.java
Fri Aug 15 16:36:16 2008
@@ -55,13 +55,13 @@
         String ValueTwo) {
         EntityManager em = emf.createEntityManager();
 
-        List list = em.createNamedQuery(findOneQName).setParameter("fname", nameOne)
+        List list = em.createNamedQuery(findOneQName).setParameter(1, nameOne)
             .getResultList();
         assertNotNull(list);
         assertEquals(list.size(), 1);
         Object o = list.get(0);
-        assertSame(o.getClass(), simple2 ? SimpleEntity2.class
-            : SimpleEntity.class);
+        assertTrue(simple2 ? o instanceof SimpleEntity2 
+        		: o instanceof SimpleEntity);
         assertEquals(simple2 ? ((SimpleEntity2) o).getValue()
             : ((SimpleEntity) o).getValue(), ValueOne);
 
@@ -71,8 +71,8 @@
             assertEquals(list.size(), 2);
             for (Iterator resultIter = list.iterator(); resultIter.hasNext();) {
                 o = resultIter.next();
-                assertSame(o.getClass(), simple2 ? SimpleEntity2.class
-                    : SimpleEntity.class);
+                assertTrue(simple2 ? o instanceof SimpleEntity2 
+                		: o instanceof SimpleEntity);
                 String n = null;
                 String v = null;
                 if (simple2) {

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java?rev=686419&r1=686418&r2=686419&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
Fri Aug 15 16:36:16 2008
@@ -1582,14 +1582,17 @@
             if (_log.isTraceEnabled())
                 _log.trace(_loc.get("parse-query", query.name()));
 
-            meta = getRepository().getCachedQueryMetaData(null, query.name());
+            meta = getRepository().searchQueryMetaDataByName(query.name());
             if (meta != null) {
-                if (_log.isWarnEnabled())
-                    _log.warn(_loc.get("dup-query", query.name(), el));
+            	Class definingType = meta.getDefiningType();
+                if ((definingType == null || definingType != _cls) 
+                  && _log.isWarnEnabled()) {
+                    _log.warn(_loc.get("dup-query", query.name(), el, 
+                    		definingType));
+                }
                 continue;
             }
-
-            meta = getRepository().addQueryMetaData(null, query.name());
+            meta = getRepository().addQueryMetaData(_cls, query.name());
             meta.setQueryString(query.query());
             meta.setLanguage(JPQLParser.LANG_JPQL);
             for (QueryHint hint : query.hints())
@@ -1623,10 +1626,12 @@
             if (_log.isTraceEnabled())
                 _log.trace(_loc.get("parse-native-query", query.name()));
 
-            meta = getRepository().getCachedQueryMetaData(null, query.name());
+            meta = getRepository().searchQueryMetaDataByName(query.name());
             if (meta != null) {
-                if (_log.isWarnEnabled())
-                    _log.warn(_loc.get("dup-query", query.name(), el));
+            	Class defType = meta.getDefiningType();
+                if ((defType != _cls) && _log.isWarnEnabled()) {
+                    _log.warn(_loc.get("dup-query", query.name(), el, defType));
+                }
                 continue;
             }
 

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java?rev=686419&r1=686418&r2=686419&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java
Fri Aug 15 16:36:16 2008
@@ -1407,9 +1407,15 @@
         if (log.isTraceEnabled())
             log.trace(_loc.get("parse-query", name));
 
-        QueryMetaData meta = getRepository().getCachedQueryMetaData(null, name);
-        if (meta != null && log.isWarnEnabled())
-            log.warn(_loc.get("override-query", name, currentLocation()));
+        QueryMetaData meta = getRepository().searchQueryMetaDataByName(name);
+        if (meta != null) {
+        	Class defType = meta.getDefiningType();
+            if ((defType != _cls) && log.isWarnEnabled()) {
+            	log.warn(_loc.get("dup-query", name, currentLocation(), defType));
+            }
+            pushElement(meta);
+            return true;
+        }
 
         meta = getRepository().addQueryMetaData(null, name);
         meta.setDefiningType(_cls);

Modified: openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties?rev=686419&r1=686418&r2=686419&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties
Fri Aug 15 16:36:16 2008
@@ -34,7 +34,8 @@
 dup-sequence: Found duplicate generator "{0}" in "{1}".  Ignoring.
 override-sequence: Found duplicate generator "{0}" in "{1}".  Overriding \
 	previous definition.
-dup-query: Found duplicate query "{0}" in "{1}".  Ignoring.
+dup-query: Ignoring duplicate query "{0}" in "{1}". A query with the same name \
+	been already declared in "{2}".
 override-query: Found duplicate query "{0}" in "{1}".  Overriding previous \
 	definition.
 no-seq-name: The sequence generator in "{0}" must declare a name.

Modified: openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/TestQuery.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/TestQuery.java?rev=686419&r1=686418&r2=686419&view=diff
==============================================================================
--- openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/TestQuery.java (original)
+++ openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/TestQuery.java Fri
Aug 15 16:36:16 2008
@@ -111,6 +111,10 @@
         em.getTransaction().rollback();
     }
     
+    /**
+     * Retired temporarily. Most likely side-effect of eager compilation of
+     * query introduced recently.
+     */
     public void testHint() {
         List<String> targets = new ArrayList<String>();
         targets.add("Even");



Mime
View raw message