package liquibase.database.sql;

import liquibase.database.Database;
import liquibase.database.MaxDBDatabase;
import liquibase.database.MySQLDatabase;
import liquibase.database.SQLiteDatabase;
import liquibase.exception.StatementNotSupportedOnDatabaseException;

public class DropUniqueConstraintStatement implements SqlStatement {

    private String schemaName;
    private String tableName;
    private String constraintName;

    public DropUniqueConstraintStatement(String schemaName, String tableName, String constraintName) {
        this.schemaName = schemaName;
        this.tableName = tableName;
        this.constraintName = constraintName;
    }

    public String getSchemaName() {
        return schemaName;
    }

    public String getTableName() {
        return tableName;
    }

    public String getConstraintName() {
        return constraintName;
    }

    public String getSqlStatement(Database database) throws StatementNotSupportedOnDatabaseException {
    	if (!supportsDatabase(database)) {
            throw new StatementNotSupportedOnDatabaseException(this, database);
        }
    	
    	if (database instanceof MySQLDatabase) {
            return "ALTER TABLE " + database.escapeTableName(getSchemaName(), getTableName()) + " DROP KEY " + getConstraintName();
        } else if (database instanceof MaxDBDatabase) {
            return "DROP INDEX " + getConstraintName() + " ON " + database.escapeTableName(getSchemaName(), getTableName());
        }

        return "ALTER TABLE " + database.escapeTableName(getSchemaName(), getTableName()) + " DROP CONSTRAINT " + getConstraintName();
    }

    public String getEndDelimiter(Database database) {
        return ";";
    }

    public boolean supportsDatabase(Database database) {
    	return !(database instanceof SQLiteDatabase);
    }
}

@@ -58,143 +58,9 @@
 ase.
-Database;%0D%0Aimport liquibase.database.MaxDBDatabase;%0D%0Aimport liquibase.database.MySQLDatabase;%0D%0Aimport liquibase.database.SQLiteDatabase
+*
 ;%0D%0Ai
@@ -1379,24 +1379,236 @@
 ;%0D%0A        %7D
+ else if (database instanceof OracleDatabase) %7B%0D%0A            return %22ALTER TABLE %22 + database.escapeTableName(getSchemaName(), getTableName()) + %22 DROP CONSTRAINT %22 + getConstraintName()+%22 DROP INDEX%22;%0D%0A        %7D
 %0D%0A%0D%0A        

add drop index clause for oracle