1 28 29 package com.caucho.amber.query; 30 31 import com.caucho.util.CharBuffer; 32 33 36 class BetweenExpr extends AbstractAmberExpr { 37 private AmberExpr _expr; 38 39 private AmberExpr _min; 40 private AmberExpr _max; 41 42 private boolean _isNot; 43 44 47 BetweenExpr(AmberExpr expr, AmberExpr min, AmberExpr max, boolean isNot) 48 { 49 _expr = expr; 50 _min = min; 51 _max = max; 52 53 _isNot = isNot; 54 } 55 56 59 public AmberExpr bindSelect(QueryParser parser) 60 { 61 _expr = _expr.bindSelect(parser); 62 _min = _min.bindSelect(parser); 63 _max = _max.bindSelect(parser); 64 65 return this; 66 } 67 68 71 public boolean usesFrom(FromItem from, int type, boolean isNot) 72 { 73 return (_expr.usesFrom(from, type) || 74 _min.usesFrom(from, type) || 75 _max.usesFrom(from, type)); 76 } 77 78 81 public void generateWhere(CharBuffer cb) 82 { 83 cb.append('('); 84 _expr.generateWhere(cb); 85 86 if (_isNot) 87 cb.append(" NOT"); 88 89 cb.append(" BETWEEN "); 90 91 _min.generateWhere(cb); 92 93 cb.append(" AND "); 94 95 _max.generateWhere(cb); 96 97 cb.append(')'); 98 } 99 100 public String toString() 101 { 102 CharBuffer cb = CharBuffer.allocate(); 103 104 cb.append('('); 105 cb.append(_expr); 106 107 if (_isNot) 108 cb.append(" NOT"); 109 110 cb.append(" BETWEEN "); 111 112 cb.append(_min); 113 114 cb.append(" AND "); 115 116 cb.append(_max); 117 118 cb.append(')'); 119 120 return cb.close(); 121 } 122 } 123 | Popular Tags |