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.HashSet ; 37 import java.util.logging.Logger ; 38 39 class InExpr extends Expr { 40 private static final Logger log = Log.open(InExpr.class); 41 42 private Expr _expr; 43 private final HashSet <String > _values; 44 private final boolean _isNot; 45 46 InExpr(Expr expr, HashSet <String > values, boolean isNot) 47 { 48 _expr = expr; 49 _values = values; 50 _isNot = isNot; 51 } 52 53 56 protected Expr bind(Query query) 57 throws SQLException 58 { 59 _expr = _expr.bind(query); 60 61 return this; 62 } 63 64 67 public Class getType() 68 { 69 return boolean.class; 70 } 71 72 75 public long subCost(ArrayList <FromItem> fromList) 76 { 77 return _expr.subCost(fromList); 78 } 79 80 87 public int evalBoolean(QueryContext context) 88 throws SQLException 89 { 90 if (_values.contains(_expr.evalString(context))) 91 return _isNot ? FALSE : TRUE; 92 else 93 return _isNot ? TRUE : FALSE; 94 } 95 96 103 public String evalString(QueryContext context) 104 throws SQLException 105 { 106 return (evalBoolean(context) == TRUE) ? "1" : "0"; 107 } 108 109 114 public void evalGroup(QueryContext context) 115 throws SQLException 116 { 117 _expr.evalGroup(context); 118 } 119 120 public String toString() 121 { 122 return _expr + " IN " + _values; 123 } 124 } 125 | Popular Tags |