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

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


                         + ", PART_ID int NOT NULL DEFAULT (1000)"
                         + ", FOREIGN KEY FK_SUPPLIER REFERENCES SUPPLIERS (SUPPLIER_ID, SUPPLIER_NAME) );";

        DdlTokenStream tokens = getTokens(content);

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

        parser.parseColumnsAndConstraints(tokens, tableNode);

        assertEquals(4, tableNode.getChildCount());

        AstNode column = parser.nodeFactory().getChildforNameAndType(tableNode, "PART_COLOR", TYPE_COLUMN_DEFINITION);
        assertNotNull(column);
        assertEquals("VARCHAR", column.getProperty(DATATYPE_NAME).getFirstValue());
        assertEquals(255, column.getProperty(DATATYPE_LENGTH).getFirstValue());
        assertTrue(column.getProperty(DATATYPE_PRECISION) == null);
        assertTrue(column.getProperty(DATATYPE_SCALE) == null);
        assertEquals("NOT NULL", column.getProperty(NULLABLE).getFirstValue());
        assertEquals(DEFAULT_ID_LITERAL, column.getProperty(DEFAULT_OPTION).getFirstValue());
        assertEquals("BLUE", column.getProperty(DEFAULT_VALUE).getFirstValue());

        AstNode foreignKeyNode = parser.nodeFactory().getChildforNameAndType(tableNode, "FK_SUPPLIER", TYPE_TABLE_CONSTRAINT);

        assertEquals(DdlConstants.FOREIGN_KEY, foreignKeyNode.getProperty(CONSTRAINT_TYPE).getFirstValue());
        assertEquals(3, foreignKeyNode.getChildCount()); // 2 COLUMN REFERENCES + 1 TABLE REFERENCE
    }
View Full Code Here


        String tableName = "MY_TABLE_A";
        String content = "CREATE LOCAL TEMPORARY TABLE MY_TABLE_A (PARTID VARCHAR (255) NOT NULL DEFAULT (100),  -- COLUMN 1 COMMENT with comma \nPARTCOLOR INTEGER NOT NULL);";

        DdlTokenStream tokens = getTokens(content);

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

        assertEquals(1, rootNode.getChildCount());
        AstNode tableNode = rootNode.getChildren().get(0);
        assertThat(result, is(tableNode));
        assertEquals(tableName, tableNode.getName().getString());
        assertEquals(2, 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("100", column.getProperty(DEFAULT_VALUE).getFirstValue());
    }
View Full Code Here

        String tableName = "MY_TABLE_B";
        String content = "CREATE TABLE MY_TABLE_B (PARTID VARCHAR (255), PRIMARY KEY (C1, C2), \nPARTCOLOR INTEGER NOT NULL, CONSTRAINT PK_A PRIMARY KEY (FILE_UID) );";

        DdlTokenStream tokens = getTokens(content);

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

        assertEquals(1, rootNode.getChildCount());
        AstNode tableNode = rootNode.getChildren().get(0);
        assertThat(result, is(tableNode));
        assertEquals(tableName, tableNode.getName().getString());
        assertEquals(4, tableNode.getChildCount()); // 2 COLUMNs + 2 PRIMARY KEY CONSTRAINTS (BOGUS)
        AstNode column1 = tableNode.getChildren().get(0);
        assertEquals("VARCHAR", column1.getProperty(DATATYPE_NAME).getFirstValue());
        assertEquals(255, column1.getProperty(DATATYPE_LENGTH).getFirstValue());
        assertTrue(column1.getProperty(DATATYPE_PRECISION) == null);
    }
View Full Code Here

        String tableName = "table_name_22_B";
        String content = "CREATE TABLE table_name_22_B ( column_name_1 VARCHAR(255) CONSTRAINT pk_name UNIQUE INITIALLY IMMEDIATE);";

        DdlTokenStream tokens = getTokens(content);

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

        assertEquals(1, rootNode.getChildCount()); // COLUMN + PRIMARY KEY CONSTRAINT
        AstNode tableNode = rootNode.getChildren().get(0);
        assertThat(result, is(tableNode));
        assertEquals(tableName, tableNode.getName().getString());
        assertEquals(2, tableNode.getChildCount()); // 1 COLUMN & 1 CONSTRAINT
        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);
    }
View Full Code Here

        boolean success = parser.parse(content, rootNode);

        assertThat(rootNode.getChildCount(), is(2));
        assertThat(success, is(true));

        AstNode viewNode = rootNode.getChildren().get(0);
        assertEquals("new_product_view", viewNode.getName().getString());
        assertEquals(0, viewNode.getChildCount());
    }
View Full Code Here

        boolean success = parser.parse(content, rootNode);

        assertThat(rootNode.getChildCount(), is(1));
        assertThat(success, is(true));

        AstNode viewNode = rootNode.getChildren().get(0);
        assertEquals("CORPDATA.EMP_YEARSOFSERVICE", viewNode.getName().getString());
        assertEquals(2, viewNode.getChildCount()); // TWO COLUMN REFERENCES
        AstNode columnRef = viewNode.getChildren().get(0);
        assertEquals("LASTNAME", columnRef.getName().getString());
    }
View Full Code Here

    private AstNode parent;

    @Before
    public void beforeEach() {
        context = new ExecutionContext();
        node = new AstNode(name("node1"));
    }
View Full Code Here

    }

    @Test
    public void shouldCreatePlanNodeWithNameAndNoParent() {
        Name name = name("something");
        node = new AstNode(name);
        assertThat(node.getName(), is(name));
        assertThat(node.getParent(), is(nullValue()));
    }
View Full Code Here

    }

    @Test
    public void shouldCreatePlanNodeWithNameAndParent() {
        Name name = name("something");
        parent = new AstNode(name("parent"));
        node = new AstNode(parent, name);
        assertThat(node.getName(), is(name));
        assertThat(node.getParent(), is(sameInstance(parent)));
        assertThat(parent.getFirstChild(), is(sameInstance(node)));
        assertThat(parent.getChildCount(), is(1));
    }
View Full Code Here

        assertThat(parent.getChildCount(), is(1));
    }

    @Test
    public void shouldGetFirstChildAndLastChildWithOneChild() {
        parent = new AstNode(name("parent"));
        node = new AstNode(parent, name("child"));
        assertThat(parent.getFirstChild(), is(sameInstance(node)));
        assertThat(parent.getLastChild(), is(sameInstance(node)));
    }
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.