Search in sources :

Example 1 with OracleHint

use of net.sf.jsqlparser.expression.OracleHint in project JSqlParser by JSQLParser.

the class TablesNamesFinderTest method testOracleHint.

@Test
public void testOracleHint() throws JSQLParserException {
    String sql = "select --+ HINT\ncol2 from mytable";
    Select select = (Select) CCJSqlParserUtil.parse(sql);
    final OracleHint[] holder = new OracleHint[1];
    TablesNamesFinder tablesNamesFinder = new TablesNamesFinder() {

        @Override
        public void visit(OracleHint hint) {
            super.visit(hint);
            holder[0] = hint;
        }
    };
    tablesNamesFinder.getTableList(select);
    assertNull(holder[0]);
}
Also used : Select(net.sf.jsqlparser.statement.select.Select) OracleHint(net.sf.jsqlparser.expression.OracleHint) Test(org.junit.Test) CCJSqlParserManagerTest(net.sf.jsqlparser.test.simpleparsing.CCJSqlParserManagerTest)

Example 2 with OracleHint

use of net.sf.jsqlparser.expression.OracleHint in project JSqlParser by JSQLParser.

the class TestUtils method assertOracleHintExists.

public static void assertOracleHintExists(String sql, boolean assertDeparser, String... hints) throws JSQLParserException {
    if (assertDeparser) {
        assertSqlCanBeParsedAndDeparsed(sql, true);
    }
    Select stmt = (Select) CCJSqlParserUtil.parse(sql);
    if (stmt.getSelectBody() instanceof PlainSelect) {
        PlainSelect ps = (PlainSelect) stmt.getSelectBody();
        OracleHint hint = ps.getOracleHint();
        assertNotNull(hint);
        assertEquals(hints[0], hint.getValue());
    } else {
        if (stmt.getSelectBody() instanceof SetOperationList) {
            SetOperationList setop = (SetOperationList) stmt.getSelectBody();
            for (int i = 0; i < setop.getSelects().size(); i++) {
                PlainSelect pselect = (PlainSelect) setop.getSelects().get(i);
                OracleHint hint = pselect.getOracleHint();
                if (hints[i] == null) {
                    Assert.assertNull(hint);
                } else {
                    assertNotNull(hint);
                    assertEquals(hints[i], hint.getValue());
                }
            }
        }
    }
}
Also used : SetOperationList(net.sf.jsqlparser.statement.select.SetOperationList) PlainSelect(net.sf.jsqlparser.statement.select.PlainSelect) Select(net.sf.jsqlparser.statement.select.Select) PlainSelect(net.sf.jsqlparser.statement.select.PlainSelect) OracleHint(net.sf.jsqlparser.expression.OracleHint) OracleHint(net.sf.jsqlparser.expression.OracleHint)

Aggregations

OracleHint (net.sf.jsqlparser.expression.OracleHint)2 Select (net.sf.jsqlparser.statement.select.Select)2 PlainSelect (net.sf.jsqlparser.statement.select.PlainSelect)1 SetOperationList (net.sf.jsqlparser.statement.select.SetOperationList)1 CCJSqlParserManagerTest (net.sf.jsqlparser.test.simpleparsing.CCJSqlParserManagerTest)1 Test (org.junit.Test)1