1 29 30 package com.caucho.db.sql; 31 32 import com.caucho.log.Log; 33 34 import java.sql.SQLException ; 35 import java.util.ArrayList ; 36 import java.util.logging.Logger ; 37 38 class BinaryLongExpr extends Expr { 39 private static final Logger log = Log.open(BinaryLongExpr.class); 40 41 private Expr _left; 42 private Expr _right; 43 private int _op; 44 45 BinaryLongExpr(Expr left, Expr right, int op) 46 { 47 _left = left; 48 _right = right; 49 _op = op; 50 } 51 52 protected Expr bind(FromItem []fromItems) 53 throws SQLException 54 { 55 throw new UnsupportedOperationException (); 56 } 57 58 61 public Class getType() 62 { 63 return long.class; 64 } 65 66 69 public long subCost(ArrayList <FromItem> fromList) 70 { 71 return _left.subCost(fromList) + _right.subCost(fromList); 72 } 73 74 81 public long evalLong(QueryContext context) 82 throws SQLException 83 { 84 switch (_op) { 85 case '+': 86 return _left.evalLong(context) + _right.evalLong(context); 87 88 case '-': 89 return _left.evalLong(context) - _right.evalLong(context); 90 91 case '*': 92 return _left.evalLong(context) * _right.evalLong(context); 93 94 case '/': 95 return _left.evalLong(context) / _right.evalLong(context); 96 97 case '%': 98 return _left.evalLong(context) % _right.evalLong(context); 99 100 default: 101 throw new IllegalStateException (); 102 } 103 } 104 105 112 public double evalDouble(QueryContext context) 113 throws SQLException 114 { 115 return evalLong(context); 116 } 117 118 125 public String evalString(QueryContext context) 126 throws SQLException 127 { 128 return String.valueOf(evalLong(context)); 129 } 130 131 136 public void evalGroup(QueryContext context) 137 throws SQLException 138 { 139 _left.evalGroup(context); 140 _right.evalGroup(context); 141 } 142 143 public boolean equals(Object o) 144 { 145 if (o == null || ! BinaryLongExpr.class.equals(o.getClass())) 146 return false; 147 148 BinaryLongExpr expr = (BinaryLongExpr) o; 149 150 return (_op == expr._op && 151 _left.equals(expr._left) && 152 _right.equals(expr._right)); 153 } 154 155 public String toString() 156 { 157 switch (_op) { 158 case '+': 159 return "(" + _left + " + " + _right + ")"; 160 161 case '-': 162 return "(" + _left + " - " + _right + ")"; 163 164 case '*': 165 return "(" + _left + " * " + _right + ")"; 166 167 case '/': 168 return "(" + _left + " / " + _right + ")"; 169 170 case '%': 171 return "(" + _left + " % " + _right + ")"; 172 173 default: 174 throw new IllegalStateException (); 175 } 176 } 177 } 178 | Popular Tags |