1 28 29 package com.caucho.db.sql; 30 31 import com.caucho.log.Log; 32 33 import java.sql.SQLException ; 34 import java.util.ArrayList ; 35 import java.util.logging.Logger ; 36 37 class SubSelectParamExpr extends Expr { 38 private static final Logger log = Log.open(SubSelectParamExpr.class); 39 40 private SelectQuery _subselect; 41 private Expr _expr; 42 private int _index; 43 44 SubSelectParamExpr(Query subselect, Expr expr, int index) 45 { 46 _subselect = (SelectQuery) subselect; 47 _expr = expr; 48 _index = index; 49 } 50 51 54 public Class getType() 55 { 56 return _expr.getType(); 57 } 58 59 62 public Expr getExpr() 63 { 64 return _expr; 65 } 66 67 70 public long subCost(ArrayList <FromItem> fromList) 71 { 72 return _subselect.getSubSelect().cost(fromList) + 1; 73 } 74 75 78 public Expr bind(Query parent) 79 throws SQLException 80 { 81 _expr = _expr.bind(parent); 82 83 return this; 84 } 85 86 89 public void eval(QueryContext parent, QueryContext context) 90 throws SQLException 91 { 92 Class type = getType(); 93 94 if (_expr.isNull(parent)) 95 context.setNull(_index); 96 else if (long.class.equals(type)) 97 context.setLong(_index, _expr.evalLong(parent)); 98 else if (int.class.equals(type)) 99 context.setLong(_index, _expr.evalLong(parent)); 100 else { 101 context.setString(_index, _expr.evalString(parent)); 102 } 103 } 104 105 112 public boolean isNull(QueryContext context) 113 throws SQLException 114 { 115 return context.isNull(_index); 116 } 117 118 125 public String evalString(QueryContext context) 126 throws SQLException 127 { 128 return context.getString(_index); 129 } 130 131 138 public int evalBoolean(QueryContext context) 139 throws SQLException 140 { 141 return context.getBoolean(_index); 142 } 143 144 151 public long evalLong(QueryContext context) 152 throws SQLException 153 { 154 return context.getLong(_index); 155 } 156 157 164 public double evalDouble(QueryContext context) 165 throws SQLException 166 { 167 return context.getDouble(_index); 168 } 169 170 177 public long evalDate(QueryContext context) 178 throws SQLException 179 { 180 return context.getDate(_index); 181 } 182 183 public String toString() 184 { 185 return "SubSelectParamExpr[" + _expr + "]"; 186 } 187 } 188 | Popular Tags |