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 OrExpr extends Expr { 38 private static final Logger log = Log.open(OrExpr.class); 39 40 private Expr _left; 41 private Expr _right; 42 43 OrExpr(Expr left, Expr right) 44 { 45 _left = left; 46 _right = right; 47 } 48 49 protected Expr bind(Query query) 50 throws SQLException 51 { 52 Expr newLeft = _left.bind(query); 53 Expr newRight = _right.bind(query); 54 55 if (! newLeft.isBoolean()) 56 throw new SQLException (L.l("OR requires boolean operands")); 57 if (! newRight.isBoolean()) 58 throw new SQLException (L.l("OR requires boolean operands")); 59 60 if (_left == newLeft && _right == newRight) 61 return this; 62 else 63 return new OrExpr(newLeft, newRight); 64 } 65 66 69 public Class getType() 70 { 71 return boolean.class; 72 } 73 74 77 public long subCost(ArrayList <FromItem> fromList) 78 { 79 return Integer.MAX_VALUE; 80 } 81 82 85 public boolean isNull(QueryContext context) 86 throws SQLException 87 { 88 return evalBoolean(context) == UNKNOWN; 89 } 90 91 94 public int evalBoolean(QueryContext context) 95 throws SQLException 96 { 97 int leftValue = _left.evalBoolean(context); 98 99 if (leftValue == TRUE) 100 return TRUE; 101 102 int rightValue = _right.evalBoolean(context); 103 104 if (rightValue == TRUE) 105 return TRUE; 106 107 if (leftValue == FALSE && rightValue == FALSE) 108 return FALSE; 109 else 110 return UNKNOWN; 111 } 112 113 public String evalString(QueryContext context) 114 throws SQLException 115 { 116 switch (evalBoolean(context)) { 117 case TRUE: 118 return "1"; 119 case FALSE: 120 return "0"; 121 default: 122 return null; 123 } 124 } 125 126 public String toString() 127 { 128 return "(" + _left + " OR " + _right + ")"; 129 } 130 } 131 | Popular Tags |