1 56 package org.objectstyle.cayenne.dba.postgres; 57 58 import org.objectstyle.cayenne.access.trans.QueryAssembler; 59 import org.objectstyle.cayenne.access.trans.TrimmingQualifierTranslator; 60 import org.objectstyle.cayenne.exp.Expression; 61 62 68 public class PostgresQualifierTranslator extends TrimmingQualifierTranslator { 69 70 public PostgresQualifierTranslator(QueryAssembler queryAssembler) { 71 super(queryAssembler, "RTRIM"); 72 } 73 74 public void startNode(Expression node, Expression parentNode) { 75 76 if (node.getOperandCount() == 2) { 77 detectObjectMatch(node); 79 80 if (parenthesisNeeded(node, parentNode)) { 81 qualBuf.append('('); 82 } 83 84 } 89 else { 90 super.startNode(node, parentNode); 91 } 92 } 93 94 public void endNode(Expression node, Expression parentNode) { 95 if (node.getOperandCount() == 2) { 96 if (matchingObject) { 98 appendObjectMatch(); 99 } 100 101 if (parenthesisNeeded(node, parentNode)) 102 qualBuf.append(')'); 103 104 } 109 else { 110 super.endNode(node, parentNode); 111 } 112 } 113 114 public void finishedChild(Expression node, int childIndex, boolean hasMoreChildren) { 115 if (!hasMoreChildren) { 116 return; 117 } 118 119 121 switch (node.getType()) { 122 123 case Expression.LIKE_IGNORE_CASE : 124 finishedChildNodeAppendExpression(node, " ILIKE "); 125 break; 126 case Expression.NOT_LIKE_IGNORE_CASE : 127 finishedChildNodeAppendExpression(node, " NOT ILIKE "); 128 break; 129 default : 130 super.finishedChild(node, childIndex, hasMoreChildren); 131 } 132 } 133 134 private void finishedChildNodeAppendExpression(Expression node, String operation) { 135 StringBuffer buf = (matchingObject) ? new StringBuffer () : qualBuf; 136 buf.append(operation); 137 if (matchingObject) { 138 objectMatchTranslator.setOperation(buf.toString()); 139 objectMatchTranslator.setExpression(node); 140 } 141 } 142 } | Popular Tags |