SchemaDDL { public static void dropSchema (DDLFunctions ddlFunctions, Session session, DropSchemaNode dropSchema, QueryContext context) { AkibanInformationSchema ais = ddlFunctions.getAIS(session); final String schemaName = dropSchema.getSchemaName(); Schema curSchema = ais.getSchema(schemaName); if((curSchema == null) && skipOrThrow(context, dropSchema.getExistenceCheck(), curSchema, new NoSuchSchemaException(schemaName))) { return; } if (dropSchema.getDropBehavior() == StatementType.DROP_RESTRICT || dropSchema.getDropBehavior() == StatementType.DROP_DEFAULT) throw new ReferencedSchemaException(schemaName); else if (dropSchema.getDropBehavior() == StatementType.DROP_CASCADE) ddlFunctions.dropSchema(session, schemaName); } private  SchemaDDL(); static void createSchema(AkibanInformationSchema ais,
                                   String defaultSchemaName,
                                   CreateSchemaNode createSchema,
                                   QueryContext context); static void dropSchema(DDLFunctions ddlFunctions,
            Session session,
            DropSchemaNode dropSchema,
            QueryContext context);  }
@Test (expected=NoSuchSchemaException.class) public void dropSchemaEmpty() throws Exception { String sql = "DROP SCHEMA EMPTY RESTRICT"; AkibanInformationSchema ais = new AkibanInformationSchema(); StatementNode stmt = parser.parseStatement(sql); assertTrue (stmt instanceof DropSchemaNode); DDLFunctions ddlFunctions = new TableDDLTest.DDLFunctionsMock(ais); SchemaDDL.dropSchema(ddlFunctions, null, (DropSchemaNode)stmt, null); }
@Test public void dropNonExistingSchemaWithIfExists() throws Exception { String sql = "DROP SCHEMA IF EXISTS AA"; AkibanInformationSchema ais = new AkibanInformationSchema(); StatementNode node = parser.parseStatement(sql); assertTrue(node instanceof DropSchemaNode); DDLFunctions ddlFunctions = new TableDDLTest.DDLFunctionsMock(ais); SchemaDDL.dropSchema(ddlFunctions, null, (DropSchemaNode)node, null); }
@Test public void dropSchemaEmptyIfExists() throws Exception { String sql = "DROP SCHEMA IF EXISTS EMPTY RESTRICT"; AkibanInformationSchema ais = new AkibanInformationSchema(); StatementNode stmt = parser.parseStatement(sql); assertTrue (stmt instanceof DropSchemaNode); DDLFunctions ddlFunctions = new TableDDLTest.DDLFunctionsMock(ais); SchemaDDL.dropSchema(ddlFunctions, null, (DropSchemaNode)stmt, null); }
@Test(expected=ReferencedSchemaException.class) public void dropSchemaUsed() throws Exception { String sql = "DROP SCHEMA S RESTRICT"; AkibanInformationSchema ais = factory(); assertNotNull(ais.getTable("s", "t")); StatementNode stmt = parser.parseStatement(sql); assertTrue (stmt instanceof DropSchemaNode); DDLFunctions ddlFunctions = new TableDDLTest.DDLFunctionsMock(ais); SchemaDDL.dropSchema(ddlFunctions, null, (DropSchemaNode)stmt, null); }