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.ValueArray; 14 15 public class ExpressionList extends Expression { 16 17 private Expression[] list; 18 19 public ExpressionList(Expression[] list) { 20 this.list = list; 21 } 22 23 public Value getValue(Session session) throws SQLException { 24 Value[] v = new Value[list.length]; 25 for(int i=0; i<list.length; i++) { 26 v[i] = list[i].getValue(session); 27 } 28 return ValueArray.get(v); 29 } 30 31 public int getType() { 32 return Value.ARRAY; 33 } 34 35 public void mapColumns(ColumnResolver resolver, int level) throws SQLException { 36 for(int i=0; i<list.length; i++) { 37 list[i].mapColumns(resolver, level); 38 } 39 } 40 41 public Expression optimize(Session session) throws SQLException { 42 boolean allConst = true; 43 for(int i=0; i<list.length; i++) { 44 Expression e = list[i].optimize(session); 45 if(!e.isConstant()) { 46 allConst = false; 47 } 48 list[i] = e; 49 } 50 if(allConst) { 51 return ValueExpression.get(getValue(session)); 52 } 53 return this; 54 } 55 56 public void setEvaluatable(TableFilter tableFilter, boolean b) { 57 for(int i=0; i<list.length; i++) { 58 list[i].setEvaluatable(tableFilter, b); 59 } 60 } 61 62 public int getScale() { 63 return 0; 64 } 65 66 public long getPrecision() { 67 return 0; 68 } 69 70 public String getSQL() { 71 StringBuffer buff = new StringBuffer (); 72 buff.append('('); 73 for (int i = 0; i < list.length; i++) { 74 if (i > 0) { 75 buff.append(", "); 76 } 77 buff.append(list[i].getSQL()); 78 } 79 buff.append(')'); 80 return buff.toString(); 81 } 82 83 public void updateAggregate(Session session) throws SQLException { 84 for (int i = 0; i < list.length; i++) { 85 list[i].updateAggregate(session); 86 } 87 } 88 89 public boolean isEverything(ExpressionVisitor visitor) { 90 for (int i = 0; i < list.length; i++) { 91 if(!list[i].isEverything(visitor)) { 92 return false; 93 } 94 } 95 return true; 96 } 97 98 public int getCost() { 99 int cost = 1; 100 for(int i=0; i<list.length; i++) { 101 cost += list[i].getCost(); 102 } 103 return cost; 104 } 105 106 } 107 | Popular Tags |