openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fayw...@apache.org
Subject svn commit: r790748 - in /openjpa/branches/subquery: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/ openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/ openjpa-persistenc...
Date Thu, 02 Jul 2009 22:09:53 GMT
Author: faywang
Date: Thu Jul  2 22:09:52 2009
New Revision: 790748

URL: http://svn.apache.org/viewvc?rev=790748&view=rev
Log:
fix exists/not exists problem

Modified:
    openjpa/branches/subquery/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCExpressionFactory.java
    openjpa/branches/subquery/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/SubQ.java
    openjpa/branches/subquery/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java
    openjpa/branches/subquery/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java
    openjpa/branches/subquery/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestSubquery.java

Modified: openjpa/branches/subquery/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCExpressionFactory.java
URL: http://svn.apache.org/viewvc/openjpa/branches/subquery/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCExpressionFactory.java?rev=790748&r1=790747&r2=790748&view=diff
==============================================================================
--- openjpa/branches/subquery/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCExpressionFactory.java
(original)
+++ openjpa/branches/subquery/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCExpressionFactory.java
Thu Jul  2 22:09:52 2009
@@ -166,8 +166,9 @@
         return new OrExpression((Exp) exp1, (Exp) exp2);
     }
 
-    public Expression not(Expression exp) {
-        if (HasContainsExpressionVisitor.hasContains(exp))
+    public Expression not(Expression exp) {// fyw
+        if (!(exp instanceof IsNotEmptyExpression) &&
+            HasContainsExpressionVisitor.hasContains(exp))
             return new NotContainsExpression((Exp) exp);
         return new NotExpression((Exp) exp);
     }

Modified: openjpa/branches/subquery/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/SubQ.java
URL: http://svn.apache.org/viewvc/openjpa/branches/subquery/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/SubQ.java?rev=790748&r1=790747&r2=790748&view=diff
==============================================================================
--- openjpa/branches/subquery/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/SubQ.java
(original)
+++ openjpa/branches/subquery/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/SubQ.java
Thu Jul  2 22:09:52 2009
@@ -45,7 +45,7 @@
 
     private final ClassMapping _candidate;
     private final boolean _subs;
-    private final String _alias;
+    private final String _subqAlias;
     private final SelectConstructor _cons = new SelectConstructor();
 
     private Class _type = null;
@@ -60,7 +60,7 @@
     public SubQ(ClassMapping candidate, boolean subs, String alias) {
         _candidate = candidate;
         _subs = subs;
-        _alias = alias;
+        _subqAlias = alias;
         _select = (((JDBCConfiguration) candidate.getMappingRepository().
             getConfiguration()).getSQLFactoryInstance().newSelect());
         _cons.setSubselect(_select);
@@ -102,7 +102,7 @@
     }
 
     public String getCandidateAlias() {
-        return _alias;
+        return _subqAlias;
     }
 
     public void setQueryExpressions(QueryExpressions query) {
@@ -192,7 +192,7 @@
     private void appendTo(Select sel, ExpContext ctx, ExpState state, 
         SQLBuffer sql, int index, boolean size) {
         QueryExpressionsState substate = new QueryExpressionsState();
-        Select sub = _cons.evaluate(ctx, sel, _alias, _exps, substate);
+        Select sub = _cons.evaluate(ctx, sel, _subqAlias, _exps, substate);
         _cons.select(sub, ctx, _candidate, _subs, _exps, substate, 
             JDBCFetchConfiguration.EAGER_NONE);
 

Modified: openjpa/branches/subquery/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java
URL: http://svn.apache.org/viewvc/openjpa/branches/subquery/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java?rev=790748&r1=790747&r2=790748&view=diff
==============================================================================
--- openjpa/branches/subquery/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java
(original)
+++ openjpa/branches/subquery/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java
Thu Jul  2 22:09:52 2009
@@ -2023,22 +2023,9 @@
         boolean create) {
         Integer i = null;
         SelectImpl sel = this;
-
-        //currCtx is set from Action, it is reset to null after the PCPath initialization
-        Context currCtx = pj == null ? null : ((PathJoinsImpl)pj).context;
-        
-        // lastCtx is set to currCtx after the SelectJoins.join. pj.lastCtx and pj.path string
are 
-        // the last snapshot of pj. They will be used together for later table alias resolution
in
-        // the getColumnAlias(). 
-        Context lastCtx = pj == null ? null : ((PathJoinsImpl)pj).lastContext;
-        Context thisCtx = currCtx == null ? lastCtx : currCtx;
-        String corrVar = pj == null ? null : pj.getCorrelatedVariable();
-        
         String alias = _schemaAlias;
-        if ((pj != null && pj.path() != null && (corrVar == null || ctx()
== thisCtx)) || 
-            table.isAssociation()) {
+        if (isPathInThisContext(pj) || table.isAssociation())          
             alias = null;
-        } 
 
         // find the context where this alias is defined
         Context ctx = (alias != null) ?
@@ -2062,6 +2049,20 @@
         return i;
     }
 
+    private boolean isPathInThisContext(PathJoins pj) {
+        // currCtx is set from Action, it is reset to null after the PCPath initialization
+        Context currCtx = pj == null ? null : ((PathJoinsImpl)pj).context;
+        
+        // lastCtx is set to currCtx after the SelectJoins.join. pj.lastCtx and pj.path string
are 
+        // the last snapshot of pj. They will be used together for later table alias resolution
in
+        // the getColumnAlias(). 
+        Context lastCtx = pj == null ? null : ((PathJoinsImpl)pj).lastContext;
+        Context thisCtx = currCtx == null ? lastCtx : currCtx;
+        String corrVar = pj == null ? null : pj.getCorrelatedVariable();
+        
+        return (pj != null && pj.path() != null && 
+            (corrVar == null || (thisCtx != null && ctx() == thisCtx)));
+    }
  
     private Integer getAlias(Table table, Object key) {
         Integer alias = null;

Modified: openjpa/branches/subquery/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java
URL: http://svn.apache.org/viewvc/openjpa/branches/subquery/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java?rev=790748&r1=790747&r2=790748&view=diff
==============================================================================
--- openjpa/branches/subquery/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java
(original)
+++ openjpa/branches/subquery/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java
Thu Jul  2 22:09:52 2009
@@ -601,11 +601,12 @@
 
         setCandidate(candidate, alias);
 
-        Subquery subquery =
-            factory.newSubquery(candidate, true, alias);
-        
         Context subContext = ctx();
-        subContext.setSubquery(subquery);
+        Subquery subquery = ctx().getSubquery();
+        if (subquery == null){
+            subquery = factory.newSubquery(candidate, true, alias);
+            subContext.setSubquery(subquery);
+        }
         Path subpath = factory.newPath(subquery);
         subpath.setMetaData(candidate);
         subquery.setMetaData(candidate);
@@ -635,14 +636,6 @@
         // OPENJPA-15 support subquery's from clause do not start with 
         // identification_variable_declaration()
         if (inner && ctx().getParent() != null && ctx().schemaAlias == null)
{
-//            ClassMetaData candidate = getFieldType(path.last());
-//            setCandidate(candidate, alias.text);
-//
-//            ctx().subquery = factory.newSubquery(candidate, true, alias.text);
-//            Path subpath = factory.newPath(ctx().subquery);
-//            subpath.setMetaData(candidate);
-//            exp = bindVariableForSubPath(path, alias.text, exp);
-//            exp =  and(exp, factory.equal(path, subpath));
             return getSubquery(alias.text, path, exp);
         }
 
@@ -704,18 +697,6 @@
             // clause, since we might be in a subquery against a collection
             if (isPath(left)) {
                 Path path = getPath(left);
-//                FieldMetaData fmd = path.last();
-//                ClassMetaData candidate = getFieldType(fmd);
-//
-//                if (candidate == null && fmd.isElementCollection())
-//                    candidate = fmd.getDefiningMetaData();
-//
-//                setCandidate(candidate, alias);
-//                exp = bindVariableForSubPath(path, alias, exp);
-//
-//                Path subpath = factory.newPath(ctx().subquery);
-//                subpath.setMetaData(ctx().subquery.getMetaData());
-//                return and(exp, factory.equal(path, subpath));
                 return getSubquery(alias, path, exp);
             } else {
                 // we have an alias: bind it as a variable

Modified: openjpa/branches/subquery/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestSubquery.java
URL: http://svn.apache.org/viewvc/openjpa/branches/subquery/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestSubquery.java?rev=790748&r1=790747&r2=790748&view=diff
==============================================================================
--- openjpa/branches/subquery/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestSubquery.java
(original)
+++ openjpa/branches/subquery/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestSubquery.java
Thu Jul  2 22:09:52 2009
@@ -94,9 +94,8 @@
             " (select count(o) from Order o)",
         "select o from Order o where o.amount > " +
             "(select count(o2) from Order o2)",
-    // outstanding problem subqueries:
-    //  "select c from Customer c left join c.orders o where not exists"
-    //    + " (select o2 from c.orders o2 where o2 = o)",
+        "select c from Customer c left join c.orders o where not exists"
+           + " (select o2 from c.orders o2 where o2 = o)",
     };
 
     static String[]  querys_jpa20 = new String[] {        



Mime
View raw message