1 5 package org.h2.expression; 6 7 import java.sql.SQLException ; 8 9 import org.h2.engine.Session; 10 import org.h2.message.Message; 11 import org.h2.table.ColumnResolver; 12 import org.h2.table.TableFilter; 13 import org.h2.value.Value; 14 15 18 public class Parameter extends Expression implements ParameterInterface { 19 20 private Value value; 21 private int index; 22 23 public Parameter(int index) { 24 this.index = index; 25 } 26 27 public String getSQL() { 28 return "?" + (index + 1); 29 } 30 31 public void setValue(Value v) { 32 this.value = v; 33 } 34 35 public Value getParamValue() throws SQLException { 36 return value == null ? null : value; 37 } 38 39 public Value getValue(Session session) throws SQLException { 40 return getParamValue(); 41 } 42 43 public int getType() { 44 return value == null ? Value.UNKNOWN : value.getType(); 45 } 46 47 public void mapColumns(ColumnResolver resolver, int level) { 48 } 50 51 public void checkMapped() { 52 } 54 55 public void checkSet() throws SQLException { 56 if (value == null) { 57 throw Message.getSQLException(Message.PARAMETER_NOT_SET_1, String.valueOf(index + 1)); 58 } 59 } 60 61 public Expression optimize(Session session) { 62 return this; 63 } 64 65 public boolean isConstant() { 66 return value != null; 67 } 68 69 public void setEvaluatable(TableFilter tableFilter, boolean b) { 70 } 72 73 public int getScale() { 74 return value == null ? 0 : value.getScale(); 75 } 76 77 public long getPrecision() { 78 return value == null ? 0 : value.getPrecision(); 79 } 80 81 public void updateAggregate(Session session) { 82 } 84 85 public boolean isEverything(ExpressionVisitor visitor) { 86 switch(visitor.type) { 87 case ExpressionVisitor.OPTIMIZABLE_MIN_MAX_COUNT_ALL: 88 return true; 89 case ExpressionVisitor.DETERMINISTIC: 90 case ExpressionVisitor.READONLY: 91 return true; 92 case ExpressionVisitor.INDEPENDENT: 93 return value != null; 94 case ExpressionVisitor.EVALUATABLE: 95 return true; 97 case ExpressionVisitor.SET_MAX_DATA_MODIFICATION_ID: 98 return true; 100 default: 101 throw Message.getInternalError("type="+visitor.type); 102 } 103 } 104 105 public int getCost() { 106 return 0; 107 } 108 109 } 110 | Popular Tags |