1 5 package org.h2.expression; 6 7 import java.sql.SQLException ; 8 9 import org.h2.engine.Session; 10 import org.h2.table.ColumnResolver; 11 import org.h2.table.TableFilter; 12 import org.h2.value.Value; 13 import org.h2.value.ValueNull; 14 15 public class ConditionNot extends Condition { 16 17 private Expression condition; 18 19 public ConditionNot(Expression condition) { 20 this.condition = condition; 21 } 22 23 public void createIndexConditions(TableFilter filter) { 24 } 26 27 public Value getValue(Session session) throws SQLException { 28 Value v = condition.getValue(session); 29 if(v == ValueNull.INSTANCE) { 30 return v; 31 } 32 return v.convertTo(Value.BOOLEAN).negate(); 33 } 34 35 public void mapColumns(ColumnResolver resolver, int level) throws SQLException { 36 condition.mapColumns(resolver, level); 37 } 38 39 public Expression optimize(Session session) throws SQLException { 40 Expression expr = condition.optimize(session); 42 if(expr.isConstant()) { 43 Value v = expr.getValue(session); 44 if(v == ValueNull.INSTANCE) { 45 return ValueExpression.NULL; 46 } 47 return ValueExpression.get(v.convertTo(Value.BOOLEAN).negate()); 48 } 49 condition = expr; 50 return this; 51 } 52 53 public void setEvaluatable(TableFilter tableFilter, boolean b) { 54 condition.setEvaluatable(tableFilter, b); 55 } 56 57 public String getSQL() { 58 return "(NOT " + condition.getSQL() + ")"; 59 } 60 61 public void updateAggregate(Session session) throws SQLException { 62 condition.updateAggregate(session); 63 } 64 65 public void addFilterConditions(TableFilter filter, boolean outerJoin) { 66 if(outerJoin) { 67 return; 72 } 73 super.addFilterConditions(filter, outerJoin); 74 } 75 76 public boolean isEverything(ExpressionVisitor visitor) { 77 return condition.isEverything(visitor); 78 } 79 80 public int getCost() { 81 return condition.getCost(); 82 } 83 84 } 85 | Popular Tags |