|
| 1 | +/*- |
| 2 | + * #%L |
| 3 | + * JSQLParser library |
| 4 | + * %% |
| 5 | + * Copyright (C) 2004 - 2025 JSQLParser |
| 6 | + * %% |
| 7 | + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 |
| 8 | + * #L% |
| 9 | + */ |
| 10 | +package net.sf.jsqlparser.statement.select; |
| 11 | + |
| 12 | +import net.sf.jsqlparser.expression.Expression; |
| 13 | + |
| 14 | +import java.io.Serializable; |
| 15 | +import java.util.List; |
| 16 | + |
| 17 | +public class WithFunctionDeclaration implements Serializable { |
| 18 | + private String functionName; |
| 19 | + private List<WithFunctionParameter> parameters; |
| 20 | + private String returnType; |
| 21 | + private Expression returnExpression; |
| 22 | + |
| 23 | + public WithFunctionDeclaration() {} |
| 24 | + |
| 25 | + public WithFunctionDeclaration(String functionName, List<WithFunctionParameter> parameters, |
| 26 | + String returnType, Expression returnExpression) { |
| 27 | + this.functionName = functionName; |
| 28 | + this.parameters = parameters; |
| 29 | + this.returnType = returnType; |
| 30 | + this.returnExpression = returnExpression; |
| 31 | + } |
| 32 | + |
| 33 | + public String getFunctionName() { |
| 34 | + return functionName; |
| 35 | + } |
| 36 | + |
| 37 | + public void setFunctionName(String functionName) { |
| 38 | + this.functionName = functionName; |
| 39 | + } |
| 40 | + |
| 41 | + public List<WithFunctionParameter> getParameters() { |
| 42 | + return parameters; |
| 43 | + } |
| 44 | + |
| 45 | + public void setParameters(List<WithFunctionParameter> parameters) { |
| 46 | + this.parameters = parameters; |
| 47 | + } |
| 48 | + |
| 49 | + public String getReturnType() { |
| 50 | + return returnType; |
| 51 | + } |
| 52 | + |
| 53 | + public void setReturnType(String returnType) { |
| 54 | + this.returnType = returnType; |
| 55 | + } |
| 56 | + |
| 57 | + public Expression getReturnExpression() { |
| 58 | + return returnExpression; |
| 59 | + } |
| 60 | + |
| 61 | + public void setReturnExpression(Expression returnExpression) { |
| 62 | + this.returnExpression = returnExpression; |
| 63 | + } |
| 64 | + |
| 65 | + public WithFunctionDeclaration withFunctionName(String functionName) { |
| 66 | + this.setFunctionName(functionName); |
| 67 | + return this; |
| 68 | + } |
| 69 | + |
| 70 | + public WithFunctionDeclaration withParameters(List<WithFunctionParameter> parameters) { |
| 71 | + this.setParameters(parameters); |
| 72 | + return this; |
| 73 | + } |
| 74 | + |
| 75 | + public WithFunctionDeclaration withReturnType(String returnType) { |
| 76 | + this.setReturnType(returnType); |
| 77 | + return this; |
| 78 | + } |
| 79 | + |
| 80 | + public WithFunctionDeclaration withReturnExpression(Expression returnExpression) { |
| 81 | + this.setReturnExpression(returnExpression); |
| 82 | + return this; |
| 83 | + } |
| 84 | + |
| 85 | + public StringBuilder appendTo(StringBuilder builder) { |
| 86 | + builder |
| 87 | + .append("FUNCTION ") |
| 88 | + .append(functionName) |
| 89 | + .append("("); |
| 90 | + for (int i = 0; parameters != null && i < parameters.size(); i++) { |
| 91 | + if (i > 0) { |
| 92 | + builder.append(", "); |
| 93 | + } |
| 94 | + parameters.get(i).appendTo(builder); |
| 95 | + } |
| 96 | + return builder |
| 97 | + .append(") RETURNS ") |
| 98 | + .append(returnType) |
| 99 | + .append(" RETURN ") |
| 100 | + .append(returnExpression); |
| 101 | + } |
| 102 | + |
| 103 | + @Override |
| 104 | + public String toString() { |
| 105 | + return appendTo(new StringBuilder()).toString(); |
| 106 | + } |
| 107 | +} |
0 commit comments