Search in sources :

Example 1 with GroupedSchemaMigratorImpl

use of org.hibernate.tool.schema.internal.GroupedSchemaMigratorImpl in project hibernate-orm by hibernate.

the class CrossSchemaForeignKeyGenerationTest method testImprovedSchemaMigrationForeignKeysAreGeneratedAfterAllTheTablesAreCreated.

@Test
@TestForIssue(jiraKey = "HHH-10420")
public void testImprovedSchemaMigrationForeignKeysAreGeneratedAfterAllTheTablesAreCreated() throws Exception {
    final MetadataSources metadataSources = new MetadataSources(ssr);
    metadataSources.addAnnotatedClass(SchemaOneEntity.class);
    metadataSources.addAnnotatedClass(SchemaTwoEntity.class);
    MetadataImplementor metadata = (MetadataImplementor) metadataSources.buildMetadata();
    metadata.validate();
    final HibernateSchemaManagementTool tool = (HibernateSchemaManagementTool) ssr.getService(SchemaManagementTool.class);
    final Map configurationValues = ssr.getService(ConfigurationService.class).getSettings();
    final ExecutionOptions options = new ExecutionOptions() {

        @Override
        public boolean shouldManageNamespaces() {
            return true;
        }

        @Override
        public Map getConfigurationValues() {
            return configurationValues;
        }

        @Override
        public ExceptionHandler getExceptionHandler() {
            return ExceptionHandlerLoggedImpl.INSTANCE;
        }
    };
    new GroupedSchemaMigratorImpl(tool, DefaultSchemaFilter.INSTANCE).doMigration(metadata, options, TargetDescriptorImpl.INSTANCE);
    new SchemaDropperImpl(tool).doDrop(metadata, options, ssr.getService(JdbcEnvironment.class).getDialect(), new SourceDescriptor() {

        @Override
        public SourceType getSourceType() {
            return SourceType.METADATA;
        }

        @Override
        public ScriptSourceInput getScriptSourceInput() {
            return null;
        }
    }, buildTargets());
}
Also used : HibernateSchemaManagementTool(org.hibernate.tool.schema.internal.HibernateSchemaManagementTool) SchemaManagementTool(org.hibernate.tool.schema.spi.SchemaManagementTool) SourceDescriptor(org.hibernate.tool.schema.spi.SourceDescriptor) ScriptSourceInput(org.hibernate.tool.schema.spi.ScriptSourceInput) SourceType(org.hibernate.tool.schema.SourceType) MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) HibernateSchemaManagementTool(org.hibernate.tool.schema.internal.HibernateSchemaManagementTool) ExecutionOptions(org.hibernate.tool.schema.spi.ExecutionOptions) GroupedSchemaMigratorImpl(org.hibernate.tool.schema.internal.GroupedSchemaMigratorImpl) SchemaDropperImpl(org.hibernate.tool.schema.internal.SchemaDropperImpl) ConfigurationService(org.hibernate.engine.config.spi.ConfigurationService) Map(java.util.Map) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Aggregations

Map (java.util.Map)1 MetadataSources (org.hibernate.boot.MetadataSources)1 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)1 ConfigurationService (org.hibernate.engine.config.spi.ConfigurationService)1 TestForIssue (org.hibernate.testing.TestForIssue)1 SourceType (org.hibernate.tool.schema.SourceType)1 GroupedSchemaMigratorImpl (org.hibernate.tool.schema.internal.GroupedSchemaMigratorImpl)1 HibernateSchemaManagementTool (org.hibernate.tool.schema.internal.HibernateSchemaManagementTool)1 SchemaDropperImpl (org.hibernate.tool.schema.internal.SchemaDropperImpl)1 ExecutionOptions (org.hibernate.tool.schema.spi.ExecutionOptions)1 SchemaManagementTool (org.hibernate.tool.schema.spi.SchemaManagementTool)1 ScriptSourceInput (org.hibernate.tool.schema.spi.ScriptSourceInput)1 SourceDescriptor (org.hibernate.tool.schema.spi.SourceDescriptor)1 Test (org.junit.Test)1