openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From awh...@apache.org
Subject svn commit: r473140 - in /incubator/openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/ openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/ openjpa-lib/src/main/java/org/apache/openjpa/lib/util/
Date Thu, 09 Nov 2006 23:55:42 GMT
Author: awhite
Date: Thu Nov  9 15:55:41 2006
New Revision: 473140

URL: http://svn.apache.org/viewvc?view=rev&rev=473140
Log:
Fix for deeply nested subqueries, and for the JPQL IN(<subquery>) construct.


Modified:
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLBuffer.java
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java
    incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Localizer.java

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLBuffer.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLBuffer.java?view=diff&rev=473140&r1=473139&r2=473140
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLBuffer.java
(original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLBuffer.java
Thu Nov  9 15:55:41 2006
@@ -374,7 +374,7 @@
     public String getSQL() {
         return getSQL(false);
     }
-
+    
     /**
      * Returns the SQL for this buffer.
      *
@@ -382,22 +382,7 @@
      * actual parameter values
      */
     public String getSQL(boolean replaceParams) {
-        if (_subsels != null && !_subsels.isEmpty()) {
-            // add subsels backwards so that the stored insertion points of
-            // later subsels remain valid
-            Subselect sub;
-            SQLBuffer buf;
-            for (int i = _subsels.size() - 1; i >= 0; i--) {
-                sub = (Subselect) _subsels.get(i);
-                if (sub.count)
-                    buf = sub.select.toSelectCount();
-                else
-                    buf = sub.select.toSelect(false, sub.fetch);
-                append(buf, sub.sqlIndex, sub.paramIndex, false);
-            }
-            _subsels.clear();
-        }
-
+        resolveSubselects();
         String sql = _sql.toString();
         if (!replaceParams || _params == null || _params.isEmpty())
             return sql;
@@ -424,6 +409,29 @@
     }
 
     /**
+     * Resolve our delayed subselects.
+     */
+    private void resolveSubselects() {
+        if (_subsels == null || _subsels.isEmpty())
+            return;
+
+        // add subsels backwards so that the stored insertion points of
+        // later subsels remain valid
+        Subselect sub;
+        SQLBuffer buf;
+        for (int i = _subsels.size() - 1; i >= 0; i--) {
+            sub = (Subselect) _subsels.get(i);
+            if (sub.count)
+                buf = sub.select.toSelectCount();
+            else
+                buf = sub.select.toSelect(false, sub.fetch);
+            buf.resolveSubselects();
+            append(buf, sub.sqlIndex, sub.paramIndex, false);
+        }
+        _subsels.clear();
+    }
+
+    /**
      * Create and populate the parameters of a prepared statement using
      * the SQL in this buffer.
      */
@@ -606,4 +614,3 @@
         }
     }
 }
-

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=473140&r1=473139&r2=473140
==============================================================================
--- 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
Thu Nov  9 15:55:41 2006
@@ -821,10 +821,14 @@
 
                 while (inIterator.hasNext()) {
                     val2 = getValue((JPQLNode) inIterator.next());
-                    setImplicitTypes(val1, val2, null);
+
+                    // special case for <value> IN (<subquery>)
+                    if (val2 instanceof Subquery && node.getChildCount() == 2)
+                        return factory.contains(val2, val1); 
 
                     // this is currently a sequence of OR expressions, since we
                     // do not have support for IN expressions
+                    setImplicitTypes(val1, val2, null);
                     if (inExp == null)
                         inExp = factory.equal(val1, val2);
                     else

Modified: incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Localizer.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Localizer.java?view=diff&rev=473140&r1=473139&r2=473140
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Localizer.java
(original)
+++ incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Localizer.java
Thu Nov  9 15:55:41 2006
@@ -86,7 +86,6 @@
         String key = file + locale.toString();
 
         // no locking; ok if bundle created multiple times
-
         // check for cached version
         Localizer loc = (Localizer) _localizers.get(key);
         if (loc != null)



Mime
View raw message