1 19 20 package org.apache.cayenne.dba.postgres; 21 22 import org.apache.cayenne.access.trans.QueryAssembler; 23 import org.apache.cayenne.access.trans.TrimmingQualifierTranslator; 24 import org.apache.cayenne.exp.Expression; 25 26 32 public class PostgresQualifierTranslator extends TrimmingQualifierTranslator { 33 34 public PostgresQualifierTranslator(QueryAssembler queryAssembler) { 35 super(queryAssembler, "RTRIM"); 36 } 37 38 public void startNode(Expression node, Expression parentNode) { 39 40 if (node.getOperandCount() == 2) { 41 detectObjectMatch(node); 43 44 if (parenthesisNeeded(node, parentNode)) { 45 qualBuf.append('('); 46 } 47 48 } 53 else { 54 super.startNode(node, parentNode); 55 } 56 } 57 58 public void endNode(Expression node, Expression parentNode) { 59 if (node.getOperandCount() == 2) { 60 if (matchingObject) { 62 appendObjectMatch(); 63 } 64 65 if (parenthesisNeeded(node, parentNode)) 66 qualBuf.append(')'); 67 68 } 73 else { 74 super.endNode(node, parentNode); 75 } 76 } 77 78 public void finishedChild(Expression node, int childIndex, boolean hasMoreChildren) { 79 if (!hasMoreChildren) { 80 return; 81 } 82 83 85 switch (node.getType()) { 86 87 case Expression.LIKE_IGNORE_CASE : 88 finishedChildNodeAppendExpression(node, " ILIKE "); 89 break; 90 case Expression.NOT_LIKE_IGNORE_CASE : 91 finishedChildNodeAppendExpression(node, " NOT ILIKE "); 92 break; 93 default : 94 super.finishedChild(node, childIndex, hasMoreChildren); 95 } 96 } 97 98 private void finishedChildNodeAppendExpression(Expression node, String operation) { 99 StringBuffer buf = (matchingObject) ? new StringBuffer () : qualBuf; 100 buf.append(operation); 101 if (matchingObject) { 102 objectMatchTranslator.setOperation(buf.toString()); 103 objectMatchTranslator.setExpression(node); 104 } 105 } 106 } 107 | Popular Tags |