Search in sources :

Example 11 with ForeignKey

use of org.hibernate.mapping.ForeignKey in project uPortal by Jasig.

the class HibernateDbLoader method createScript.

/** 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));
        }
    }
    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;
}
Also used : Table(org.hibernate.mapping.Table) UniqueKey(org.hibernate.mapping.UniqueKey) ArrayList(java.util.ArrayList) Index(org.hibernate.mapping.Index) ForeignKey(org.hibernate.mapping.ForeignKey)

Aggregations

ForeignKey (org.hibernate.mapping.ForeignKey)11 Iterator (java.util.Iterator)7 Table (org.hibernate.mapping.Table)5 PersistentClass (org.hibernate.mapping.PersistentClass)3 UniqueKey (org.hibernate.mapping.UniqueKey)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Identifier (org.hibernate.boot.model.naming.Identifier)2 Namespace (org.hibernate.boot.model.relational.Namespace)2 Column (org.hibernate.mapping.Column)2 Index (org.hibernate.mapping.Index)2 TestForIssue (org.hibernate.testing.TestForIssue)2 Map (java.util.Map)1 JoinColumn (javax.persistence.JoinColumn)1 UniqueConstraint (javax.persistence.UniqueConstraint)1 DuplicateMappingException (org.hibernate.DuplicateMappingException)1 MappingException (org.hibernate.MappingException)1 MetadataSources (org.hibernate.boot.MetadataSources)1