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.dialect.postgresql.visitor.PGExportParameterVisitor; 17 18 19 import hunt.collection; 20 21 import hunt.sql.ast.SQLOrderBy; 22 import hunt.sql.ast.expr.SQLBetweenExpr; 23 import hunt.sql.ast.expr.SQLBinaryOpExpr; 24 import hunt.sql.ast.expr.SQLInListExpr; 25 import hunt.sql.ast.expr.SQLMethodInvokeExpr; 26 import hunt.sql.ast.statement.SQLSelectGroupByClause; 27 import hunt.sql.ast.statement.SQLSelectItem; 28 import hunt.sql.visitor.ExportParameterVisitor; 29 import hunt.sql.visitor.ExportParameterVisitorUtils; 30 import hunt.sql.dialect.postgresql.visitor.PGOutputVisitor; 31 import hunt.String; 32 import hunt.sql.visitor.SQLASTOutputVisitor; 33 import hunt.util.Appendable; 34 import hunt.util.Common; 35 import hunt.text; 36 37 public class PGExportParameterVisitor : PGOutputVisitor , ExportParameterVisitor { 38 39 alias visit = PGOutputVisitor.visit; 40 alias endVisit = PGOutputVisitor.endVisit; 41 /** 42 * true= if require parameterized sql output 43 */ 44 private bool requireParameterizedOutput; 45 46 override public bool isParameterizedMergeInList() 47 { 48 return super.isParameterizedMergeInList(); 49 } 50 override public void setParameterizedMergeInList(bool flag) 51 { 52 return super.setParameterizedMergeInList(flag); 53 } 54 55 public this( List!(Object) parameters, Appendable appender, bool wantParameterizedOutput){ 56 super(appender, true); 57 this.parameters = parameters; 58 this.requireParameterizedOutput = wantParameterizedOutput; 59 } 60 61 public this() { 62 this(new ArrayList!(Object)()); 63 } 64 65 public this( List!(Object) parameters){ 66 this(parameters,new StringBuilder(),false); 67 } 68 69 public this( Appendable appender) { 70 this(new ArrayList!(Object)(),appender,true); 71 } 72 73 override public List!(Object) getParameters() { 74 return parameters; 75 } 76 77 override 78 public bool visit(SQLSelectItem x) { 79 if(requireParameterizedOutput){ 80 return (super).visit(x); 81 } 82 return false; 83 } 84 85 override 86 public bool visit(SQLOrderBy x) { 87 if(requireParameterizedOutput){ 88 return (super).visit(x); 89 } 90 return false; 91 } 92 93 override 94 public bool visit(SQLSelectGroupByClause x) { 95 if(requireParameterizedOutput){ 96 return (super).visit(x); 97 } 98 return false; 99 } 100 101 override 102 public bool visit(SQLMethodInvokeExpr x) { 103 if(requireParameterizedOutput){ 104 return (super).visit(x); 105 } 106 ExportParameterVisitorUtils.exportParamterAndAccept(this.parameters, x.getParameters()); 107 108 return true; 109 } 110 111 override 112 public bool visit(SQLInListExpr x) { 113 if(requireParameterizedOutput){ 114 return (super).visit(x); 115 } 116 ExportParameterVisitorUtils.exportParamterAndAccept(this.parameters, x.getTargetList()); 117 118 return true; 119 } 120 121 override 122 public bool visit(SQLBetweenExpr x) { 123 if(requireParameterizedOutput){ 124 return (super).visit(x); 125 } 126 ExportParameterVisitorUtils.exportParameter(this.parameters, x); 127 return true; 128 } 129 130 override public bool visit(SQLBinaryOpExpr x) { 131 if(requireParameterizedOutput){ 132 return (super).visit(x); 133 } 134 ExportParameterVisitorUtils.exportParameter(this.parameters, x); 135 return true; 136 } 137 138 }