package liquibase.sqlgenerator.core;

import liquibase.database.Database;
import liquibase.database.core.OracleDatabase;
import liquibase.exception.ValidationErrors;
import liquibase.logging.LogFactory;
import liquibase.sql.Sql;
import liquibase.sql.UnparsedSql;
import liquibase.sqlgenerator.SqlGeneratorChain;
import liquibase.statement.core.DropTableStatement;
import liquibase.structure.core.Relation;
import liquibase.structure.core.Table;

public class DropTableGenerator extends AbstractSqlGenerator<DropTableStatement> {

    @Override
    public ValidationErrors validate(DropTableStatement dropTableStatement, Database database, SqlGeneratorChain sqlGeneratorChain) {
        ValidationErrors validationErrors = new ValidationErrors();
        validationErrors.checkRequiredField("tableName", dropTableStatement.getTableName());
        return validationErrors;
    }

    @Override
    public Sql[] generateSql(DropTableStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
        StringBuffer buffer = new StringBuffer();
        buffer.append("DROP TABLE ").append(database.escapeTableName(statement.getCatalogName(), statement.getSchemaName(), statement.getTableName()));
        if (statement.isCascadeConstraints()) {
            if (!database.supportsDropTableCascadeConstraints()) {
                // TODO Is this really a problem, and does it warrant to many WARNINGs in the log? Need to investigate.
                LogFactory.getInstance().getLog().warning("Database does not support drop with cascade");
            } else if (database instanceof OracleDatabase) {
                buffer.append(" CASCADE CONSTRAINTS");
            } else {
                buffer.append(" CASCADE");
            }
        }

        return new Sql[]{
                new UnparsedSql(buffer.toString(), getAffectedTable(statement))
        };
    }

    protected Relation getAffectedTable(DropTableStatement statement) {
        return new Table().setName(statement.getTableName()).setSchema(statement.getCatalogName(), statement.getSchemaName());
    }
}

@@ -163,45 +163,8 @@
 rs;%0A
-import liquibase.logging.LogFactory;%0A
 impo
@@ -1236,9 +1236,8 @@
 if (
-!
 data
@@ -1302,237 +1302,8 @@
     
-// TODO Is this really a problem, and does it warrant to many WARNINGs in the log? Need to investigate.%0A                LogFactory.getInstance().getLog().warning(%22Database does not support drop with cascade%22);%0A            %7D else 
 if (
@@ -1348,32 +1348,36 @@
                 
+    
 buffer.append(%22 
@@ -1411,16 +1411,20 @@
         
+  
+  
 %7D else %7B
@@ -1424,16 +1424,20 @@
  else %7B%0A
+    
         
@@ -1467,24 +1467,42 @@
  CASCADE%22);%0A
+                %7D%0A
             

Remove unnecessary "Database does not support drop with cascade" warning