cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1449474 [2/2] - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/access/jdbc/ test/java/org/apache/cayenne/access/jdbc/
Date Sun, 24 Feb 2013 13:05:15 GMT
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLPathTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLPathTranslator.java?rev=1449474&r1=1449473&r2=1449474&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLPathTranslator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLPathTranslator.java
Sun Feb 24 13:05:14 2013
@@ -24,7 +24,6 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.cayenne.dba.QuotingSupport;
 import org.apache.cayenne.ejbql.EJBQLBaseVisitor;
 import org.apache.cayenne.ejbql.EJBQLException;
 import org.apache.cayenne.ejbql.EJBQLExpression;
@@ -39,7 +38,8 @@ import org.apache.cayenne.map.Relationsh
 import org.apache.cayenne.reflect.ClassDescriptor;
 
 /**
- * A translator that walks the relationship/attribute path, appending joins to the query.
+ * A translator that walks the relationship/attribute path, appending joins to
+ * the query.
  * 
  * @since 3.0
  */
@@ -69,8 +69,7 @@ public abstract class EJBQLPathTranslato
 
             if (finishedChildIndex + 1 < expression.getChildrenCount()) {
                 processIntermediatePathComponent();
-            }
-            else {
+            } else {
                 processLastPathComponent();
             }
         }
@@ -82,8 +81,7 @@ public abstract class EJBQLPathTranslato
     public boolean visitIdentifier(EJBQLExpression expression) {
         ClassDescriptor descriptor = context.getEntityDescriptor(expression.getText());
         if (descriptor == null) {
-            throw new EJBQLException("Invalid identification variable: "
-                    + expression.getText());
+            throw new EJBQLException("Invalid identification variable: " + expression.getText());
         }
 
         this.currentEntity = descriptor.getEntity();
@@ -96,7 +94,8 @@ public abstract class EJBQLPathTranslato
     @Override
     public boolean visitIdentificationVariable(EJBQLExpression expression) {
 
-        // TODO: andrus 6/11/2007 - if the path ends with relationship, the last join will
+        // TODO: andrus 6/11/2007 - if the path ends with relationship, the last
+        // join will
         // get lost...
         if (lastPathComponent != null) {
             resolveJoin(true);
@@ -108,75 +107,55 @@ public abstract class EJBQLPathTranslato
 
     protected void resolveJoin(boolean inner) {
 
-        EJBQLJoinAppender joinAppender = context.getTranslatorFactory().getJoinAppender(
-                context);
+        EJBQLJoinAppender joinAppender = context.getTranslatorFactory().getJoinAppender(context);
 
         String newPath = idPath + '.' + lastPathComponent;
-        String oldPath = joinAppender.registerReusableJoin(
-                idPath,
-                lastPathComponent,
-                newPath);
+        String oldPath = joinAppender.registerReusableJoin(idPath, lastPathComponent, newPath);
 
         this.fullPath = fullPath + '.' + lastPathComponent;
 
         if (oldPath != null) {
             this.idPath = oldPath;
-            Relationship lastRelationship = currentEntity
-                    .getRelationship(lastPathComponent);
+            Relationship lastRelationship = currentEntity.getRelationship(lastPathComponent);
             if (lastRelationship != null) {
                 ObjEntity targetEntity = (ObjEntity) lastRelationship.getTargetEntity();
 
-                this.lastAlias = context.getTableAlias(fullPath, context.getQuotingSupport().generateTableName(
-                        targetEntity.getDbEntity()));
-            }
-            else {
-                String tableName = context.getQuotingSupport().generateTableName(currentEntity.getDbEntity());
+                this.lastAlias = context.getTableAlias(fullPath,
+                        context.getQuotingStrategy().quotedFullyQualifiedName(targetEntity.getDbEntity()));
+            } else {
+                String tableName = context.getQuotingStrategy().quotedFullyQualifiedName(currentEntity.getDbEntity());
                 this.lastAlias = context.getTableAlias(oldPath, tableName);
             }
-        }
-        else {
-            Relationship lastRelationship = currentEntity
-                    .getRelationship(lastPathComponent);
+        } else {
+            Relationship lastRelationship = currentEntity.getRelationship(lastPathComponent);
 
             ObjEntity targetEntity = null;
             if (lastRelationship != null) {
                 targetEntity = (ObjEntity) lastRelationship.getTargetEntity();
-            }
-            else {
+            } else {
                 targetEntity = currentEntity;
             }
 
             // register join
             if (inner) {
-                joinAppender.appendInnerJoin(
-                        joinMarker,
-                        new EJBQLTableId(idPath),
-                        new EJBQLTableId(fullPath));
-            }
-            else {
-                joinAppender.appendOuterJoin(
-                        joinMarker,
-                        new EJBQLTableId(idPath),
-                        new EJBQLTableId(fullPath));
+                joinAppender.appendInnerJoin(joinMarker, new EJBQLTableId(idPath), new EJBQLTableId(fullPath));
+            } else {
+                joinAppender.appendOuterJoin(joinMarker, new EJBQLTableId(idPath), new EJBQLTableId(fullPath));
 
             }
 
-            this.lastAlias = context.getTableAlias(fullPath, context.getQuotingSupport().generateTableName(
-                    targetEntity.getDbEntity()));
+            this.lastAlias = context.getTableAlias(fullPath,
+                    context.getQuotingStrategy().quotedFullyQualifiedName(targetEntity.getDbEntity()));
 
             this.idPath = newPath;
         }
     }
 
     protected void processIntermediatePathComponent() {
-        ObjRelationship relationship = (ObjRelationship) currentEntity
-                .getRelationship(lastPathComponent);
+        ObjRelationship relationship = (ObjRelationship) currentEntity.getRelationship(lastPathComponent);
         if (relationship == null) {
-            throw new EJBQLException("Unknown relationship '"
-                    + lastPathComponent
-                    + "' for entity '"
-                    + currentEntity.getName()
-                    + "'");
+            throw new EJBQLException("Unknown relationship '" + lastPathComponent + "' for
entity '"
+                    + currentEntity.getName() + "'");
         }
 
         this.currentEntity = (ObjEntity) relationship.getTargetEntity();
@@ -184,16 +163,14 @@ public abstract class EJBQLPathTranslato
 
     protected void processLastPathComponent() {
 
-        ObjAttribute attribute = (ObjAttribute) currentEntity
-                .getAttribute(lastPathComponent);
+        ObjAttribute attribute = (ObjAttribute) currentEntity.getAttribute(lastPathComponent);
 
         if (attribute != null) {
             processTerminatingAttribute(attribute);
             return;
         }
 
-        ObjRelationship relationship = (ObjRelationship) currentEntity
-                .getRelationship(lastPathComponent);
+        ObjRelationship relationship = (ObjRelationship) currentEntity.getRelationship(lastPathComponent);
         if (relationship != null) {
             processTerminatingRelationship(relationship);
             return;
@@ -203,7 +180,6 @@ public abstract class EJBQLPathTranslato
     }
 
     protected void processTerminatingAttribute(ObjAttribute attribute) {
-        QuotingSupport quotingSupport = context.getQuotingSupport();
 
         DbEntity table = null;
         Iterator<?> it = attribute.getDbPathIterator();
@@ -215,14 +191,12 @@ public abstract class EJBQLPathTranslato
         }
 
         if (isUsingAliases()) {
-            String alias = this.lastAlias != null ? lastAlias : context.getTableAlias(
-                    idPath,
-                    quotingSupport.generateTableName(table));
-            context.append(' ').append(alias).append('.').append(
-                    quotingSupport.generateColumnName(attribute.getDbAttribute()));
-        }
-        else {
-            context.append(' ').append(context.getQuotingSupport().generateColumnName(attribute.getDbAttribute()));
+            String alias = this.lastAlias != null ? lastAlias : context.getTableAlias(idPath,
context
+                    .getQuotingStrategy().quotedFullyQualifiedName(table));
+            context.append(' ').append(alias).append('.')
+                    .append(context.getQuotingStrategy().quotedName(attribute.getDbAttribute()));
+        } else {
+            context.append(' ').append(context.getQuotingStrategy().quotedName(attribute.getDbAttribute()));
         }
     }
 
@@ -230,19 +204,22 @@ public abstract class EJBQLPathTranslato
 
         if (relationship.isSourceIndependentFromTargetChange()) {
 
-            // (andrus) use an outer join for to-many matches.. This is somewhat different
-            // from traditional Cayenne SelectQuery, as EJBQL spec does not allow regular
-            // path matches done against to-many relationships, and instead provides
-            // MEMBER OF and IS EMPTY operators. Outer join is needed for IS EMPTY... I
+            // (andrus) use an outer join for to-many matches.. This is somewhat
+            // different
+            // from traditional Cayenne SelectQuery, as EJBQL spec does not
+            // allow regular
+            // path matches done against to-many relationships, and instead
+            // provides
+            // MEMBER OF and IS EMPTY operators. Outer join is needed for IS
+            // EMPTY... I
             // guess MEMBER OF could've been done with an inner join though..
             resolveJoin(false);
 
             DbRelationship dbRelationship = chooseDbRelationship(relationship);
             DbEntity table = (DbEntity) dbRelationship.getTargetEntity();
 
-            String alias = this.lastAlias != null ? lastAlias : context.getTableAlias(
-                    idPath,
-                    context.getQuotingSupport().generateTableName(table));
+            String alias = this.lastAlias != null ? lastAlias : context.getTableAlias(idPath,
context
+                    .getQuotingStrategy().quotedFullyQualifiedName(table));
 
             Collection<DbAttribute> pks = table.getPrimaryKeys();
 
@@ -252,23 +229,19 @@ public abstract class EJBQLPathTranslato
                 if (isUsingAliases()) {
                     context.append(alias).append('.');
                 }
-                context.append(context.getQuotingSupport().generateColumnName(pk));
-            }
-            else {
-                throw new EJBQLException(
-                        "Multi-column PK to-many matches are not yet supported.");
+                context.append(context.getQuotingStrategy().quotedName(pk));
+            } else {
+                throw new EJBQLException("Multi-column PK to-many matches are not yet supported.");
             }
 
-        }
-        else {
+        } else {
             // match FK against the target object
 
             DbRelationship dbRelationship = chooseDbRelationship(relationship);
             DbEntity table = (DbEntity) dbRelationship.getSourceEntity();
 
-            String alias = this.lastAlias != null ? lastAlias : context.getTableAlias(
-                    idPath,
-                    context.getQuotingSupport().generateTableName(table));
+            String alias = this.lastAlias != null ? lastAlias : context.getTableAlias(idPath,
context
+                    .getQuotingStrategy().quotedFullyQualifiedName(table));
 
             List<DbJoin> joins = dbRelationship.getJoins();
 
@@ -278,33 +251,28 @@ public abstract class EJBQLPathTranslato
                 if (isUsingAliases()) {
                     context.append(alias).append('.');
                 }
-                context.append(context.getQuotingSupport().generateColumnName(join.getSource()));
-            }
-            else {
-                Map<String, String> multiColumnMatch = new HashMap<String, String>(joins
-                        .size() + 2);
+                context.append(context.getQuotingStrategy().quotedName(join.getSource()));
+            } else {
+                Map<String, String> multiColumnMatch = new HashMap<String, String>(joins.size()
+ 2);
 
                 for (DbJoin join : joins) {
-                    String column = isUsingAliases()
-                            ? alias + "." + join.getSourceName()
-                            : join.getSourceName();
+                    String column = isUsingAliases() ? alias + "." + join.getSourceName()
: join.getSourceName();
 
                     multiColumnMatch.put(join.getTargetName(), column);
                 }
 
-                appendMultiColumnPath(EJBQLMultiColumnOperand.getPathOperand(
-                        context,
-                        multiColumnMatch));
+                appendMultiColumnPath(EJBQLMultiColumnOperand.getPathOperand(context, multiColumnMatch));
             }
         }
     }
-    
+
     /**
-     * Checks if the object relationship is flattened and then chooses
-     * the corresponding db relationship. The last in idPath if isFlattened and
-     * the first in list otherwise.
+     * Checks if the object relationship is flattened and then chooses the
+     * corresponding db relationship. The last in idPath if isFlattened and the
+     * first in list otherwise.
      * 
-     * @param relationship the object relationship
+     * @param relationship
+     *            the object relationship
      * 
      * @return {@link DbRelationship}
      */
@@ -314,8 +282,7 @@ public abstract class EJBQLPathTranslato
         String dbRelationshipPath = relationship.getDbRelationshipPath();
 
         if (dbRelationshipPath.contains(".")) {
-            String dbRelName = dbRelationshipPath.substring(dbRelationshipPath
-                    .lastIndexOf(".") + 1);
+            String dbRelName = dbRelationshipPath.substring(dbRelationshipPath.lastIndexOf(".")
+ 1);
             for (DbRelationship dbR : dbRelationships) {
                 if (dbR.getName().equals(dbRelName)) {
                     return dbR;

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLSelectColumnsTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLSelectColumnsTranslator.java?rev=1449474&r1=1449473&r2=1449474&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLSelectColumnsTranslator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLSelectColumnsTranslator.java
Sun Feb 24 13:05:14 2013
@@ -59,8 +59,7 @@ public class EJBQLSelectColumnsTranslato
 
     @Override
     public boolean visitAggregate(EJBQLExpression expression) {
-        expression.visit(context.getTranslatorFactory().getAggregateColumnTranslator(
-                context));
+        expression.visit(context.getTranslatorFactory().getAggregateColumnTranslator(context));
         return false;
     }
 
@@ -84,8 +83,8 @@ public class EJBQLSelectColumnsTranslato
 
                 final Map<String, String> fields = xfields;
 
-                Collection<DbAttribute> dbAttr = ((ObjEntity) relationship
-                        .getTargetEntity()).getDbEntity().getAttributes();
+                Collection<DbAttribute> dbAttr = ((ObjEntity) relationship.getTargetEntity()).getDbEntity()
+                        .getAttributes();
 
                 DbRelationship dbRelationship = relationship.getDbRelationships().get(0);
                 DbEntity table = (DbEntity) dbRelationship.getTargetEntity();
@@ -95,8 +94,8 @@ public class EJBQLSelectColumnsTranslato
                     this.resolveJoin(true);
                 }
 
-                String alias = this.lastAlias != null ? lastAlias : context
-                        .getTableAlias(idPath, context.getQuotingSupport().generateTableName(table));
+                String alias = this.lastAlias != null ? lastAlias : context.getTableAlias(idPath,
context
+                        .getQuotingStrategy().quotedFullyQualifiedName(table));
 
                 boolean first = true;
                 while (it.hasNext()) {
@@ -104,11 +103,8 @@ public class EJBQLSelectColumnsTranslato
                     context.append(!first ? ", " : " ");
 
                     DbAttribute dbAttribute = it.next();
-                    appendColumn(
-                            TypesMapping.getJavaBySqlType(dbAttribute.getType()),
-                            alias,
-                            dbAttribute,
-                            fields!=null?fields.get(dbAttribute.getName()):"");
+                    appendColumn(TypesMapping.getJavaBySqlType(dbAttribute.getType()), alias,
dbAttribute,
+                            fields != null ? fields.get(dbAttribute.getName()) : "");
 
                     first = false;
                 }
@@ -118,44 +114,36 @@ public class EJBQLSelectColumnsTranslato
             @Override
             protected void processTerminatingAttribute(ObjAttribute attribute) {
                 DbEntity table = currentEntity.getDbEntity();
-                String alias = this.lastAlias != null ? lastAlias : context
-                        .getTableAlias(idPath, context.getQuotingSupport().generateTableName(table));
+                String alias = this.lastAlias != null ? lastAlias : context.getTableAlias(idPath,
context
+                        .getQuotingStrategy().quotedFullyQualifiedName(table));
                 if (attribute.isFlattened()) {
                     Iterator<?> dbPathIterator = attribute.getDbPathIterator();
                     EJBQLTableId lhsId = new EJBQLTableId(idPath);
 
                     while (dbPathIterator.hasNext()) {
                         Object pathPart = dbPathIterator.next();
-                        // DbRelationships not processed, because they will be processed
+                        // DbRelationships not processed, because they will be
+                        // processed
                         // later when appending table
                         if (pathPart == null) {
-                            throw new CayenneRuntimeException(
-                                    "ObjAttribute has no component: "
-                                            + attribute.getName());
-                        }
-                        else if (pathPart instanceof DbAttribute) {
+                            throw new CayenneRuntimeException("ObjAttribute has no component:
" + attribute.getName());
+                        } else if (pathPart instanceof DbAttribute) {
                             DbAttribute dbAttribute = (DbAttribute) pathPart;
-                            appendColumn(
-                                    attribute.getType(),
-                                    context.getTableAlias(
-                                            lhsId.getEntityId(),
-                                            context.getQuotingSupport()
-                                                    .generateTableName((DbEntity) dbAttribute.getEntity())),
-                                    dbAttribute,
-                                    context.isAppendingResultColumns() ? context
-                                            .nextColumnAlias() : "");
+                            appendColumn(attribute.getType(),
+                                    context.getTableAlias(lhsId.getEntityId(), context.getQuotingStrategy()
+                                            .quotedFullyQualifiedName((DbEntity) dbAttribute.getEntity())),
+                                    dbAttribute, context.isAppendingResultColumns() ? context.nextColumnAlias()
: "");
 
                         }
 
                     }
 
-                }
-                else {
+                } else {
 
                     DbAttribute dbAttribute = attribute.getDbAttribute();
 
-                    appendColumn(attribute.getType(), alias, dbAttribute, context
-                            .isAppendingResultColumns() ? context.nextColumnAlias() : "");
+                    appendColumn(attribute.getType(), alias, dbAttribute,
+                            context.isAppendingResultColumns() ? context.nextColumnAlias()
: "");
                 }
             }
 
@@ -166,24 +154,18 @@ public class EJBQLSelectColumnsTranslato
 
     @Override
     public boolean visitIdentifier(EJBQLExpression expression) {
-        expression.visit(context.getTranslatorFactory().getIdentifierColumnsTranslator(
-                context));
+        expression.visit(context.getTranslatorFactory().getIdentifierColumnsTranslator(context));
         return false;
     }
 
-    public void appendColumn(
-            String javaType,
-            String alias,
-            DbAttribute dbAttribute,
-            String columnAlias) {
+    public void appendColumn(String javaType, String alias, DbAttribute dbAttribute, String
columnAlias) {
         if (context.isAppendingResultColumns()) {
             context.append(" #result('");
-        }
-        else {
+        } else {
             context.append(' ');
         }
 
-        context.append(alias).append('.').append(context.getQuotingSupport().generateColumnName(dbAttribute));
+        context.append(alias).append('.').append(context.getQuotingStrategy().quotedName(dbAttribute));
 
         if (context.isAppendingResultColumns()) {
             // String columnAlias = context.nextColumnAlias();
@@ -191,15 +173,8 @@ public class EJBQLSelectColumnsTranslato
             // TODO: andrus 6/27/2007 - the last parameter is an unofficial
             // "jdbcType"
             // pending CAY-813 implementation, switch to #column directive
-            context
-                    .append("' '")
-                    .append(javaType)
-                    .append("' '")
-                    .append(columnAlias)
-                    .append("' '")
-                    .append(columnAlias)
-                    .append("' " + dbAttribute.getType())
-                    .append(")");
+            context.append("' '").append(javaType).append("' '").append(columnAlias).append("'
'").append(columnAlias)
+                    .append("' " + dbAttribute.getType()).append(")");
         }
 
     }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLTranslationContext.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLTranslationContext.java?rev=1449474&r1=1449473&r2=1449474&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLTranslationContext.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLTranslationContext.java
Sun Feb 24 13:05:14 2013
@@ -24,8 +24,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.cayenne.dba.JdbcAdapter;
-import org.apache.cayenne.dba.QuotingSupport;
+import org.apache.cayenne.dba.QuotingStrategy;
 import org.apache.cayenne.ejbql.EJBQLCompiledExpression;
 import org.apache.cayenne.ejbql.EJBQLException;
 import org.apache.cayenne.map.DbEntity;
@@ -49,7 +48,7 @@ public class EJBQLTranslationContext {
     protected Map<String, Object> namedParameters;
     protected Map<Integer, Object> positionalParameters;
     private EJBQLTranslatorFactory translatorFactory;
-    private QuotingSupport quotingSupport;
+    private QuotingStrategy quotingStrategy;
     private EntityResolver entityResolver;
     private List<Object> resultSetMetadata;
 
@@ -72,7 +71,7 @@ public class EJBQLTranslationContext {
 
     public EJBQLTranslationContext(EntityResolver entityResolver, EJBQLQuery query,
             EJBQLCompiledExpression compiledExpression,
-            EJBQLTranslatorFactory translatorFactory) {
+            EJBQLTranslatorFactory translatorFactory, QuotingStrategy quotingStrategy) {
 
         this.entityResolver = entityResolver;
         this.compiledExpression = compiledExpression;
@@ -84,8 +83,7 @@ public class EJBQLTranslationContext {
         this.usingAliases = true;
         this.caseInsensitive = false;
         this.queryMetadata = query.getMetaData(entityResolver);
-
-        this.quotingSupport = ((JdbcEJBQLTranslatorFactory) translatorFactory).getQuotingSupport();
+        this.quotingStrategy = quotingStrategy;
 
         // buffer stack will hold named buffers during translation in the order they were
         // requested
@@ -444,8 +442,8 @@ public class EJBQLTranslationContext {
         this.caseInsensitive = caseInsensitive;
     }
 
-    public QuotingSupport getQuotingSupport() {
-        return this.quotingSupport;
+    public QuotingStrategy getQuotingStrategy() {
+        return quotingStrategy;
     }
 
     public void onSubselect() {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/JdbcEJBQLTranslatorFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/JdbcEJBQLTranslatorFactory.java?rev=1449474&r1=1449473&r2=1449474&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/JdbcEJBQLTranslatorFactory.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/JdbcEJBQLTranslatorFactory.java
Sun Feb 24 13:05:14 2013
@@ -18,9 +18,6 @@
  ****************************************************************/
 package org.apache.cayenne.access.jdbc;
 
-import org.apache.cayenne.dba.DbAdapter;
-import org.apache.cayenne.dba.DefaultQuotingStrategy;
-import org.apache.cayenne.dba.QuotingSupport;
 import org.apache.cayenne.ejbql.EJBQLExpressionVisitor;
 
 /**
@@ -34,20 +31,6 @@ public class JdbcEJBQLTranslatorFactory 
     
     protected boolean caseInsensitive = false;
 
-    protected QuotingSupport quotingSupport;
-
-    public JdbcEJBQLTranslatorFactory() {
-        initQuoting();
-    }
-
-    protected void initQuoting() {
-        quotingSupport = new QuotingSupport(new DefaultQuotingStrategy());
-    }
-
-    public QuotingSupport getQuotingSupport() {
-        return this.quotingSupport;
-    }
-
     public EJBQLJoinAppender getJoinAppender(EJBQLTranslationContext context) {
         EJBQLJoinAppender appender = (EJBQLJoinAppender) context
                 .getAttribute(JOIN_APPENDER_KEY);

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/jdbc/EJBQLSelectTranslatorTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/jdbc/EJBQLSelectTranslatorTest.java?rev=1449474&r1=1449473&r2=1449474&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/jdbc/EJBQLSelectTranslatorTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/jdbc/EJBQLSelectTranslatorTest.java
Sun Feb 24 13:05:14 2013
@@ -23,6 +23,7 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.cayenne.configuration.server.ServerRuntime;
+import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.ejbql.EJBQLCompiledExpression;
 import org.apache.cayenne.ejbql.EJBQLParser;
@@ -38,17 +39,16 @@ public class EJBQLSelectTranslatorTest e
     @Inject
     private ServerRuntime runtime;
 
+    @Inject
+    private DbAdapter adapter;
+
     private SQLTemplate translateSelect(String ejbql) {
         return translateSelect(ejbql, Collections.EMPTY_MAP);
     }
 
-    private SQLTemplate translateSelect(
-            String ejbql,
-            final Map<Integer, Object> queryParameters) {
+    private SQLTemplate translateSelect(String ejbql, final Map<Integer, Object> queryParameters)
{
         EJBQLParser parser = EJBQLParserFactory.getParser();
-        EJBQLCompiledExpression select = parser.compile(ejbql, runtime
-                .getDataDomain()
-                .getEntityResolver());
+        EJBQLCompiledExpression select = parser.compile(ejbql, runtime.getDataDomain().getEntityResolver());
         EJBQLQuery query = new EJBQLQuery(ejbql) {
 
             @Override
@@ -57,9 +57,8 @@ public class EJBQLSelectTranslatorTest e
             }
         };
 
-        EJBQLTranslationContext tr = new EJBQLTranslationContext(runtime
-                .getDataDomain()
-                .getEntityResolver(), query, select, new JdbcEJBQLTranslatorFactory());
+        EJBQLTranslationContext tr = new EJBQLTranslationContext(runtime.getDataDomain().getEntityResolver(),
query,
+                select, new JdbcEJBQLTranslatorFactory(), adapter.getQuotingStrategy());
         select.getExpression().visit(new EJBQLSelectTranslator(tr));
         return tr.getQuery();
     }
@@ -68,7 +67,8 @@ public class EJBQLSelectTranslatorTest e
         SQLTemplate query = translateSelect("select a from Artist a");
         String sql = query.getDefaultTemplate();
 
-        // column order is unpredictable, just need to ensure that they are all there
+        // column order is unpredictable, just need to ensure that they are all
+        // there
         assertTrue(sql, sql.startsWith("SELECT"));
         assertTrue(sql, sql.indexOf("t0.ARTIST_ID") > 0);
         assertTrue(sql, sql.indexOf("t0.ARTIST_NAME") > 0);
@@ -84,10 +84,8 @@ public class EJBQLSelectTranslatorTest e
 
         assertTrue(sql, sql.startsWith("SELECT"));
 
-        assertTrue(sql, sql
-                .indexOf("INNER JOIN PAINTING t1 ON (t0.ARTIST_ID = t1.ARTIST_ID)") >
0);
-        assertTrue(sql, sql
-                .indexOf("INNER JOIN PAINTING t2 ON (t0.ARTIST_ID = t2.ARTIST_ID)") >
0);
+        assertTrue(sql, sql.indexOf("INNER JOIN PAINTING t1 ON (t0.ARTIST_ID = t1.ARTIST_ID)")
> 0);
+        assertTrue(sql, sql.indexOf("INNER JOIN PAINTING t2 ON (t0.ARTIST_ID = t2.ARTIST_ID)")
> 0);
     }
 
     public void testSelectImplicitColumnJoins() throws Exception {
@@ -97,7 +95,8 @@ public class EJBQLSelectTranslatorTest e
 
         assertTrue(sql, sql.startsWith("SELECT"));
 
-        // check that overlapping implicit and explicit joins did not result in duplicates
+        // check that overlapping implicit and explicit joins did not result in
+        // duplicates
 
         assertTrue(sql, sql.contains("INNER JOIN GALLERY"));
         assertTrue(sql, sql.contains("INNER JOIN PAINTING"));
@@ -123,8 +122,7 @@ public class EJBQLSelectTranslatorTest e
 
         assertTrue(sql, sql.startsWith("SELECT"));
 
-        assertTrue(sql, sql.endsWith(" FROM ARTIST t0 WHERE t0.ARTIST_NAME ="
-                + " #bind('Dali' 'VARCHAR')"));
+        assertTrue(sql, sql.endsWith(" FROM ARTIST t0 WHERE t0.ARTIST_NAME =" + " #bind('Dali'
'VARCHAR')"));
     }
 
     public void testSelectFromWhereOrEqual() {
@@ -133,8 +131,7 @@ public class EJBQLSelectTranslatorTest e
         String sql = query.getDefaultTemplate();
 
         SQLTemplate query1 = translateSelect("select a from Artist a where a.artistName =
'Picasso' "
-                + "or a.artistName = 'Malevich' "
-                + "or a.artistName = 'Dali'");
+                + "or a.artistName = 'Malevich' " + "or a.artistName = 'Dali'");
         String sql1 = query1.getDefaultTemplate();
 
         assertTrue(sql, sql.startsWith("SELECT"));
@@ -153,8 +150,7 @@ public class EJBQLSelectTranslatorTest e
         String sql = query.getDefaultTemplate();
 
         SQLTemplate query1 = translateSelect("select a from Artist a where a.artistName =
'Picasso' "
-                + "and a.artistName = 'Malevich' "
-                + "and a.artistName = 'Dali'");
+                + "and a.artistName = 'Malevich' " + "and a.artistName = 'Dali'");
         String sql1 = query1.getDefaultTemplate();
 
         assertTrue(sql, sql.startsWith("SELECT"));
@@ -171,8 +167,7 @@ public class EJBQLSelectTranslatorTest e
         String sql = query.getDefaultTemplate();
 
         assertTrue(sql, sql.startsWith("SELECT"));
-        assertTrue(sql, sql.endsWith("WHERE NOT "
-                + "t0.ARTIST_NAME = #bind('Dali' 'VARCHAR')"));
+        assertTrue(sql, sql.endsWith("WHERE NOT " + "t0.ARTIST_NAME = #bind('Dali' 'VARCHAR')"));
     }
 
     public void testSelectFromWhereGreater() {
@@ -228,36 +223,31 @@ public class EJBQLSelectTranslatorTest e
         SQLTemplate query = translateSelect("select p from Painting p where p.paintingTitle
like 'Stuff'");
         String sql = query.getDefaultTemplate();
 
-        assertTrue(sql, sql.endsWith("WHERE t0.PAINTING_TITLE "
-                + "LIKE #bind('Stuff' 'VARCHAR')"));
+        assertTrue(sql, sql.endsWith("WHERE t0.PAINTING_TITLE " + "LIKE #bind('Stuff' 'VARCHAR')"));
     }
 
     public void testSelectFromWhereNotLike() {
         SQLTemplate query = translateSelect("select p from Painting p where p.paintingTitle
NOT like 'Stuff'");
         String sql = query.getDefaultTemplate();
 
-        assertTrue(sql, sql.endsWith("WHERE t0.PAINTING_TITLE "
-                + "NOT LIKE #bind('Stuff' 'VARCHAR')"));
+        assertTrue(sql, sql.endsWith("WHERE t0.PAINTING_TITLE " + "NOT LIKE #bind('Stuff'
'VARCHAR')"));
     }
 
     public void testSelectPositionalParameters() {
         Map<Integer, Object> params = new HashMap<Integer, Object>();
         params.put(new Integer(1), "X");
         params.put(new Integer(2), "Y");
-        SQLTemplate query = translateSelect(
-                "select a from Artist a where a.artistName = ?1 or a.artistName = ?2",
+        SQLTemplate query = translateSelect("select a from Artist a where a.artistName =
?1 or a.artistName = ?2",
                 params);
         String sql = query.getDefaultTemplate();
-        assertTrue(sql, sql
-                .endsWith("t0.ARTIST_NAME = #bind($id0) OR t0.ARTIST_NAME = #bind($id1)"));
+        assertTrue(sql, sql.endsWith("t0.ARTIST_NAME = #bind($id0) OR t0.ARTIST_NAME = #bind($id1)"));
     }
 
     public void testMax() {
         SQLTemplate query = translateSelect("select max(p.estimatedPrice) from Painting p");
         String sql = query.getDefaultTemplate();
 
-        assertTrue(sql, sql.startsWith("SELECT "
-                + "#result('MAX(t0.ESTIMATED_PRICE)' 'java.math.BigDecimal' 'sc0') "
+        assertTrue(sql, sql.startsWith("SELECT " + "#result('MAX(t0.ESTIMATED_PRICE)' 'java.math.BigDecimal'
'sc0') "
                 + "FROM PAINTING t0"));
     }
 
@@ -265,11 +255,9 @@ public class EJBQLSelectTranslatorTest e
         SQLTemplate query = translateSelect("select sum( distinct p.estimatedPrice) from
Painting p");
         String sql = query.getDefaultTemplate();
 
-        assertTrue(
-                sql,
-                sql
-                        .startsWith("SELECT #result('SUM(DISTINCT t0.ESTIMATED_PRICE)' 'java.math.BigDecimal'
'sc0') "
-                                + "FROM PAINTING t0"));
+        assertTrue(sql,
+                sql.startsWith("SELECT #result('SUM(DISTINCT t0.ESTIMATED_PRICE)' 'java.math.BigDecimal'
'sc0') "
+                        + "FROM PAINTING t0"));
     }
 
     public void testColumnPaths() {
@@ -291,19 +279,17 @@ public class EJBQLSelectTranslatorTest e
         return i;
     }
 
-    // if parameter value is null (in this test x := null) we will generate "IS NULL"
+    // if parameter value is null (in this test x := null) we will generate
+    // "IS NULL"
     public void testEqualsNullParameter() {
         String ejbql = "select p from Painting p WHERE p.toArtist=:x";
         EJBQLParser parser = EJBQLParserFactory.getParser();
-        EJBQLCompiledExpression select = parser.compile(ejbql, runtime
-                .getDataDomain()
-                .getEntityResolver());
+        EJBQLCompiledExpression select = parser.compile(ejbql, runtime.getDataDomain().getEntityResolver());
         EJBQLQuery query = new EJBQLQuery(ejbql);
         query.setParameter("x", null);
 
-        EJBQLTranslationContext tr = new EJBQLTranslationContext(runtime
-                .getDataDomain()
-                .getEntityResolver(), query, select, new JdbcEJBQLTranslatorFactory());
+        EJBQLTranslationContext tr = new EJBQLTranslationContext(runtime.getDataDomain().getEntityResolver(),
query,
+                select, new JdbcEJBQLTranslatorFactory(), adapter.getQuotingStrategy());
         select.getExpression().visit(new EJBQLSelectTranslator(tr));
         String sql = tr.getQuery().getDefaultTemplate();
         assertTrue(sql, sql.endsWith("t0.ARTIST_ID IS NULL"));
@@ -313,19 +299,15 @@ public class EJBQLSelectTranslatorTest e
     public void testEqualsNullAndNotNullParameter() {
         String ejbql = "select p from Painting p WHERE p.toArtist=:x OR p.toArtist.artistName=:b";
         EJBQLParser parser = EJBQLParserFactory.getParser();
-        EJBQLCompiledExpression select = parser.compile(ejbql, runtime
-                .getDataDomain()
-                .getEntityResolver());
+        EJBQLCompiledExpression select = parser.compile(ejbql, runtime.getDataDomain().getEntityResolver());
         EJBQLQuery query = new EJBQLQuery(ejbql);
         query.setParameter("x", null);
         query.setParameter("b", "Y");
 
-        EJBQLTranslationContext tr = new EJBQLTranslationContext(runtime
-                .getDataDomain()
-                .getEntityResolver(), query, select, new JdbcEJBQLTranslatorFactory());
+        EJBQLTranslationContext tr = new EJBQLTranslationContext(runtime.getDataDomain().getEntityResolver(),
query,
+                select, new JdbcEJBQLTranslatorFactory(), adapter.getQuotingStrategy());
         select.getExpression().visit(new EJBQLSelectTranslator(tr));
         String sql = tr.getQuery().getDefaultTemplate();
-        assertTrue(sql, sql
-                .endsWith("t0.ARTIST_ID IS NULL OR t1.ARTIST_NAME = #bind($id0)"));
+        assertTrue(sql, sql.endsWith("t0.ARTIST_ID IS NULL OR t1.ARTIST_NAME = #bind($id0)"));
     }
 }



Mime
View raw message