1 module hunt.sql.ast.expr.SQLSequenceExpr; 2 import hunt.sql.ast.SQLExprImpl; 3 import hunt.sql.ast.SQLName; 4 import hunt.sql.visitor.SQLASTVisitor; 5 import hunt.collection; 6 import std.uni; 7 import hunt.sql.ast.SQLObject; 8 9 public class SQLSequenceExpr : SQLExprImpl { 10 11 private SQLName sequence; 12 private Function _function; 13 14 public this(){ 15 16 } 17 18 public this(SQLName sequence, Function function_p){ 19 this.sequence = sequence; 20 this._function = function_p; 21 } 22 23 override public SQLSequenceExpr clone() { 24 SQLSequenceExpr x = new SQLSequenceExpr(); 25 if (sequence !is null) { 26 x.setSequence(sequence.clone()); 27 } 28 x._function = _function; 29 return x; 30 } 31 32 protected override void accept0(SQLASTVisitor visitor) { 33 if (visitor.visit(this)) { 34 acceptChild(visitor, sequence); 35 } 36 visitor.endVisit(this); 37 } 38 39 public static struct Function { 40 enum Function NextVal = Function("NEXTVAL"); 41 enum Function CurrVal = Function("CURRVAL"); 42 enum Function PrevVal = Function("PREVVAL"); 43 44 public string name; 45 public string name_lcase; 46 47 private this(string name){ 48 this.name = name; 49 this.name_lcase = toLower(name); 50 } 51 52 bool opEquals(const Function h) nothrow { 53 return name == h.name ; 54 } 55 56 bool opEquals(ref const Function h) nothrow { 57 return name == h.name ; 58 } 59 } 60 61 override public List!SQLObject getChildren() { 62 return Collections.singletonList!SQLObject(sequence); 63 } 64 65 public SQLName getSequence() { 66 return sequence; 67 } 68 69 public void setSequence(SQLName sequence) { 70 this.sequence = sequence; 71 } 72 73 public Function getFunction() { 74 return _function; 75 } 76 77 public void setFunction(Function function_p) { 78 this._function = function_p; 79 } 80 81 public override size_t toHash() @trusted nothrow { 82 int prime = 31; 83 size_t result = 1; 84 result = prime * result + hashOf(_function); 85 result = prime * result + ((sequence is null) ? 0 : (cast(Object)sequence).toHash()); 86 return result; 87 } 88 89 public override bool opEquals(Object obj) { 90 if (this is obj) return true; 91 if (obj is null) return false; 92 if (typeid(SQLSequenceExpr) != typeid(obj)) return false; 93 SQLSequenceExpr other = cast(SQLSequenceExpr) obj; 94 if (_function != other._function) return false; 95 if (sequence is null) { 96 if (other.sequence !is null) return false; 97 } else if (!(cast(Object)(sequence)).opEquals(cast(Object)(other.sequence))) return false; 98 return true; 99 } 100 101 }