1 /* 2 * Copyright 2015-2018 HuntLabs.cn 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 module hunt.sql.ast.statement.SQLCreateFunctionStatement; 17 18 import hunt.sql.ast; 19 import hunt.sql.ast.expr.SQLPropertyExpr; 20 import hunt.sql.visitor.SQLASTVisitor; 21 import hunt.sql.ast.statement.SQLCreateStatement; 22 23 import hunt.collection; 24 25 /** 26 * Created by wenshao on 23/05/2017. 27 */ 28 public class SQLCreateFunctionStatement : SQLStatementImpl , SQLCreateStatement, SQLObjectWithDataType { 29 private SQLName definer; 30 31 private bool create = true; 32 private bool orReplace; 33 private SQLName name; 34 private SQLStatement block; 35 private List!SQLParameter parameters; 36 37 // for oracle 38 private string javaCallSpec; 39 40 private SQLName authid; 41 42 SQLDataType returnDataType; 43 44 // for mysql 45 46 private string comment; 47 private bool deterministic = false; 48 private bool parallelEnable; 49 private bool aggregate; 50 private SQLName using; 51 private bool pipelined; 52 private bool resultCache; 53 private string wrappedSource; 54 55 this() 56 { 57 parameters = new ArrayList!SQLParameter(); 58 } 59 60 override public SQLCreateFunctionStatement clone() { 61 SQLCreateFunctionStatement x = new SQLCreateFunctionStatement(); 62 63 if (definer !is null) { 64 x.setDefiner(definer.clone()); 65 } 66 x.create = create; 67 x.orReplace = orReplace; 68 if (name !is null) { 69 x.setName(name.clone()); 70 } 71 if (block !is null) { 72 x.setBlock(block.clone()); 73 } 74 foreach (SQLParameter p ; parameters) { 75 SQLParameter p2 = p.clone(); 76 p2.setParent(x); 77 x.parameters.add(p2); 78 } 79 x.javaCallSpec = javaCallSpec; 80 if (authid !is null) { 81 x.setAuthid(authid.clone()); 82 } 83 if (returnDataType !is null) { 84 x.setReturnDataType(returnDataType.clone()); 85 } 86 x.comment = comment; 87 x.deterministic = deterministic; 88 x.pipelined = pipelined; 89 90 return x; 91 } 92 93 override 94 public void accept0(SQLASTVisitor visitor) { 95 if (visitor.visit(this)) { 96 acceptChild(visitor, definer); 97 acceptChild(visitor, name); 98 acceptChild!SQLParameter(visitor, parameters); 99 acceptChild(visitor, returnDataType); 100 acceptChild(visitor, block); 101 } 102 visitor.endVisit(this); 103 } 104 105 public List!SQLParameter getParameters() { 106 return parameters; 107 } 108 109 public void setParameters(List!SQLParameter parameters) { 110 this.parameters = parameters; 111 } 112 113 public SQLName getName() { 114 return name; 115 } 116 117 public void setName(SQLName name) { 118 this.name = name; 119 } 120 121 public SQLStatement getBlock() { 122 return block; 123 } 124 125 public void setBlock(SQLStatement block) { 126 if (block !is null) { 127 block.setParent(this); 128 } 129 this.block = block; 130 } 131 132 public SQLName getAuthid() { 133 return authid; 134 } 135 136 public void setAuthid(SQLName authid) { 137 if (authid !is null) { 138 authid.setParent(this); 139 } 140 this.authid = authid; 141 } 142 143 public bool isOrReplace() { 144 return orReplace; 145 } 146 147 public void setOrReplace(bool orReplace) { 148 this.orReplace = orReplace; 149 } 150 151 public SQLName getDefiner() { 152 return definer; 153 } 154 155 public void setDefiner(SQLName definer) { 156 this.definer = definer; 157 } 158 159 public bool isCreate() { 160 return create; 161 } 162 163 public void setCreate(bool create) { 164 this.create = create; 165 } 166 167 public string getJavaCallSpec() { 168 return javaCallSpec; 169 } 170 171 public void setJavaCallSpec(string javaCallSpec) { 172 this.javaCallSpec = javaCallSpec; 173 } 174 175 public SQLDataType getReturnDataType() { 176 return returnDataType; 177 } 178 179 public void setReturnDataType(SQLDataType returnDataType) { 180 if (returnDataType !is null) { 181 returnDataType.setParent(this); 182 } 183 this.returnDataType = returnDataType; 184 } 185 186 public string getComment() { 187 return comment; 188 } 189 190 public void setComment(string comment) { 191 this.comment = comment; 192 } 193 194 public bool isDeterministic() { 195 return deterministic; 196 } 197 198 public void setDeterministic(bool deterministic) { 199 this.deterministic = deterministic; 200 } 201 202 public string getSchema() { 203 SQLName name = getName(); 204 if (name is null) { 205 return null; 206 } 207 208 if (cast(SQLPropertyExpr)(name) !is null ) { 209 return (cast(SQLPropertyExpr) name).getOwnernName(); 210 } 211 212 return null; 213 } 214 215 override 216 public SQLDataType getDataType() { 217 return returnDataType; 218 } 219 220 override 221 public void setDataType(SQLDataType dataType) { 222 this.setReturnDataType(dataType); 223 } 224 225 226 public bool isParallelEnable() { 227 return parallelEnable; 228 } 229 230 public void setParallelEnable(bool parallel_enable) { 231 this.parallelEnable = parallel_enable; 232 } 233 234 public bool isAggregate() { 235 return aggregate; 236 } 237 238 public void setAggregate(bool aggregate) { 239 this.aggregate = aggregate; 240 } 241 242 public SQLName getUsing() { 243 return using; 244 } 245 246 public void setUsing(SQLName using) { 247 this.using = using; 248 } 249 250 public bool isPipelined() { 251 return pipelined; 252 } 253 254 public void setPipelined(bool pipelined) { 255 this.pipelined = pipelined; 256 } 257 258 public bool isResultCache() { 259 return resultCache; 260 } 261 262 public void setResultCache(bool resultCache) { 263 this.resultCache = resultCache; 264 } 265 266 public string getWrappedSource() { 267 return wrappedSource; 268 } 269 270 public void setWrappedSource(string wrappedSource) { 271 this.wrappedSource = wrappedSource; 272 } 273 }