HHH-10066 - Drop and recreate AuxiliaryDatabaseObjects as part of schema update

(cherry picked from commit 59a8d3122f)
This commit is contained in:
Steve Ebersole 2015-09-28 14:26:57 -05:00
parent 398cec2bcc
commit 4899a1db96
1 changed files with 49 additions and 0 deletions

View File

@ -13,6 +13,7 @@ import java.util.Set;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.boot.model.relational.AuxiliaryDatabaseObject;
import org.hibernate.boot.model.relational.Database;
import org.hibernate.boot.model.relational.Exportable;
import org.hibernate.boot.model.relational.Namespace;
@ -72,6 +73,38 @@ public class SchemaMigratorImpl implements SchemaMigrator {
final Set<String> exportIdentifiers = new HashSet<String>( 50 );
final Database database = metadata.getDatabase();
final JdbcEnvironment jdbcEnvironment = database.getJdbcEnvironment();
final Dialect dialect = jdbcEnvironment.getDialect();
// Drop all AuxiliaryDatabaseObjects
for ( AuxiliaryDatabaseObject auxiliaryDatabaseObject : database.getAuxiliaryDatabaseObjects() ) {
if ( !auxiliaryDatabaseObject.appliesToDialect( dialect ) ) {
continue;
}
applySqlStrings(
dialect.getAuxiliaryDatabaseObjectExporter().getSqlDropStrings( auxiliaryDatabaseObject, metadata ),
targets,
true
);
}
// Create before-table AuxiliaryDatabaseObjects
for ( AuxiliaryDatabaseObject auxiliaryDatabaseObject : database.getAuxiliaryDatabaseObjects() ) {
if ( auxiliaryDatabaseObject.beforeTablesOnCreation() ) {
continue;
}
if ( !auxiliaryDatabaseObject.appliesToDialect( dialect ) ) {
continue;
}
applySqlStrings(
auxiliaryDatabaseObject.sqlCreateStrings( jdbcEnvironment.getDialect() ),
targets,
true
);
}
boolean tryToCreateCatalogs = false;
boolean tryToCreateSchemas = false;
@ -175,6 +208,22 @@ public class SchemaMigratorImpl implements SchemaMigrator {
);
}
}
// Create after-table AuxiliaryDatabaseObjects
for ( AuxiliaryDatabaseObject auxiliaryDatabaseObject : database.getAuxiliaryDatabaseObjects() ) {
if ( !auxiliaryDatabaseObject.beforeTablesOnCreation() ) {
continue;
}
if ( !auxiliaryDatabaseObject.appliesToDialect( dialect ) ) {
continue;
}
applySqlStrings(
auxiliaryDatabaseObject.sqlCreateStrings( jdbcEnvironment.getDialect() ),
targets,
true
);
}
}
private void createTable(Table table, Metadata metadata, List<Target> targets) {