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.EJBQLExpressionVisitor; 25 import org.apache.cayenne.ejbql.parser.EJBQLPath; 26 27 31 class EJBQLOrderByTranslator extends EJBQLBaseVisitor { 32 33 private EJBQLTranslationContext context; 34 private int itemCount; 35 36 EJBQLOrderByTranslator(EJBQLTranslationContext context) { 37 this.context = context; 38 } 39 40 public boolean visitOrderByItem(EJBQLExpression expression) { 41 if (itemCount++ > 0) { 42 context.append(','); 43 } 44 45 return true; 46 } 47 48 public boolean visitDescending(EJBQLExpression expression) { 49 context.append(" DESC"); 50 return true; 51 } 52 53 public boolean visitPath(EJBQLPath expression, int finishedChildIndex) { 54 55 EJBQLExpressionVisitor childVisitor = new EJBQLPathTranslator(context) { 56 57 protected void appendMultiColumnPath(EJBQLMultiColumnOperand operand) { 58 throw new EJBQLException("Can't order on multi-column paths or objects"); 59 } 60 }; 61 expression.visit(childVisitor); 62 return false; 63 } 64 } 65 | Popular Tags |