sql-parser

  • k3_457683
    了解作者
  • 1.2MB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-05-01 04:26
    上传日期
sql-parser
sql-parser-master.zip
内容介绍
/* * Copyright 1999-2018 Alibaba Group Holding Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.lz.druid.sql.visitor; import java.io.IOException; import java.io.InputStream; import java.io.Reader; import java.math.BigDecimal; import java.math.BigInteger; import java.sql.Blob; import java.sql.Clob; import java.sql.NClob; import java.text.SimpleDateFormat; import java.util.*; import com.lz.druid.sql.SQLUtils; import com.lz.druid.sql.ast.*; import com.lz.druid.sql.ast.expr.*; import com.lz.druid.sql.ast.statement.*; import com.lz.druid.sql.ast.expr.*; import com.lz.druid.sql.ast.statement.*; import com.lz.druid.sql.ast.statement.SQLCreateTriggerStatement.TriggerType; import com.lz.druid.sql.ast.statement.SQLInsertStatement.ValuesClause; import com.lz.druid.sql.ast.statement.SQLJoinTableSource.JoinType; import com.lz.druid.sql.ast.statement.SQLMergeStatement.MergeInsertClause; import com.lz.druid.sql.ast.statement.SQLMergeStatement.MergeUpdateClause; import com.lz.druid.sql.dialect.oracle.ast.OracleSegmentAttributes; import com.lz.druid.sql.dialect.oracle.ast.expr.OracleCursorExpr; import com.lz.druid.sql.dialect.oracle.ast.expr.OracleDatetimeExpr; import com.lz.druid.sql.dialect.oracle.ast.stmt.OracleCreatePackageStatement; import com.lz.druid.sql.dialect.oracle.ast.stmt.OracleForStatement; import com.lz.druid.sql.dialect.oracle.ast.stmt.OracleSelectPivot; import com.lz.druid.sql.dialect.oracle.parser.OracleFunctionDataType; import com.lz.druid.sql.dialect.oracle.parser.OracleProcedureDataType; import com.lz.druid.util.JdbcConstants; import com.lz.druid.util.JdbcUtils; import com.lz.druid.sql.SQLUtils; import com.lz.druid.sql.ast.*; import com.lz.druid.sql.dialect.oracle.ast.OracleSegmentAttributes; import com.lz.druid.sql.dialect.oracle.ast.expr.OracleCursorExpr; import com.lz.druid.sql.dialect.oracle.ast.expr.OracleDatetimeExpr; import com.lz.druid.sql.dialect.oracle.ast.stmt.OracleCreatePackageStatement; import com.lz.druid.sql.dialect.oracle.ast.stmt.OracleForStatement; import com.lz.druid.sql.dialect.oracle.ast.stmt.OracleSelectPivot; import com.lz.druid.sql.dialect.oracle.parser.OracleFunctionDataType; import com.lz.druid.sql.dialect.oracle.parser.OracleProcedureDataType; import java.io.IOException; import java.io.InputStream; import java.io.Reader; import java.sql.Blob; import java.sql.Clob; import java.sql.NClob; import java.text.SimpleDateFormat; import java.util.*; import static com.lz.druid.util.Utils.getBoolean; public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements ParameterizedVisitor, PrintableVisitor { public static Boolean defaultPrintStatementAfterSemi; static { try { defaultPrintStatementAfterSemi = getBoolean(System.getProperties(), "druid.sql.output.printStatementAfterSemi"); // compatible for early versions } catch (Throwable ex) { // skip } } protected final Appendable appender; protected int indentCount = 0; protected boolean ucase = true; protected int selectListNumberOfLine = 5; protected boolean groupItemSingleLine = false; protected List<Object> parameters; protected List<Object> inputParameters; protected Set<String> tables; protected String table; // for improved protected boolean exportTables = false; protected String dbType; protected Map<String, String> tableMapping; protected int replaceCount; protected boolean parameterizedMergeInList = false; protected boolean parameterizedQuesUnMergeInList = false; protected boolean parameterized = false; protected boolean shardingSupport = false; protected transient int lines = 0; protected Boolean printStatementAfterSemi = defaultPrintStatementAfterSemi; { features |= VisitorFeature.OutputPrettyFormat.mask; } public SQLASTOutputVisitor(Appendable appender){ this.appender = appender; } public SQLASTOutputVisitor(Appendable appender, String dbType){ this.appender = appender; this.dbType = dbType; } public SQLASTOutputVisitor(Appendable appender, boolean parameterized){ this.appender = appender; this.config(VisitorFeature.OutputParameterized, parameterized); this.config(VisitorFeature.OutputParameterizedQuesUnMergeInList, parameterizedQuesUnMergeInList); } public int getReplaceCount() { return this.replaceCount; } public void incrementReplaceCunt() { replaceCount++; } public void addTableMapping(String srcTable, String destTable) { if (tableMapping == null) { tableMapping = new HashMap<String, String>(); } if (srcTable.indexOf('.') >= 0) { SQLExpr expr = SQLUtils.toSQLExpr(srcTable, dbType); if (expr instanceof SQLPropertyExpr) { srcTable = ((SQLPropertyExpr) expr).simplify().toString(); } } else { srcTable = SQLUtils.normalize(srcTable); } tableMapping.put(srcTable, destTable); } public void setTableMapping(Map<String, String> tableMapping) { this.tableMapping = tableMapping; } public List<Object> getParameters() { if (parameters == null) { parameters = new ArrayList<Object>(); } return parameters; } public boolean isDesensitize() { return isEnabled(VisitorFeature.OutputDesensitize); } public void setDesensitize(boolean desensitize) { config(VisitorFeature.OutputDesensitize, desensitize); } public Set<String> getTables() { if (this.table != null && this.tables == null) { return Collections.singleton(this.table); } return this.tables; } @Deprecated public void setParameters(List<Object> parameters) { if (parameters != null && parameters.size() > 0) { this.inputParameters = parameters; } else { this.parameters = parameters; } } public void setInputParameters(List<Object> parameters) { this.inputParameters = parameters; } /** * * @since 1.1.5 */ public void setOutputParameters(List<Object> parameters) { this.parameters = parameters; } public int getIndentCount() { return indentCount; } public Appendable getAppender() { return appender; } public boolean isPrettyFormat() { return isEnabled(VisitorFeature.OutputPrettyFormat); } public void setPrettyFormat(boolean prettyFormat) { config(VisitorFeature.OutputPrettyFormat, prettyFormat); } public void decrementIndent() { this.indentCount--; } public void incrementIndent() { this.indentCount++; } public boolean isParameterized() { return isEnabled(VisitorFeature.OutputParameterized); } public void setParameterized(boolean parameterized) { config(VisitorFeature.OutputParameterized, parameterized); } public boolean isParameterizedMergeInList() { return parameterizedMergeInList; } public void setParameterizedMergeInList(boolean parameterizedMergeInList) { this.parameterizedMergeInList = parameterizedMergeInList; } public boolean isParameterizedQuesUnMergeInList() { return isEnabled(VisitorFeature.OutputParameterizedQuesUnMergeInList); } public void setPa
评论