1 19 package org.apache.cayenne.access.jdbc; 20 21 import org.apache.cayenne.ejbql.EJBQLBaseVisitor; 22 import org.apache.cayenne.ejbql.EJBQLException; 23 import org.apache.cayenne.ejbql.EJBQLExpression; 24 import org.apache.cayenne.ejbql.parser.EJBQLPath; 25 import org.apache.cayenne.map.DbAttribute; 26 import org.apache.cayenne.map.DbEntity; 27 import org.apache.cayenne.map.ObjAttribute; 28 29 35 class EJBQLSelectColumnsTranslator extends EJBQLBaseVisitor { 36 37 private EJBQLTranslationContext context; 38 private int expressionsCount; 39 40 EJBQLSelectColumnsTranslator(EJBQLTranslationContext context) { 41 this.context = context; 42 } 43 44 public boolean visitSelectExpression(EJBQLExpression expression) { 45 if (expressionsCount++ > 0) { 46 context.append(","); 47 } 48 49 return true; 50 } 51 52 public boolean visitAggregate(EJBQLExpression expression) { 53 expression.visit(new EJBQLAggregateColumnTranslator(context)); 54 return false; 55 } 56 57 public boolean visitPath(EJBQLPath expression, int finishedChildIndex) { 58 59 EJBQLPathTranslator pathTranslator = new EJBQLPathTranslator(context) { 60 61 protected void appendMultiColumnPath(EJBQLMultiColumnOperand operand) { 62 throw new EJBQLException("Can't use multi-column paths in column clause"); 63 } 64 65 protected void processTerminatingAttribute(ObjAttribute attribute) { 66 DbEntity table = currentEntity.getDbEntity(); 67 String alias = this.lastAlias != null ? lastAlias : context 68 .getTableAlias(idPath, table.getFullyQualifiedName()); 69 70 DbAttribute dbAttribute = (DbAttribute) attribute.getDbAttribute(); 71 72 String columnAlias = context.nextColumnAlias(); 75 context 76 .append(" #result('") 77 .append(alias) 78 .append('.') 79 .append(dbAttribute.getName()) 80 .append("' '") 81 .append(attribute.getType()) 82 .append("' '") 83 .append(columnAlias) 84 .append("' '") 85 .append(columnAlias) 86 .append("' " + dbAttribute.getType()) 87 .append(")"); 88 } 89 }; 90 91 expression.visit(pathTranslator); 92 return false; 93 } 94 95 public boolean visitIdentifier(EJBQLExpression expression) { 96 expression.visit(new EJBQLIdentifierColumnsTranslator(context, true)); 97 return false; 98 } 99 } 100 | Popular Tags |