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.schema.Sequence; 12 import org.h2.table.ColumnResolver; 13 import org.h2.table.TableFilter; 14 import org.h2.value.Value; 15 import org.h2.value.ValueInt; 16 import org.h2.value.ValueLong; 17 18 public class SequenceValue extends Expression { 19 20 private Sequence sequence; 21 22 public SequenceValue(Sequence sequence) { 23 this.sequence = sequence; 24 } 25 26 public Value getValue(Session session) throws SQLException { 27 long value = sequence.getNext(); 28 session.setLastIdentity(value); 29 return ValueLong.get(value); 30 } 31 32 public int getType() { 33 return Value.LONG; 34 } 35 36 public void mapColumns(ColumnResolver resolver, int level) { 37 } 39 40 public void checkMapped() { 41 } 43 44 public Expression optimize(Session session) { 45 return this; 46 } 47 48 public void setEvaluatable(TableFilter tableFilter, boolean b) { 49 } 51 52 public int getScale() { 53 return 0; 54 } 55 56 public long getPrecision() { 57 return ValueInt.PRECISION; 58 } 59 60 public String getSQL() { 61 return "(NEXT VALUE FOR " + sequence.getSQL() +")"; 62 } 63 64 public void updateAggregate(Session session) { 65 } 67 68 public boolean isEverything(ExpressionVisitor visitor) { 69 switch(visitor.type) { 70 case ExpressionVisitor.OPTIMIZABLE_MIN_MAX_COUNT_ALL: 71 return true; 72 case ExpressionVisitor.DETERMINISTIC: 73 case ExpressionVisitor.READONLY: 74 return false; 75 case ExpressionVisitor.INDEPENDENT: 76 return false; 77 case ExpressionVisitor.EVALUATABLE: 78 return true; 79 case ExpressionVisitor.SET_MAX_DATA_MODIFICATION_ID: 80 visitor.addDataModificationId(sequence.getModificationId()); 81 return true; 82 default: 83 throw Message.getInternalError("type="+visitor.type); 84 } 85 } 86 87 public int getCost() { 88 return 1; 89 } 90 91 } 92 | Popular Tags |