Example usage for org.hibernate.dialect Dialect hasAlterTable

List of usage examples for org.hibernate.dialect Dialect hasAlterTable

Introduction

In this page you can find the example usage for org.hibernate.dialect Dialect hasAlterTable.

Prototype

public boolean hasAlterTable() 

Source Link

Document

Does this dialect support the ALTER TABLE syntax?

Usage

From source file:org.apereo.portal.tools.dbloader.HibernateDbLoader.java

License:Apache License

/** Generate create scripts and add them to the script list */
@SuppressWarnings("unchecked")
protected List<String> createScript(Collection<Table> tables, Dialect dialect, Mapping mapping,
        String defaultCatalog, String defaultSchema) {
    final List<String> script = new ArrayList<String>(tables.size() * 2);

    for (final Table table : tables) {
        if (table.isPhysicalTable()) {
            script.add(table.sqlCreateString(dialect, mapping, defaultCatalog, defaultSchema));
        }//from   w w  w  .j  a  va 2s. com
    }

    for (final Table table : tables) {
        if (table.isPhysicalTable()) {
            if (!dialect.supportsUniqueConstraintInCreateAlterTable()) {
                for (final Iterator<UniqueKey> subIter = table.getUniqueKeyIterator(); subIter.hasNext();) {
                    final UniqueKey uk = subIter.next();
                    final String constraintString = uk.sqlCreateString(dialect, mapping, defaultCatalog,
                            defaultSchema);
                    if (constraintString != null) {
                        script.add(constraintString);
                    }
                }
            }

            for (final Iterator<Index> subIter = table.getIndexIterator(); subIter.hasNext();) {
                final Index index = subIter.next();
                script.add(index.sqlCreateString(dialect, mapping, defaultCatalog, defaultSchema));
            }

            if (dialect.hasAlterTable()) {
                for (final Iterator<ForeignKey> subIter = table.getForeignKeyIterator(); subIter.hasNext();) {
                    final ForeignKey fk = subIter.next();
                    if (fk.isPhysicalConstraint()) {
                        script.add(fk.sqlCreateString(dialect, mapping, defaultCatalog, defaultSchema));
                    }
                }
            }
        }
    }

    return script;
}