StandardDdlParser implements DdlParser, DdlConstants, DdlConstants.StatementStartPhrases { public AstNodeFactory nodeFactory() { return this.nodeFactory; } StandardDdlParser(); DataTypeParser getDatatypeParser(); void setDatatypeParser( DataTypeParser datatypeParser ); AstNodeFactory nodeFactory(); AstNode getRootNode(); void setRootNode( AstNode rootNode ); @Override Object score( String ddl,
                         String fileName,
                         DdlParserScorer scorer ); String[] getIdentifyingKeywords(); @Override void parse( String ddl,
                       AstNode rootNode,
                       Object scoreReturnObject ); final void addProblem( DdlParserProblem problem,
                                  AstNode node ); final void addProblem( DdlParserProblem problem ); final List<DdlParserProblem> getProblems(); final void attachNewProblem( DdlParserProblem problem,
                                        AstNode parentNode ); void mergeNodes( DdlTokenStream tokens,
                            AstNode firstNode,
                            AstNode secondNode ); AstNode handleUnknownToken( DdlTokenStream tokens,
                                       String tokenValue ); final AstNode unknownTerminatedNode( AstNode parentNode ); final AstNode missingTerminatorNode( AstNode parentNode ); final boolean isMissingTerminatorNode( AstNode node ); final boolean isValidSchemaChild( AstNode node ); final boolean setAsSchemaChildNode( AstNode statementNode,
                                               boolean stmtIsMissingTerminator ); boolean doUseTerminator(); void setDoUseTerminator( boolean useTerminator ); String getStatementTypeName( String[] stmtPhrase ); final Position getCurrentMarkedPosition(); final void markStartOfStatement( DdlTokenStream tokens ); final void markEndOfStatement( DdlTokenStream tokens,
                                          AstNode statementNode ); @Override void postProcess( AstNode rootNode ); boolean isTestMode(); void setTestMode( boolean testMode ); @Override String getId(); @Override int hashCode(); @Override boolean equals( Object obj ); static final String ID; }
@FixFor( "MODE-817" ) @Test public void shouldParseAlterTables() { printTest("shouldParseAlterTables()"); String content = getFileContent(DDL_FILE_PATH + "alterTables.ddl"); assertScoreAndParse(content, "alterTables.ddl", 31); List<AstNode> theNodes = parser.nodeFactory().getChildrenForType(rootNode, TYPE_CREATE_TABLE_STATEMENT); assertThat(theNodes.size(), is(0)); theNodes = parser.nodeFactory().getChildrenForType(rootNode, TYPE_ALTER_TABLE_STATEMENT); assertThat(theNodes.size(), is(13)); }
@Test public void shouldParseCreateTables() { printTest("shouldParseCreateTables()"); String content = getFileContent(DDL_FILE_PATH + "createTables.ddl"); assertScoreAndParse(content, "createTables.ddl", 20); List<AstNode> theNodes = parser.nodeFactory().getChildrenForType(rootNode, TYPE_CREATE_TABLE_STATEMENT); assertThat(theNodes.size(), is(16)); theNodes = parser.nodeFactory().getChildrenForType(rootNode, TYPE_ALTER_TABLE_STATEMENT); assertThat(theNodes.size(), is(2)); }
@Test public void shouldParseDropStatements() { printTest("shouldParseDropStatements()"); String content = getFileContent(DDL_FILE_PATH + "drop_statements.ddl"); assertScoreAndParse(content, "drop_statements.ddl", 12); List<AstNode> theNodes = parser.nodeFactory().getChildrenForType(rootNode, TYPE_DROP_TABLE_STATEMENT); assertThat(theNodes.size(), is(2)); assertEquals("list_customers", theNodes.get(0).getName()); String prop = (String)theNodes.get(1).getProperty(DROP_BEHAVIOR); assertEquals("RESTRICT", prop); theNodes = parser.nodeFactory().getChildrenForType(rootNode, TYPE_DROP_VIEW_STATEMENT); assertThat(theNodes.size(), is(2)); assertEquals("list_customers", theNodes.get(0).getName()); prop = (String)theNodes.get(1).getProperty(DROP_BEHAVIOR); assertEquals("RESTRICT", prop); theNodes = parser.nodeFactory().getChildrenForType(rootNode, TYPE_DROP_SCHEMA_STATEMENT); assertThat(theNodes.size(), is(2)); assertEquals("list_customers", theNodes.get(0).getName()); prop = (String)theNodes.get(0).getProperty(DROP_BEHAVIOR); assertEquals("CASCADE", prop); theNodes = parser.nodeFactory().getChildrenForType(rootNode, TYPE_DROP_DOMAIN_STATEMENT); assertThat(theNodes.size(), is(2)); assertEquals("list_customers", theNodes.get(0).getName()); prop = (String)theNodes.get(0).getProperty(DROP_BEHAVIOR); assertEquals("CASCADE", prop); theNodes = parser.nodeFactory().getChildrenForType(rootNode, TYPE_DROP_TRANSLATION_STATEMENT); assertThat(theNodes.size(), is(1)); assertEquals("translation_name", theNodes.get(0).getName()); theNodes = parser.nodeFactory().getChildrenForType(rootNode, TYPE_DROP_COLLATION_STATEMENT); assertThat(theNodes.size(), is(1)); assertEquals("collation_name", theNodes.get(0).getName()); theNodes = parser.nodeFactory().getChildrenForType(rootNode, TYPE_DROP_CHARACTER_SET_STATEMENT); assertThat(theNodes.size(), is(1)); assertEquals("character_set_name", theNodes.get(0).getName()); theNodes = parser.nodeFactory().getChildrenForType(rootNode, TYPE_DROP_ASSERTION_STATEMENT); assertThat(theNodes.size(), is(1)); assertEquals("assertion_name", theNodes.get(0).getName()); }
@Test public void shouldParseUnterminatedStatementsFile() { printTest("shouldParseUnterminatedOracleFile()"); String content = getFileContent(DDL_FILE_PATH + "GFM_Physical_Partial.ddl"); assertScoreAndParse(content, "GFM_Physical_Partial.ddl", 5); List<AstNode> schemaNodes = parser.nodeFactory().getChildrenForType(rootNode, TYPE_CREATE_SCHEMA_STATEMENT); assertThat(schemaNodes.size(), is(1)); assertThat(schemaNodes.get(0).getChildCount(), is(2)); assertThat(schemaNodes.get(0).getName(), is("GLOBALFORCEMGMT")); }
@Test @FixFor( "MODE-2604" ) public void shouldParseCreateTableStatementsWithCheckConstraints() throws Exception { String content = getFileContent(DDL_FILE_PATH + "create_table_check_constraint.ddl"); assertScoreAndParse(content, "create_table_check_constraint.ddl", 2); List<AstNode> constraintNodes = parser.nodeFactory().getChildrenForType(rootNode, StandardDdlLexicon.TYPE_TABLE_CONSTRAINT); assertEquals(2, constraintNodes.size()); assertEquals(DdlConstants.UNNAMED_CHECK_NODE_NAME, constraintNodes.get(0).getName()); assertEquals("chk_Person", constraintNodes.get(1).getName()); }
@Test @FixFor( "MODE-2604" ) public void shouldParseAlterTableStatementsWithCheckConstraints() throws Exception { String content = getFileContent(DDL_FILE_PATH + "alter_table_check_constraint.ddl"); assertScoreAndParse(content, "alter_table_check_constraint.ddl", 2); List<AstNode> constraintNodes = parser.nodeFactory().getChildrenForType(rootNode, StandardDdlLexicon.TYPE_ADD_TABLE_CONSTRAINT_DEFINITION); assertEquals(2, constraintNodes.size()); assertEquals(DdlConstants.UNNAMED_CHECK_NODE_NAME, constraintNodes.get(0).getName()); assertEquals("chk_Person", constraintNodes.get(1).getName()); }