Search in sources :

Example 1 with SourceType

use of org.hibernate.tool.schema.SourceType 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)

Example 2 with SourceType

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

the class SchemaDropperImpl method doDrop.

/**
 * For tests
 */
public void doDrop(Metadata metadata, final ServiceRegistry serviceRegistry, final Map settings, final boolean manageNamespaces, GenerationTarget... targets) {
    if (targets == null || targets.length == 0) {
        final JdbcContext jdbcContext = tool.resolveJdbcContext(settings);
        targets = new GenerationTarget[] { new GenerationTargetToDatabase(serviceRegistry.getService(TransactionCoordinatorBuilder.class).buildDdlTransactionIsolator(jdbcContext), true) };
    }
    doDrop(metadata, new ExecutionOptions() {

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

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

        @Override
        public ExceptionHandler getExceptionHandler() {
            return ExceptionHandlerLoggedImpl.INSTANCE;
        }
    }, serviceRegistry.getService(JdbcEnvironment.class).getDialect(), new SourceDescriptor() {

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

        @Override
        public ScriptSourceInput getScriptSourceInput() {
            return null;
        }
    }, targets);
}
Also used : ExceptionHandler(org.hibernate.tool.schema.spi.ExceptionHandler) ExecutionOptions(org.hibernate.tool.schema.spi.ExecutionOptions) SourceDescriptor(org.hibernate.tool.schema.spi.SourceDescriptor) ScriptSourceInput(org.hibernate.tool.schema.spi.ScriptSourceInput) JdbcContext(org.hibernate.tool.schema.internal.exec.JdbcContext) SourceType(org.hibernate.tool.schema.SourceType) TransactionCoordinatorBuilder(org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder) GenerationTargetToDatabase(org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase) Map(java.util.Map)

Example 3 with SourceType

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

the class SchemaManagementToolCoordinator method buildScriptTargetDescriptor.

private static JpaTargetAndSourceDescriptor buildScriptTargetDescriptor(Map configurationValues, SettingSelector settingSelector, ServiceRegistry serviceRegistry) {
    final Object scriptSourceSetting = settingSelector.getScriptSourceSetting(configurationValues);
    final SourceType sourceType = SourceType.interpret(settingSelector.getSourceTypeSetting(configurationValues), scriptSourceSetting != null ? SourceType.SCRIPT : SourceType.METADATA);
    final boolean includesScripts = sourceType != SourceType.METADATA;
    if (includesScripts && scriptSourceSetting == null) {
        throw new SchemaManagementException("Schema generation configuration indicated to include CREATE scripts, but no script was specified");
    }
    String charsetName = (String) configurationValues.get(AvailableSettings.HBM2DDL_CHARSET_NAME);
    final ScriptSourceInput scriptSourceInput = includesScripts ? Helper.interpretScriptSourceSetting(scriptSourceSetting, serviceRegistry.getService(ClassLoaderService.class), charsetName) : null;
    final ScriptTargetOutput scriptTargetOutput = Helper.interpretScriptTargetSetting(settingSelector.getScriptTargetSetting(configurationValues), serviceRegistry.getService(ClassLoaderService.class), charsetName);
    return new JpaTargetAndSourceDescriptor() {

        @Override
        public EnumSet<TargetType> getTargetTypes() {
            return EnumSet.of(TargetType.SCRIPT);
        }

        @Override
        public ScriptTargetOutput getScriptTargetOutput() {
            return scriptTargetOutput;
        }

        @Override
        public SourceType getSourceType() {
            return sourceType;
        }

        @Override
        public ScriptSourceInput getScriptSourceInput() {
            return scriptSourceInput;
        }
    };
}
Also used : SourceType(org.hibernate.tool.schema.SourceType) TargetType(org.hibernate.tool.schema.TargetType) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService)

Example 4 with SourceType

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

the class SchemaManagementToolCoordinator method buildDatabaseTargetDescriptor.

private static JpaTargetAndSourceDescriptor buildDatabaseTargetDescriptor(Map configurationValues, SettingSelector settingSelector, ServiceRegistry serviceRegistry) {
    final Object scriptSourceSetting = settingSelector.getScriptSourceSetting(configurationValues);
    final SourceType sourceType = SourceType.interpret(settingSelector.getSourceTypeSetting(configurationValues), scriptSourceSetting != null ? SourceType.SCRIPT : SourceType.METADATA);
    final boolean includesScripts = sourceType != SourceType.METADATA;
    if (includesScripts && scriptSourceSetting == null) {
        throw new SchemaManagementException("Schema generation configuration indicated to include CREATE scripts, but no script was specified");
    }
    final ScriptSourceInput scriptSourceInput = includesScripts ? Helper.interpretScriptSourceSetting(scriptSourceSetting, serviceRegistry.getService(ClassLoaderService.class), (String) configurationValues.get(AvailableSettings.HBM2DDL_CHARSET_NAME)) : null;
    return new JpaTargetAndSourceDescriptor() {

        @Override
        public EnumSet<TargetType> getTargetTypes() {
            return EnumSet.of(TargetType.DATABASE);
        }

        @Override
        public ScriptTargetOutput getScriptTargetOutput() {
            return null;
        }

        @Override
        public SourceType getSourceType() {
            return sourceType;
        }

        @Override
        public ScriptSourceInput getScriptSourceInput() {
            return scriptSourceInput;
        }
    };
}
Also used : SourceType(org.hibernate.tool.schema.SourceType) TargetType(org.hibernate.tool.schema.TargetType)

Example 5 with SourceType

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

the class CrossSchemaForeignKeyGenerationTest method testSchemaMigrationForeignKeysAreGeneratedAfterAllTheTablesAreCreated.

@Test
@TestForIssue(jiraKey = "HHH-10420")
public void testSchemaMigrationForeignKeysAreGeneratedAfterAllTheTablesAreCreated() throws Exception {
    final MetadataSources metadataSources = new MetadataSources(ssr);
    metadataSources.addAnnotatedClass(SchemaOneEntity.class);
    metadataSources.addAnnotatedClass(SchemaTwoEntity.class);
    MetadataImplementor metadata = (MetadataImplementor) metadataSources.buildMetadata();
    metadata.validate();
    final Database database = metadata.getDatabase();
    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 IndividuallySchemaMigratorImpl(tool, DefaultSchemaFilter.INSTANCE).doMigration(metadata, options, TargetDescriptorImpl.INSTANCE);
    new IndividuallySchemaMigratorImpl(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) SchemaDropperImpl(org.hibernate.tool.schema.internal.SchemaDropperImpl) Database(org.hibernate.boot.model.relational.Database) ConfigurationService(org.hibernate.engine.config.spi.ConfigurationService) Map(java.util.Map) IndividuallySchemaMigratorImpl(org.hibernate.tool.schema.internal.IndividuallySchemaMigratorImpl) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Aggregations

SourceType (org.hibernate.tool.schema.SourceType)5 Map (java.util.Map)3 ExecutionOptions (org.hibernate.tool.schema.spi.ExecutionOptions)3 ScriptSourceInput (org.hibernate.tool.schema.spi.ScriptSourceInput)3 SourceDescriptor (org.hibernate.tool.schema.spi.SourceDescriptor)3 MetadataSources (org.hibernate.boot.MetadataSources)2 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)2 ConfigurationService (org.hibernate.engine.config.spi.ConfigurationService)2 TestForIssue (org.hibernate.testing.TestForIssue)2 TargetType (org.hibernate.tool.schema.TargetType)2 HibernateSchemaManagementTool (org.hibernate.tool.schema.internal.HibernateSchemaManagementTool)2 SchemaDropperImpl (org.hibernate.tool.schema.internal.SchemaDropperImpl)2 SchemaManagementTool (org.hibernate.tool.schema.spi.SchemaManagementTool)2 Test (org.junit.Test)2 Database (org.hibernate.boot.model.relational.Database)1 ClassLoaderService (org.hibernate.boot.registry.classloading.spi.ClassLoaderService)1 TransactionCoordinatorBuilder (org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder)1 GroupedSchemaMigratorImpl (org.hibernate.tool.schema.internal.GroupedSchemaMigratorImpl)1 IndividuallySchemaMigratorImpl (org.hibernate.tool.schema.internal.IndividuallySchemaMigratorImpl)1 GenerationTargetToDatabase (org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase)1