cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r904522 - /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLConditionTranslator.java
Date Fri, 29 Jan 2010 15:45:28 GMT
Author: oltka
Date: Fri Jan 29 15:45:27 2010
New Revision: 904522

URL: http://svn.apache.org/viewvc?rev=904522&view=rev
Log:
CAY-1365  "= NULL" being used instead of "IS NULL" on an EJBQL expression..

(cherry picked from commit 50c3635fb0c789a5b0d137664ee809e6a4f4c0b5)

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLConditionTranslator.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLConditionTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLConditionTranslator.java?rev=904522&r1=904521&r2=904522&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLConditionTranslator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLConditionTranslator.java
Fri Jan 29 15:45:27 2010
@@ -166,7 +166,7 @@
 
         String subqueryId = context.createIdAlias(id);
         ClassDescriptor targetDescriptor = context.getEntityDescriptor(subqueryId);
-       
+
         if (expression.isNegated()) {
             context.append(" NOT");
         }
@@ -182,7 +182,7 @@
         ObjRelationship relationship = (ObjRelationship) correlatedEntityDescriptor
                 .getEntity()
                 .getRelationship(path.getRelativePath());
-        
+
         if (relationship.getDbRelationshipPath().contains(".")) {
             // if the DbRelationshipPath contains '.', the relationship is flattened
             subqueryRootAlias = processFlattenedRelationShip(
@@ -274,7 +274,7 @@
         ObjRelationship relationship = (ObjRelationship) correlatedEntityDescriptor
                 .getEntity()
                 .getRelationship(path.getRelativePath());
-        
+
         if (relationship.getDbRelationshipPath().contains(".")) {
             // if the DbRelationshipPath contains '.', the relationship is flattened
             subqueryRootAlias = processFlattenedRelationShip(
@@ -316,12 +316,12 @@
     private String processFlattenedRelationShip(
             String subqueryRootAlias,
             ObjRelationship relationship) {
-        List<DbRelationship> dbRelationships = relationship
-                .getDbRelationships();
+        List<DbRelationship> dbRelationships = relationship.getDbRelationships();
         // reverse order to get the nearest to the correlated of the direct relation
         for (int i = dbRelationships.size() - 1; i > 0; i--) {
             DbRelationship dbRelationship = dbRelationships.get(i);
-            String subqueryTargetTableName = ((DbEntity)dbRelationship.getTargetEntity()).getFullyQualifiedName();
+            String subqueryTargetTableName = ((DbEntity) dbRelationship.getTargetEntity())
+                    .getFullyQualifiedName();
             String subqueryTargetAlias;
             if (i == dbRelationships.size() - 1) {
                 subqueryTargetAlias = subqueryRootAlias;
@@ -333,18 +333,17 @@
                         subqueryTargetTableName,
                         subqueryTargetTableName);
             }
-           
 
             context.append(" JOIN ");
 
-            String subquerySourceTableName = ((DbEntity)dbRelationship
-                    .getSourceEntity())
+            String subquerySourceTableName = ((DbEntity) dbRelationship.getSourceEntity())
                     .getFullyQualifiedName();
             String subquerySourceAlias = context.getTableAlias(
                     subquerySourceTableName,
                     subquerySourceTableName);
 
-            context.append(subquerySourceTableName).append(' ').append(subquerySourceAlias);
+            context.append(subquerySourceTableName).append(' ').append(
+                    subquerySourceAlias);
 
             context.append(" ON (");
 
@@ -390,15 +389,18 @@
         switch (finishedChildIndex) {
             case 0:
                 if (expression.getChildrenCount() == 2) {
-                    for (int j = 0; j < expression.getChildrenCount(); j++) {
-                        if (expression.getChild(j) instanceof EJBQLNamedInputParameter) {
-                            EJBQLNamedInputParameter par = (EJBQLNamedInputParameter) expression
-                                    .getChild(j);
-                            if (context.namedParameters.containsKey(par.getText())
-                                    && context.namedParameters.get(par.getText())
== null) {
-                                context.append(" IS NULL");
-                                return false;
-                            }
+
+                    // We rewrite expression "parameter = :x" where x=null
+                    // as "parameter IS NULL"
+                    // BUT in such as ":x = parameter" (where x=null) we don't do anything
+                    // as a result it can be unsupported in some DB
+                    if (expression.getChild(1) instanceof EJBQLNamedInputParameter) {
+                        EJBQLNamedInputParameter par = (EJBQLNamedInputParameter) expression
+                                .getChild(1);
+                        if (context.namedParameters.containsKey(par.getText())
+                                && context.namedParameters.get(par.getText()) ==
null) {
+                            context.append(" IS NULL");
+                            return false;
                         }
                     }
                 }
@@ -573,7 +575,7 @@
 
         return true;
     }
-    
+
     /**
      * Visits conditional node, suppling brackets if needed
      */
@@ -583,18 +585,19 @@
         }
 
         afterChild(e, afterText, childIndex);
-        
+
         if (childIndex == e.getChildrenCount() - 1 && needBracket(e)) {
             context.append(")");
         }
     }
-    
+
     /**
      * Checks whether expression needs to be rounded by brackets
      */
     boolean needBracket(AggregateConditionNode e) {
-        return (e.jjtGetParent() instanceof AggregateConditionNode) &&
-            e.getPriority() > ((AggregateConditionNode) e.jjtGetParent()).getPriority();
+        return (e.jjtGetParent() instanceof AggregateConditionNode)
+                && e.getPriority() > ((AggregateConditionNode) e.jjtGetParent())
+                        .getPriority();
     }
 
     protected void afterChild(EJBQLExpression e, String text, int childIndex) {
@@ -835,7 +838,9 @@
 
                 Property property = descriptor.getProperty(pathChunk);
                 if (property instanceof AttributeProperty) {
-                    String atrType = ((AttributeProperty) property).getAttribute().getType();
+                    String atrType = ((AttributeProperty) property)
+                            .getAttribute()
+                            .getType();
 
                     type = TypesMapping.getSqlNameByType(TypesMapping
                             .getSqlTypeByJava(atrType));



Mime
View raw message