1 module hunt.sql.ast.SQLParameter; 2 3 import hunt.sql.visitor.SQLASTVisitor; 4 5 import hunt.collection; 6 import hunt.sql.ast.SQLName; 7 import hunt.sql.ast.SQLDataType; 8 import hunt.sql.ast.SQLExpr; 9 import hunt.sql.ast.SQLObjectImpl; 10 import hunt.sql.ast.SQLObjectWithDataType; 11 12 13 14 public class SQLParameter : SQLObjectImpl , SQLObjectWithDataType { 15 private SQLName name; 16 private SQLDataType dataType; 17 private SQLExpr defaultValue; 18 private ParameterType paramType; 19 private bool noCopy = false; 20 private bool constant = false; 21 private SQLName cursorName; 22 private List!SQLParameter cursorParameters ; 23 private bool order; 24 private bool map; 25 private bool member; 26 27 this() 28 { 29 cursorParameters = new ArrayList!SQLParameter(); 30 } 31 public SQLExpr getDefaultValue() { 32 return defaultValue; 33 } 34 35 public void setDefaultValue(SQLExpr deaultValue) { 36 if (deaultValue !is null) { 37 deaultValue.setParent(this); 38 } 39 this.defaultValue = deaultValue; 40 } 41 42 public SQLName getName() { 43 return name; 44 } 45 46 public void setName(SQLName name) { 47 if (name !is null) { 48 name.setParent(this); 49 } 50 this.name = name; 51 } 52 53 public SQLDataType getDataType() { 54 return dataType; 55 } 56 57 public void setDataType(SQLDataType dataType) { 58 if (dataType !is null) { 59 dataType.setParent(this); 60 } 61 this.dataType = dataType; 62 } 63 64 public ParameterType getParamType() { 65 return paramType; 66 } 67 68 public void setParamType(ParameterType paramType) { 69 this.paramType = paramType; 70 } 71 72 public override void accept0(SQLASTVisitor visitor) { 73 if (visitor.visit(this)) { 74 acceptChild(visitor, name); 75 acceptChild(visitor, dataType); 76 acceptChild(visitor, defaultValue); 77 } 78 visitor.endVisit(this); 79 } 80 81 public static struct ParameterType { 82 enum ParameterType DEFAULT = ParameterType("DEFAULT"); // 83 enum ParameterType IN = ParameterType("IN"); // in 84 enum ParameterType OUT = ParameterType("OUT"); // out_p 85 enum ParameterType INOUT = ParameterType("INOUT");// inout 86 87 private string _name; 88 89 this(string name) 90 { 91 _name = name; 92 } 93 94 @property string name() 95 { 96 return _name; 97 } 98 99 bool opEquals(const ParameterType h) nothrow { 100 return _name == h._name ; 101 } 102 103 bool opEquals(ref const ParameterType h) nothrow { 104 return _name == h._name ; 105 } 106 } 107 108 public bool isNoCopy() { 109 return noCopy; 110 } 111 112 public void setNoCopy(bool noCopy) { 113 this.noCopy = noCopy; 114 } 115 116 public bool isConstant() { 117 return constant; 118 } 119 120 public void setConstant(bool constant) { 121 this.constant = constant; 122 } 123 124 public List!SQLParameter getCursorParameters() { 125 return cursorParameters; 126 } 127 128 public SQLName getCursorName() { 129 return cursorName; 130 } 131 132 public void setCursorName(SQLName cursorName) { 133 if (cursorName !is null) { 134 cursorName.setParent(this); 135 } 136 this.cursorName = cursorName; 137 } 138 139 public override SQLParameter clone() { 140 SQLParameter x = new SQLParameter(); 141 if (name !is null) { 142 x.setName(name.clone()); 143 } 144 if (dataType !is null) { 145 x.setDataType(dataType.clone()); 146 } 147 if (defaultValue !is null) { 148 x.setDefaultValue(defaultValue.clone()); 149 } 150 x.paramType = paramType; 151 x.noCopy = noCopy; 152 x.constant = constant; 153 x.order = order; 154 x.map = map; 155 if (cursorName !is null) { 156 x.setCursorName(cursorName.clone()); 157 } 158 foreach(SQLParameter p ; cursorParameters) { 159 SQLParameter p2 = p.clone(); 160 p2.setParent(x); 161 x.cursorParameters.add(p2); 162 } 163 return x; 164 } 165 166 public bool isOrder() { 167 return order; 168 } 169 170 public void setOrder(bool order) { 171 this.order = order; 172 } 173 174 public bool isMap() { 175 return map; 176 } 177 178 public void setMap(bool map) { 179 this.map = map; 180 } 181 182 public bool isMember() { 183 return member; 184 } 185 186 public void setMember(bool member) { 187 this.member = member; 188 } 189 }