Package com.alibaba.druid.sql.dialect.oracle.visitor

Examples of com.alibaba.druid.sql.dialect.oracle.visitor.OracleOutputVisitor


        String sql = "select * from ge_rms_company start with comcode = '00' connect by nocycle prior comcode = uppercomcode";
        SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, JdbcUtils.ORACLE);
        List<SQLStatement> stmtList = parser.parseStatementList();
        StringBuilder out = new StringBuilder();
        // PrettyFormat use default : true
        SQLASTOutputVisitor visitor = new OracleOutputVisitor(out);
        for(SQLStatement statement : stmtList) {
            statement.accept(visitor);
        }

        String expectResult = "SELECT *\nFROM ge_rms_company\nSTART WITH comcode = '00'\nCONNECT BY NOCYCLE PRIOR comcode = uppercomcode;\n";
        Assert.assertEquals(expectResult, out.toString());

        out.setLength(0);
        visitor = new OracleOutputVisitor(out);
        // setPrettyFormat : false
        visitor.setPrettyFormat(false);
        for(SQLStatement statement : stmtList) {
            statement.accept(visitor);
        }
        expectResult = "SELECT * FROM ge_rms_company START WITH comcode = '00' CONNECT BY NOCYCLE PRIOR comcode = uppercomcode";
        Assert.assertEquals(expectResult, out.toString());
View Full Code Here


        SQLStatementParser parser = new OracleStatementParser(sql);
        List<SQLStatement> stmtList = parser.parseStatementList(); //

        // 将AST通过visitor输出
        StringBuilder out = new StringBuilder();
        OracleOutputVisitor visitor = new OracleOutputVisitor(out);

        for (SQLStatement stmt : stmtList) {
            stmt.accept(visitor);
            out.append(";");
        }
View Full Code Here

        System.out.println(text);
    }

    private String output(List<SQLStatement> stmtList) {
        StringBuilder out = new StringBuilder();
        OracleOutputVisitor visitor = new OracleOutputVisitor(out);

        for (SQLStatement stmt : stmtList) {
            stmt.accept(visitor);
        }
View Full Code Here

import com.alibaba.druid.sql.dialect.oracle.visitor.OracleOutputVisitor;

public class OracleTest extends TestCase {
  protected String output(List<SQLStatement> stmtList) {
    StringBuilder out = new StringBuilder();
    OracleOutputVisitor visitor = new OracleOutputVisitor(out);

    for (SQLStatement stmt : stmtList) {
      stmt.accept(visitor);
    }
View Full Code Here

public class TestUtils {

    public static String outputOracle(List<SQLStatement> stmtList) {
        StringBuilder out = new StringBuilder();
        OracleOutputVisitor visitor = new OracleOutputVisitor(out);

        for (SQLStatement stmt : stmtList) {
            stmt.accept(visitor);
        }
View Full Code Here

        output(statementList);
    }

    private void output(List<SQLStatement> stmtList) {
        StringBuilder out = new StringBuilder();
        OracleOutputVisitor visitor = new OracleOutputVisitor(out);

        for (SQLStatement stmt : stmtList) {
            stmt.accept(visitor);
            visitor.println();
        }

        System.out.println(out.toString());
    }
View Full Code Here

        System.out.println(millis);
    }

    private String merge() {
        StringBuilder out = new StringBuilder();
        OracleOutputVisitor visitor = new OracleOutputVisitor(out) {

            public boolean visit(SQLInListExpr x) {
                x.getExpr().accept(this);

                if (x.isNot()) {
                    print(" NOT IN (##)");
                } else {
                    print(" IN (##)");
                }
                return false;
            }
        };

        OracleStatementParser parser = new OracleStatementParser(sql);
        List<SQLStatement> statementList = parser.parseStatementList();
        for (SQLStatement statement : statementList) {
            statement.accept(visitor);
            visitor.println();
        }

        return out.toString();
    }
View Full Code Here

        System.out.println("MySql\t" + millis);
    }

    private String execOracle(String sql) {
        StringBuilder out = new StringBuilder();
        OracleOutputVisitor visitor = new OracleOutputVisitor(out);

        OracleStatementParser parser = new OracleStatementParser(sql);
        List<SQLStatement> statementList = parser.parseStatementList();
        for (SQLStatement statement : statementList) {
            statement.accept(visitor);
            visitor.println();
        }

        return out.toString();
    }
View Full Code Here

    public void test_1() throws Exception {
        String sql = "SELECT /*mark for picman*/ * FROM WP_ALBUM WHERE MEMBER_ID = ? AND ID IN (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

        StringBuilder out = new StringBuilder();
        OracleOutputVisitor visitor = new OracleOutputVisitor(out);
        OracleStatementParser parser = new OracleStatementParser(sql);
        List<SQLStatement> statementList = parser.parseStatementList();
        for (SQLStatement statement : statementList) {
            statement.accept(visitor);
            visitor.print(";");
            visitor.println();
        }

        System.out.println(out.toString());
    }
View Full Code Here

        Assert.assertEquals(true, visitor.getColumns().contains(new Column("employee", "salary")));
        Assert.assertEquals(true, visitor.getColumns().contains(new Column("employee", "depId")));
        Assert.assertEquals(true, visitor.getColumns().contains(new Column("department", "id")));

        StringBuilder buf = new StringBuilder();
        OracleOutputVisitor outputVisitor = new OracleOutputVisitor(buf);
        stmt.accept(outputVisitor);
        Assert.assertEquals("SELECT e.salary\nFROM employee e\n\tJOIN department d\nWHERE e.depId = d.id;\n",
                            buf.toString());

    }
View Full Code Here

TOP

Related Classes of com.alibaba.druid.sql.dialect.oracle.visitor.OracleOutputVisitor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.