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 BinaryExpr extends Expr { 39 private static final Logger log = Log.open(BinaryExpr.class); 40 41 private Expr _left; 42 private Expr _right; 43 private int _op; 44 45 BinaryExpr(Expr left, Expr right, int op) 46 { 47 _left = left; 48 _right = right; 49 _op = op; 50 } 51 52 55 protected Expr bind(Query query) 56 throws SQLException 57 { 58 Expr newLeft = _left.bind(query); 59 Expr newRight = _right.bind(query); 60 61 switch (_op) { 62 case '+': 63 case '-': 64 case '*': 65 case '/': 66 case '%': 67 if (newLeft.isLong() && newRight.isLong()) 68 return new BinaryLongExpr(newLeft, newRight, _op); 69 else 70 return new BinaryDoubleExpr(newLeft, newRight, _op); 71 } 72 73 throw new SQLException ("can't cope: " + newLeft + " " + newLeft.getType() + " " + newRight); 74 } 75 76 79 public long subCost(ArrayList <FromItem> fromList) 80 { 81 return _left.subCost(fromList) + _right.subCost(fromList); 82 } 83 84 87 public Class getType() 88 { 89 return Object .class; 90 } 91 92 97 public void evalGroup(QueryContext context) 98 throws SQLException 99 { 100 _left.evalGroup(context); 101 _right.evalGroup(context); 102 } 103 104 public String toString() 105 { 106 switch (_op) { 107 case '+': 108 return "(" + _left + " + " + _right + ")"; 109 110 case '-': 111 return "(" + _left + " - " + _right + ")"; 112 113 case '*': 114 return "(" + _left + " * " + _right + ")"; 115 116 case '/': 117 return "(" + _left + " / " + _right + ")"; 118 119 case '%': 120 return "(" + _left + " % " + _right + ")"; 121 122 default: 123 throw new IllegalStateException ("can't compare"); 124 } 125 } 126 } 127 | Popular Tags |