protected TableDefinitionChangesPredicate getTableDefinitionChangesPredicate()

in src/main/java/org/apache/ddlutils/platform/interbase/InterbasePlatform.java [222:286]


    protected TableDefinitionChangesPredicate getTableDefinitionChangesPredicate()
    {
        return new DefaultTableDefinitionChangesPredicate()
        {
            public boolean areSupported(Table intermediateTable, List changes)
            {
                // Firebird does support adding a primary key, but only if none of the primary
                // key columns have been added within the same session
                if (super.areSupported(intermediateTable, changes))
                {
                    HashSet  addedColumns = new HashSet();
                    String[] pkColNames   = null;

                    for (Iterator it = changes.iterator(); it.hasNext();)
                    {
                        TableChange change = (TableChange)it.next();

                        if (change instanceof AddColumnChange)
                        {
                            addedColumns.add(((AddColumnChange)change).getNewColumn().getName());
                        }
                        else if (change instanceof AddPrimaryKeyChange)
                        {
                            pkColNames = ((AddPrimaryKeyChange)change).getPrimaryKeyColumns();
                        }
                        else if (change instanceof PrimaryKeyChange)
                        {
                            pkColNames = ((PrimaryKeyChange)change).getNewPrimaryKeyColumns();
                        }
                    }
                    if (pkColNames != null)
                    {
                        for (int colIdx = 0; colIdx < pkColNames.length; colIdx++)
                        {
                            if (addedColumns.contains(pkColNames[colIdx]))
                            {
                                return false;
                            }
                        }
                    }
                    return true;
                }
                else
                {
                    return false;
                }
            }

            protected boolean isSupported(Table intermediateTable, TableChange change)
            {
                // Firebird cannot add columns to the primary key or drop columns from it but
                // since we add/drop the primary key with separate changes anyways, this will
                // no problem here
                if ((change instanceof RemoveColumnChange) ||
                    (change instanceof AddColumnChange))
                {
                    return true;
                }
                else
                {
                    return super.isSupported(intermediateTable, change);
                }
            }
        };
    }