Package org.modeshape.sequencer.ddl.node

Examples of org.modeshape.sequencer.ddl.node.AstNode


    protected AstNode parseDropStatement( DdlTokenStream tokens,
                                          AstNode parentNode ) throws ParsingException {
        assert tokens != null;
        assert parentNode != null;

        AstNode dropNode = null;

        if (tokens.matches(StatementStartPhrases.STMT_DROP_TABLE)) {
            markStartOfStatement(tokens);

            // DROP TABLE [ schema. ]table [ CASCADE CONSTRAINTS ] [ PURGE ] ;

            tokens.consume(DROP, TABLE);

            String name = parseName(tokens);
            dropNode = nodeFactory().node(name, parentNode, TYPE_DROP_TABLE_STATEMENT);

            if (tokens.canConsume("CASCADE", "CONSTRAINTTS")) {
                dropNode.setProperty(DROP_BEHAVIOR, "CASCADE CONSTRAINTS");
            }

            if (tokens.canConsume("PURGE")) {
                AstNode optionNode = nodeFactory().node(DROP_OPTION, dropNode, TYPE_STATEMENT_OPTION);
                optionNode.setProperty(StandardDdlLexicon.VALUE, "PURGE");
            }

            markEndOfStatement(tokens, dropNode);

            return dropNode;
View Full Code Here


        assert tokens != null;
        assert parentNode != null;

        markStartOfStatement(tokens);
        tokens.consume(STMT_CREATE_JAVA);
        AstNode result = nodeFactory().node(getStatementTypeName(STMT_CREATE_JAVA), parentNode, TYPE_CREATE_JAVA_STATEMENT);

        // We want to parse until we find a terminator AND all brackets are matched.

        // Assume we start with open parenthesis '{', then we can count on walking through ALL tokens until we find the close
        // parenthesis '}'. If there are intermediate parenthesis, we can count on them being pairs.
View Full Code Here

        assert stmt_start_phrase != null && stmt_start_phrase.length > 0;
        assert parentNode != null;

        markStartOfStatement(tokens);
        tokens.consume(stmt_start_phrase);
        AstNode result = nodeFactory().node(getStatementTypeName(stmt_start_phrase), parentNode, mixinType);

        parseUntilFwdSlash(tokens, false);

        consumeSlash(tokens);
View Full Code Here

    }

    @Test
    public void shouldParseUnresolvedTableReference() {
        final String content = "CREATE TRIGGER ON missingTable INSTEAD OF DELETE AS FOR EACH ROW DELETE FROM x WHERE foo = 'bar';";
        final AstNode triggerNode = this.parser.parse(getTokens(content), this.rootNode);
        assertThat(triggerNode.getName(), is("missingTable"));
        assertMixinType(triggerNode, TeiidDdlLexicon.CreateTrigger.STATEMENT);
        assertProperty(triggerNode, TeiidDdlLexicon.CreateTrigger.INSTEAD_OF, DdlConstants.DELETE);
        assertProperty(triggerNode, TeiidDdlLexicon.CreateTrigger.ATOMIC, true);
        assertThat(triggerNode.getProperty(TeiidDdlLexicon.CreateTrigger.TABLE_REFERENCE), is(nullValue()));
    }
View Full Code Here

    }

    @Test
    public void shouldParseCreateTriggerDelete() {
        final String content = "CREATE TRIGGER ON foo INSTEAD OF DELETE AS FOR EACH ROW DELETE FROM x WHERE foo = 'bar';";
        final AstNode triggerNode = this.parser.parse(getTokens(content), this.rootNode);
        assertThat(triggerNode.getName(), is("foo"));
        assertMixinType(triggerNode, TeiidDdlLexicon.CreateTrigger.STATEMENT);
        assertProperty(triggerNode, TeiidDdlLexicon.CreateTrigger.INSTEAD_OF, DdlConstants.DELETE);
        assertProperty(triggerNode, TeiidDdlLexicon.CreateTrigger.ATOMIC, true);
        assertProperty(triggerNode, TeiidDdlLexicon.CreateTrigger.TABLE_REFERENCE, this.tableRefNode);

        // row actions
        assertThat(triggerNode.getChildCount(), is(1));
        assertThat(triggerNode.getChild(0).getName(), is(TeiidDdlLexicon.CreateTrigger.ROW_ACTION));
        assertMixinType(triggerNode.getChild(0), TeiidDdlLexicon.CreateTrigger.TRIGGER_ROW_ACTION);
        assertProperty(triggerNode.getChild(0), TeiidDdlLexicon.CreateTrigger.ACTION, "DELETE FROM x WHERE foo = 'bar';");
    }
View Full Code Here

    }

    @Test
    public void shouldParseCreateTriggerDeleteWithAtomicBeginBlockOneStatement() {
        final String content = "CREATE TRIGGER ON foo INSTEAD OF DELETE AS FOR EACH ROW BEGIN ATOMIC DELETE FROM x WHERE foo = 'bar'; END";
        final AstNode triggerNode = this.parser.parse(getTokens(content), this.rootNode);
        assertThat(triggerNode.getName(), is("foo"));
        assertMixinType(triggerNode, TeiidDdlLexicon.CreateTrigger.STATEMENT);
        assertProperty(triggerNode, TeiidDdlLexicon.CreateTrigger.INSTEAD_OF, DdlConstants.DELETE);
        assertProperty(triggerNode, TeiidDdlLexicon.CreateTrigger.ATOMIC, true);
        assertProperty(triggerNode, TeiidDdlLexicon.CreateTrigger.TABLE_REFERENCE, this.tableRefNode);

        // row actions
        assertThat(triggerNode.getChildCount(), is(1));
        assertThat(triggerNode.getChild(0).getName(), is(TeiidDdlLexicon.CreateTrigger.ROW_ACTION));
        assertMixinType(triggerNode.getChild(0), TeiidDdlLexicon.CreateTrigger.TRIGGER_ROW_ACTION);
        assertProperty(triggerNode.getChild(0), TeiidDdlLexicon.CreateTrigger.ACTION, "DELETE FROM x WHERE foo = 'bar';");
    }
View Full Code Here

    }

    @Test
    public void shouldParseCreateTriggerDeleteWithBeginBlockOneStatement() {
        final String content = "CREATE TRIGGER ON foo INSTEAD OF DELETE AS FOR EACH ROW BEGIN DELETE FROM x WHERE foo = 'bar'; END";
        final AstNode triggerNode = this.parser.parse(getTokens(content), this.rootNode);
        assertThat(triggerNode.getName(), is("foo"));
        assertMixinType(triggerNode, TeiidDdlLexicon.CreateTrigger.STATEMENT);
        assertProperty(triggerNode, TeiidDdlLexicon.CreateTrigger.INSTEAD_OF, DdlConstants.DELETE);
        assertProperty(triggerNode, TeiidDdlLexicon.CreateTrigger.ATOMIC, false);
        assertProperty(triggerNode, TeiidDdlLexicon.CreateTrigger.TABLE_REFERENCE, this.tableRefNode);

        // row actions
        assertThat(triggerNode.getChildCount(), is(1));
        assertThat(triggerNode.getChild(0).getName(), is(TeiidDdlLexicon.CreateTrigger.ROW_ACTION));
        assertMixinType(triggerNode.getChild(0), TeiidDdlLexicon.CreateTrigger.TRIGGER_ROW_ACTION);
        assertProperty(triggerNode.getChild(0), TeiidDdlLexicon.CreateTrigger.ACTION, "DELETE FROM x WHERE foo = 'bar';");
    }
View Full Code Here

    }

    @Test
    public void shouldParseCreateTriggerDeleteWithBeginBlockTwoStatements() {
        final String content = "CREATE TRIGGER ON foo INSTEAD OF DELETE AS FOR EACH ROW BEGIN DELETE FROM x WHERE foo = 'bar'; DELETE FROM x WHERE bar = 'foo'; END";
        final AstNode triggerNode = this.parser.parse(getTokens(content), this.rootNode);
        assertThat(triggerNode.getName(), is("foo"));
        assertMixinType(triggerNode, TeiidDdlLexicon.CreateTrigger.STATEMENT);
        assertProperty(triggerNode, TeiidDdlLexicon.CreateTrigger.INSTEAD_OF, DdlConstants.DELETE);
        assertProperty(triggerNode, TeiidDdlLexicon.CreateTrigger.ATOMIC, false);
        assertProperty(triggerNode, TeiidDdlLexicon.CreateTrigger.TABLE_REFERENCE, this.tableRefNode);

        // row actions
        assertThat(triggerNode.getChildCount(), is(2));
        assertThat(triggerNode.getChild(0).getName(), is(TeiidDdlLexicon.CreateTrigger.ROW_ACTION));
        assertMixinType(triggerNode.getChild(0), TeiidDdlLexicon.CreateTrigger.TRIGGER_ROW_ACTION);
        assertProperty(triggerNode.getChild(0), TeiidDdlLexicon.CreateTrigger.ACTION, "DELETE FROM x WHERE foo = 'bar';");
        assertThat(triggerNode.getChild(1).getName(), is(TeiidDdlLexicon.CreateTrigger.ROW_ACTION));
        assertMixinType(triggerNode.getChild(1), TeiidDdlLexicon.CreateTrigger.TRIGGER_ROW_ACTION);
        assertProperty(triggerNode.getChild(1), TeiidDdlLexicon.CreateTrigger.ACTION, "DELETE FROM x WHERE bar = 'foo';");
    }
View Full Code Here

    }

    @Test
    public void shouldParseCreateTriggerInsert() {
        final String content = "CREATE TRIGGER ON foo INSTEAD OF INSERT AS FOR EACH ROW insert into g1 (e1, e2) values (1, 'trig');";
        final AstNode triggerNode = this.parser.parse(getTokens(content), this.rootNode);
        assertThat(triggerNode.getName(), is("foo"));
        assertMixinType(triggerNode, TeiidDdlLexicon.CreateTrigger.STATEMENT);
        assertProperty(triggerNode, TeiidDdlLexicon.CreateTrigger.INSTEAD_OF, DdlConstants.INSERT);
        assertProperty(triggerNode, TeiidDdlLexicon.CreateTrigger.ATOMIC, true);
        assertProperty(triggerNode, TeiidDdlLexicon.CreateTrigger.TABLE_REFERENCE, this.tableRefNode);

        // row actions
        assertThat(triggerNode.getChildCount(), is(1));
        assertThat(triggerNode.getChild(0).getName(), is(TeiidDdlLexicon.CreateTrigger.ROW_ACTION));
        assertMixinType(triggerNode.getChild(0), TeiidDdlLexicon.CreateTrigger.TRIGGER_ROW_ACTION);
        assertProperty(triggerNode.getChild(0),
                       TeiidDdlLexicon.CreateTrigger.ACTION,
                       "insert into g1 (e1, e2) values (1, 'trig');");
    }
View Full Code Here

    }

    @Test
    public void shouldParseCreateTriggerInsertWithAtomicBeginBlockOneStatement() {
        final String content = "CREATE TRIGGER ON foo INSTEAD OF INSERT AS FOR EACH ROW BEGIN ATOMIC insert into g1 (e1, e2) values (1, 'trig'); END";
        final AstNode triggerNode = this.parser.parse(getTokens(content), this.rootNode);
        assertThat(triggerNode.getName(), is("foo"));
        assertMixinType(triggerNode, TeiidDdlLexicon.CreateTrigger.STATEMENT);
        assertProperty(triggerNode, TeiidDdlLexicon.CreateTrigger.INSTEAD_OF, DdlConstants.INSERT);
        assertProperty(triggerNode, TeiidDdlLexicon.CreateTrigger.ATOMIC, true);
        assertProperty(triggerNode, TeiidDdlLexicon.CreateTrigger.TABLE_REFERENCE, this.tableRefNode);

        // row actions
        assertThat(triggerNode.getChildCount(), is(1));
        assertThat(triggerNode.getChild(0).getName(), is(TeiidDdlLexicon.CreateTrigger.ROW_ACTION));
        assertMixinType(triggerNode.getChild(0), TeiidDdlLexicon.CreateTrigger.TRIGGER_ROW_ACTION);
        assertProperty(triggerNode.getChild(0),
                       TeiidDdlLexicon.CreateTrigger.ACTION,
                       "insert into g1 (e1, e2) values (1, 'trig');");
    }
View Full Code Here

TOP

Related Classes of org.modeshape.sequencer.ddl.node.AstNode

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.