Package org.jboss.dna.sequencer.ddl.node

Examples of org.jboss.dna.sequencer.ddl.node.AstNode


       
        boolean success = parser.parse(content, rootNode);
       
        assertEquals(true, success);
        assertEquals(1, rootNode.getChildCount());
        AstNode childNode = rootNode.getChildren().get(0);
        assertTrue(hasMixinType(childNode.getProperty(JcrLexicon.MIXIN_TYPES), TYPE_CREATE_MATERIALIZED_VIEW_STATEMENT));
    }
View Full Code Here


       
        boolean success = parser.parse(content, rootNode);
       
        assertEquals(true, success);
        assertEquals(1, rootNode.getChildCount());
        AstNode childNode = rootNode.getChildren().get(0);
        assertTrue(hasMixinType(childNode.getProperty(JcrLexicon.MIXIN_TYPES), TYPE_CREATE_MATERIALIZED_VIEW_LOG_STATEMENT));
    }
View Full Code Here

    @Before
    public void beforeEach() {
        parsers = new DdlParsers();
        //ddlTest = this.getClass().getClassLoader().getResource("createTablesTest.ddl");
        context = new ExecutionContext();
        rootNode = new AstNode(context.getValueFactories().getNameFactory().create("root_node"));
        nodeFactory = new AstNodeFactory(context);
    }
View Full Code Here

        assertEquals(0, parser.getProblems().size());

        // assertTrue(parser.getProblems().get(0).getMessage().startsWith("Tokens were found at line"));

        assertEquals(3, rootNode.getChildCount()); // TWO STATEMENTS + UNKNOWN statement
        AstNode tableNode = rootNode.getChildren().get(0);
        assertTrue(hasMixinType(tableNode.getProperty(JcrLexicon.MIXIN_TYPES), TYPE_CREATE_TABLE_STATEMENT));
        assertEquals("myTable", tableNode.getName().getString());
        assertEquals(3, tableNode.getChildCount());
    }
View Full Code Here

        parser.parse(content, rootNode);

        printNodeChildren(rootNode);

        assertEquals(2, rootNode.getChildCount()); // ONE TABLE + ONE PROBLEM
        AstNode tableNode = rootNode.getChildren().get(0);
        assertTrue(hasMixinType(tableNode.getProperty(JcrLexicon.MIXIN_TYPES), TYPE_CREATE_TABLE_STATEMENT));
        assertEquals("myTable", tableNode.getName().getString());
        assertEquals(4, tableNode.getChildCount()); // 2 Columns, 1 Constraint + 1 Problem

        assertEquals(1, parser.getProblems().size());

        assertTrue(parser.getProblems().get(0).getMessage().startsWith("The following unused tokens were found"));
    }
View Full Code Here

        String content = "ALTER TABLE table_name_14 ADD CONSTRAINT fk_name FOREIGN KEY (ref_col_name) REFERENCES ref_table_name(ref_table_column_name);";

        parser.parse(content, rootNode);

        assertEquals(1, rootNode.getChildCount());
        AstNode alterTableNode = rootNode.getChildren().get(0);
        assertTrue(hasMixinType(alterTableNode.getProperty(JcrLexicon.MIXIN_TYPES), TYPE_ALTER_TABLE_STATEMENT));
        assertEquals("table_name_14", alterTableNode.getName().getString());
        assertEquals(1, alterTableNode.getChildCount());
        AstNode constraintNode = alterTableNode.getChild(0); // / FOREIGN KEY
        assertEquals("fk_name", constraintNode.getName().getString());
        assertEquals(DdlConstants.FOREIGN_KEY, constraintNode.getProperty(CONSTRAINT_TYPE).getFirstValue());
        assertTrue(hasMixinType(constraintNode.getProperty(JcrLexicon.MIXIN_TYPES), TYPE_ADD_TABLE_CONSTRAINT_DEFINITION));

        // Expect 3 references: COLUMN REFERENCE for this table, External Table reference and column reference in external table
        assertEquals(3, constraintNode.getChildCount());
    }
View Full Code Here

        // CASE 1
        String content = "PARTID VARCHAR (255) NOT NULL DEFAULT '12345'";

        DdlTokenStream tokens = getTokens(content);

        AstNode tableNode = parser.nodeFactory().node("PARTID", rootNode, TYPE_CREATE_TABLE_STATEMENT, rootNode);
        parser.setRootNode(rootNode);
        parser.parseColumnDefinition(tokens, tableNode, false);

        assertEquals(1, tableNode.getChildCount());
        AstNode column = tableNode.getChildren().get(0);
        assertEquals("VARCHAR", column.getProperty(DATATYPE_NAME).getFirstValue());
        assertEquals(255, column.getProperty(DATATYPE_LENGTH).getFirstValue());
        assertTrue(column.getProperty(DATATYPE_PRECISION) == null);
        assertEquals("NOT NULL", column.getProperty(NULLABLE).getFirstValue());
        assertEquals(DEFAULT_ID_LITERAL, column.getProperty(DEFAULT_OPTION).getFirstValue());
        assertEquals("'12345'", column.getProperty(DEFAULT_VALUE).getFirstValue());

        tableNode.removeAllChildren();

        // CASE 2
        content = "PARTID CHARACTER (255) NULL DEFAULT (12345)";

        tokens = getTokens(content);

        parser.parseColumnDefinition(tokens, tableNode, false);

        assertEquals(1, tableNode.getChildCount());
        column = tableNode.getChildren().get(0);
        assertEquals("CHARACTER", column.getProperty(DATATYPE_NAME).getFirstValue());
        assertEquals(255, column.getProperty(DATATYPE_LENGTH).getFirstValue());
        assertTrue(column.getProperty(DATATYPE_PRECISION) == null);
        assertEquals("NULL", column.getProperty(NULLABLE).getFirstValue());
        assertEquals(DEFAULT_ID_LITERAL, column.getProperty(DEFAULT_OPTION).getFirstValue());
        assertEquals("12345", column.getProperty(DEFAULT_VALUE).getFirstValue());

        tableNode.removeAllChildren();

        // CASE 3
        content = "PARTID DECIMAL (6, 2) DEFAULT (6.213)";

        tokens = getTokens(content);

        parser.parseColumnDefinition(tokens, tableNode, false);

        assertEquals(1, tableNode.getChildCount());
        column = tableNode.getChildren().get(0);
        assertEquals("DECIMAL", column.getProperty(DATATYPE_NAME).getFirstValue());
        assertEquals(6, column.getProperty(DATATYPE_PRECISION).getFirstValue());
        assertEquals(2, column.getProperty(DATATYPE_SCALE).getFirstValue());
        assertTrue(column.getProperty(DATATYPE_LENGTH) == null);
        assertEquals(DEFAULT_ID_LITERAL, column.getProperty(DEFAULT_OPTION).getFirstValue());
        assertEquals("6.213", column.getProperty(DEFAULT_VALUE).getFirstValue());
    }
View Full Code Here

        DdlTokenStream tokens = getTokens(content);

        parser.setRootNode(rootNode);

        AstNode result = parser.parseCreateTableStatement(tokens, rootNode);

        assertEquals(1, rootNode.getChildCount());
        AstNode tableNode = rootNode.getChildren().get(0);
        assertThat(result, is(tableNode));
        assertEquals("MY_TABLE_A", tableNode.getName().getString());
        assertEquals(3, tableNode.getChildCount()); // 2 COLUMNS + 1 Table Option
        AstNode column = tableNode.getChildren().get(0);
        assertEquals("PARTID", column.getName().getString());
        assertEquals("VARCHAR", column.getProperty(DATATYPE_NAME).getFirstValue());
        assertEquals(255, column.getProperty(DATATYPE_LENGTH).getFirstValue());
        assertTrue(column.getProperty(DATATYPE_PRECISION) == null);

        List<AstNode> tableOptions = parser.nodeFactory().getChildrenForType(tableNode, TYPE_STATEMENT_OPTION);
        assertEquals(1, tableOptions.size());
        assertEquals("ON COMMIT DELETE ROWS", tableOptions.get(0).getProperty(VALUE).getFirstValue());
View Full Code Here

        // CASE 1 ON COMMIT PRESERVE ROWS
        String content = "ON COMMIT PRESERVE ROWS";

        DdlTokenStream tokens = getTokens(content);

        AstNode tableNode = parser.nodeFactory().node("PARTS_COLOR", rootNode, TYPE_CREATE_TABLE_STATEMENT);

        parser.parseNextCreateTableOption(tokens, tableNode);

        List<AstNode> options = parser.nodeFactory().getChildrenForType(tableNode, TYPE_STATEMENT_OPTION);
        assertEquals(1, options.size());

        assertEquals(content, options.get(0).getProperty(VALUE).getFirstValue());

        tableNode.removeAllChildren();

        // CASE 2 ON COMMIT DELETE ROWS
        content = "ON COMMIT DELETE ROWS";
        tokens = getTokens(content);

        parser.parseNextCreateTableOption(tokens, tableNode);

        options = parser.nodeFactory().getChildrenForType(tableNode, TYPE_STATEMENT_OPTION);
        assertEquals(1, options.size());

        assertEquals(content, options.get(0).getProperty(VALUE).getFirstValue());

        tableNode.removeAllChildren();

        // CASE 3 ON COMMIT DROP
        content = "ON COMMIT DROP";
        tokens = getTokens(content);

        parser.parseNextCreateTableOption(tokens, tableNode);

        options = parser.nodeFactory().getChildrenForType(tableNode, TYPE_STATEMENT_OPTION);
        assertEquals(1, options.size());

        assertEquals(content, options.get(0).getProperty(VALUE).getFirstValue());

        tableNode.removeAllChildren();
    }
View Full Code Here

        // CASE 1: INITIALLY DEFERRED
        String content = "INITIALLY DEFERRED";

        DdlTokenStream tokens = getTokens(content);

        AstNode constraintNode = parser.nodeFactory().node("FK_1", rootNode, TYPE_TABLE_CONSTRAINT);

        parser.parseConstraintAttributes(tokens, constraintNode);

        assertEquals(1, constraintNode.getChildCount()); // ONE CHILD

        List<AstNode> attributes = parser.nodeFactory().getChildrenForType(constraintNode, CONSTRAINT_ATTRIBUTE_TYPE);
        assertEquals(1, attributes.size());
        assertEquals(content, attributes.get(0).getProperty(PROPERTY_VALUE).getFirstValue());

        constraintNode.removeAllChildren();

        // CASE 2: INITIALLY IMMEDIATE DEFERRABLE
        content = "INITIALLY IMMEDIATE DEFERRABLE";
        tokens = getTokens(content);

        parser.parseConstraintAttributes(tokens, constraintNode);

        assertEquals(2, constraintNode.getChildCount()); // TWO CHILDREN

        attributes = parser.nodeFactory().getChildrenForType(constraintNode, CONSTRAINT_ATTRIBUTE_TYPE);
        assertEquals(2, attributes.size());
        assertEquals("INITIALLY IMMEDIATE", attributes.get(0).getProperty(PROPERTY_VALUE).getFirstValue());
        assertEquals("DEFERRABLE", attributes.get(1).getProperty(PROPERTY_VALUE).getFirstValue());

        constraintNode.removeAllChildren();

        // CASE 3: NOT DEFERRABLE INITIALLY IMMEDIATE
        content = "NOT DEFERRABLE INITIALLY IMMEDIATE";
        tokens = getTokens(content);

        parser.parseConstraintAttributes(tokens, constraintNode);

        assertEquals(2, constraintNode.getChildCount()); // 2 Children

        attributes = parser.nodeFactory().getChildrenForType(constraintNode, CONSTRAINT_ATTRIBUTE_TYPE);
        assertEquals(2, attributes.size());
        assertEquals("NOT DEFERRABLE", attributes.get(0).getProperty(PROPERTY_VALUE).getFirstValue());
        assertEquals("INITIALLY IMMEDIATE", attributes.get(1).getProperty(PROPERTY_VALUE).getFirstValue());

        constraintNode.removeAllChildren();

    }
View Full Code Here

TOP

Related Classes of org.jboss.dna.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.