Package org.modeshape.sequencer.ddl.node

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


        String PK_COL = "customerfamilyhistoryid";
        String content = "CREATE TABLE CustomerFamilyHistory (";
        content += PK_COL
                   + " numeric(10) CONSTRAINT customerfamilyhistoryid_pk PRIMARY KEY, firstname varchar(50) NOT NULL, lastname varchar(50) NOT NULL, age numeric(3), sibling varchar(20), customerid numeric(7) NOT NULL);";
        DdlTokenStream tokens = getTokens(content);
        AstNode result = parser.parseCreateTableStatement(tokens, rootNode);
        assertThat(result, is(notNullValue()));

        // test to make sure there is a table node
        assertEquals(1, rootNode.getChildCount()); // TABLE
        AstNode tableNode = rootNode.getChild(0);

        // test to make sure all columns and primary key constraint are children of the table node
        assertEquals(7, tableNode.getChildCount()); // 6 Columns + 1 Constraint

        // find constraint
        boolean foundConstraint = false;
        for (AstNode kid : tableNode.getChildren()) {
            Object value = kid.getProperty(CONSTRAINT_TYPE);

            if (value != null) {
                assertFalse(foundConstraint); // make sure no other constraint found
                foundConstraint = true;

                assertEquals(value, PRIMARY_KEY); // test for primary key

                // make sure a child node pointing to the column is found
                assertEquals(1, kid.getChildCount());
                AstNode child = kid.getChild(0);
                assertTrue(hasMixinType(child, TYPE_COLUMN_REFERENCE));
                assertEquals(PK_COL, child.getName());
            }
        }
    }
View Full Code Here


        String tableName = "table_name_24_B";
        String content = "CREATE TABLE table_name_24_B ( REALMUID     NUMERIC(10) NOT NULL CONSTRAINT PK_AUTHREALMS UNIQUE (columnA, columnB));";

        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());
        assertEquals(2, tableNode.getChildCount()); // 1 COLUMN & 1 CONSTRAINT
        AstNode column = tableNode.getChildren().get(0);
        assertEquals("NUMERIC", column.getProperty(DATATYPE_NAME));
        assertEquals(10, column.getProperty(DATATYPE_PRECISION));
        assertTrue(column.getProperty(DATATYPE_LENGTH) == null);

        AstNode prim_key = tableNode.getChildren().get(1);
        assertEquals(2, prim_key.getChildCount()); // 2 column references
        AstNode columnRef = prim_key.getChildren().get(0);
        assertEquals("columnA", columnRef.getName());
    }
View Full Code Here

        String content = "CREATE VIEW new_product_view" + " AS SELECT color, quantity FROM new_product WHERE color = 'RED'"
                         + " GRANT select ON new_product_view TO hr;";

        assertScoreAndParse(content, null, 2);

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

        String content = "CREATE VIEW CORPDATA.EMP_YEARSOFSERVICE (LASTNAME, YEARSOFSERVICE)"
                         + " AS SELECT LASTNAME, YEAR (CURRENT DATE - HIREDATE) FROM CORPDATA.EMPLOYEE;";

        assertScoreAndParse(content, null, 1);

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

        String content = "CREATE OR REPLACE TRIGGER drop_trigger" + DdlConstants.SPACE + "BEFORE DROP ON hr.SCHEMA"
                         + DdlConstants.SPACE + "BEGIN" + DdlConstants.SPACE
                         + "RAISE_APPLICATION_ERROR ( num => -20000,msg => 'Cannot drop object');" + DdlConstants.SPACE + "END;"
                         + DdlConstants.SPACE + "/";
        assertScoreAndParse(content, null, 1);
        AstNode childNode = rootNode.getChildren().get(0);
        assertTrue(hasMixinType(childNode, TYPE_CREATE_TRIGGER_STATEMENT));

    }
View Full Code Here

    @Test
    public void shouldParseAnalyze() {
        printTest("shouldParseAnalyze()");
        String content = "ANALYZE TABLE customers VALIDATE STRUCTURE ONLINE;";
        assertScoreAndParse(content, null, 1);
        AstNode childNode = rootNode.getChildren().get(0);
        assertTrue(hasMixinType(childNode, TYPE_ANALYZE_STATEMENT));
    }
View Full Code Here

    @Test
    public void shouldParseRollbackToSavepoint() {
        printTest("shouldParseRollbackToSavepoint()");
        String content = "ROLLBACK TO SAVEPOINT banda_sal;";
        assertScoreAndParse(content, null, 1);
        AstNode childNode = rootNode.getChildren().get(0);
        assertTrue(hasMixinType(childNode, TYPE_ROLLBACK_STATEMENT));
    }
View Full Code Here

    @Test
    public void shouldParseAlterTableAddREF() {
        printTest("shouldParseAlterTableAddREF()");
        String content = "ALTER TABLE staff ADD (REF(dept) WITH ROWID);";
        assertScoreAndParse(content, null, 1);
        AstNode childNode = rootNode.getChildren().get(0);
        assertTrue(hasMixinType(childNode, TYPE_ALTER_TABLE_STATEMENT));
    }
View Full Code Here

    public void shouldParseAlterTableADDWithNESTED_TABLE() {
        // This is a one-off case where there is a custom datatype (i.e. skill_table_type)
        printTest("shouldParseAlterTableADDWithNESTED_TABLE()");
        String content = "ALTER TABLE employees ADD (skills skill_table_type) NESTED TABLE skills STORE AS nested_skill_table;";
        assertScoreAndParse(content, null, 2); // ALTER TABLE + 1 PROBLEM
        AstNode childNode = rootNode.getChildren().get(0);
        assertTrue(hasMixinType(childNode, TYPE_ALTER_TABLE_STATEMENT));
    }
View Full Code Here

    @Test
    public void shouldParseAlterIndexRename() {
        printTest("shouldParseAlterIndexRename()");
        String content = "ALTER INDEX upper_ix RENAME TO upper_name_ix;";
        assertScoreAndParse(content, null, 1);
        AstNode childNode = rootNode.getChildren().get(0);
        assertTrue(hasMixinType(childNode, TYPE_ALTER_INDEX_STATEMENT));
    }
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.