package liquibase.sqlgenerator.core;

import liquibase.database.Database;
import liquibase.database.core.HsqlDatabase;
import liquibase.exception.ValidationErrors;
import liquibase.sql.Sql;
import liquibase.sql.UnparsedSql;
import liquibase.sqlgenerator.SqlGeneratorChain;
import liquibase.statement.core.FindForeignKeyConstraintsStatement;

public class FindForeignKeyConstraintsGeneratorHsql extends AbstractSqlGenerator<FindForeignKeyConstraintsStatement>
{
    @Override
    public int getPriority()
    {
        return PRIORITY_DATABASE;
    }

    @Override
    public boolean supports(FindForeignKeyConstraintsStatement statement, Database database)
    {
        return database instanceof HsqlDatabase;
    }

    @Override
    public ValidationErrors validate(FindForeignKeyConstraintsStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain)
    {
        ValidationErrors validationErrors = new ValidationErrors();
        validationErrors.checkRequiredField("baseTableName", statement.getBaseTableName());
        return validationErrors;
    }

    @Override
    public Sql[] generateSql(FindForeignKeyConstraintsStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain)
    {
        StringBuilder sb = new StringBuilder();
        
        sb.append("SELECT ");
        sb.append("FKTABLE_NAME as ").append(FindForeignKeyConstraintsStatement.RESULT_COLUMN_BASE_TABLE_NAME).append(", ");
        sb.append("FKCOLUMN_NAME as ").append(FindForeignKeyConstraintsStatement.RESULT_COLUMN_BASE_TABLE_COLUMN_NAME).append(", ");
        sb.append("PKTABLE_NAME as ").append(FindForeignKeyConstraintsStatement.RESULT_COLUMN_FOREIGN_TABLE_NAME).append(", ");
        sb.append("PKCOLUMN_NAME as ").append(FindForeignKeyConstraintsStatement.RESULT_COLUMN_FOREIGN_COLUMN_NAME).append(", ");
        sb.append("FK_NAME as ").append(FindForeignKeyConstraintsStatement.RESULT_COLUMN_CONSTRAINT_NAME).append(" ");
        sb.append("FROM INFORMATION_SCHEMA.SYSTEM_CROSSREFERENCE ");
        sb.append("WHERE FKTABLE_NAME = '").append(statement.getBaseTableName().toUpperCase()).append("'");

        return new Sql[]
            {
                new UnparsedSql(sb.toString())
            };
    }
}

@@ -455,15 +455,12 @@
 ent%3E
-%0A%7B%0A    
+ %7B%0A%09
 @Ove
@@ -461,28 +461,25 @@
 %0A%09@Override%0A
-    
+%09
 public int g
@@ -490,31 +490,21 @@
 iority()
-%0A    %7B%0A        
+ %7B%0A%09%09
 return P
@@ -521,27 +521,21 @@
 TABASE;%0A
-    %7D%0A%0A    
+%09%7D%0A%0A%09
 @Overrid
@@ -532,28 +532,25 @@
 %0A%09@Override%0A
-    
+%09
 public boole
@@ -625,31 +625,21 @@
 atabase)
-%0A    %7B%0A        
+ %7B%0A%09%09
 return d
@@ -675,33 +675,13 @@
 se;%0A
-    %7D%0A%0A    @Override%0A    
+%09%7D%0A%0A%09
 publ
@@ -810,31 +810,21 @@
 orChain)
-%0A    %7B%0A        
+ %7B%0A%09%09
 Validati
@@ -875,24 +875,18 @@
 rors();%0A
-        
+%09%09
 validati
@@ -961,24 +961,18 @@
 ame());%0A
-        
+%09%09
 return v
@@ -992,33 +992,13 @@
 rs;%0A
-    %7D%0A%0A    @Override%0A    
+%09%7D%0A%0A%09
 publ
@@ -1123,23 +1123,13 @@
 ain)
-%0A    %7B%0A        
+ %7B%0A%09%09
 Stri
@@ -1168,25 +1168,11 @@
 ();%0A
-        %0A        
+%0A%09%09
 sb.a
@@ -1185,32 +1185,26 @@
 %22SELECT %22);%0A
-        
+%09%09
 sb.append(%22F
@@ -1304,32 +1304,26 @@
 pend(%22, %22);%0A
-        
+%09%09
 sb.append(%22F
@@ -1431,32 +1431,26 @@
 pend(%22, %22);%0A
-        
+%09%09
 sb.append(%22P
@@ -1553,32 +1553,26 @@
 pend(%22, %22);%0A
-        
+%09%09
 sb.append(%22P
@@ -1677,32 +1677,26 @@
 pend(%22, %22);%0A
-        
+%09%09
 sb.append(%22F
@@ -1790,32 +1790,26 @@
 ppend(%22 %22);%0A
-        
+%09%09
 sb.append(%22F
@@ -1857,24 +1857,18 @@
 NCE %22);%0A
-        
+%09%09
 sb.appen
@@ -1960,24 +1960,18 @@
 (%22'%22);%0A%0A
-        
+%09%09
 return n
@@ -1982,38 +1982,10 @@
 ql%5B%5D
-%0A            %7B%0A              
  
+%7B
  new
@@ -2015,28 +2015,13 @@
 g())
-%0A            %7D;%0A    
+ %7D;%0A%09
 %7D%0A%7D%0A

remove unnecessary @Override annotations