Search in sources :

Example 1 with SourceDescriptor

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

the class SchemaExport method doExecution.

public void doExecution(Action action, boolean needsJdbc, Metadata metadata, ServiceRegistry serviceRegistry, TargetDescriptor targetDescriptor) {
    Map config = new HashMap();
    config.putAll(serviceRegistry.getService(ConfigurationService.class).getSettings());
    config.put(AvailableSettings.HBM2DDL_DELIMITER, delimiter);
    config.put(AvailableSettings.FORMAT_SQL, format);
    config.put(AvailableSettings.HBM2DDL_IMPORT_FILES, importFiles);
    final SchemaManagementTool tool = serviceRegistry.getService(SchemaManagementTool.class);
    final ExceptionHandler exceptionHandler = haltOnError ? ExceptionHandlerHaltImpl.INSTANCE : new ExceptionHandlerCollectingImpl();
    final ExecutionOptions executionOptions = SchemaManagementToolCoordinator.buildExecutionOptions(config, exceptionHandler);
    final SourceDescriptor sourceDescriptor = new SourceDescriptor() {

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

        @Override
        public ScriptSourceInput getScriptSourceInput() {
            return null;
        }
    };
    try {
        if (action.doDrop()) {
            tool.getSchemaDropper(config).doDrop(metadata, executionOptions, sourceDescriptor, targetDescriptor);
        }
        if (action.doCreate()) {
            tool.getSchemaCreator(config).doCreation(metadata, executionOptions, sourceDescriptor, targetDescriptor);
        }
    } finally {
        if (exceptionHandler instanceof ExceptionHandlerCollectingImpl) {
            exceptions.addAll(((ExceptionHandlerCollectingImpl) exceptionHandler).getExceptions());
        }
    }
}
Also used : SchemaManagementTool(org.hibernate.tool.schema.spi.SchemaManagementTool) ExceptionHandler(org.hibernate.tool.schema.spi.ExceptionHandler) ExecutionOptions(org.hibernate.tool.schema.spi.ExecutionOptions) SourceDescriptor(org.hibernate.tool.schema.spi.SourceDescriptor) HashMap(java.util.HashMap) ExceptionHandlerCollectingImpl(org.hibernate.tool.schema.internal.ExceptionHandlerCollectingImpl) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with SourceDescriptor

use of org.hibernate.tool.schema.spi.SourceDescriptor 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 SourceDescriptor

use of org.hibernate.tool.schema.spi.SourceDescriptor 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 4 with SourceDescriptor

use of org.hibernate.tool.schema.spi.SourceDescriptor 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 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

Map (java.util.Map)4 ExecutionOptions (org.hibernate.tool.schema.spi.ExecutionOptions)4 SourceDescriptor (org.hibernate.tool.schema.spi.SourceDescriptor)4 SourceType (org.hibernate.tool.schema.SourceType)3 SchemaManagementTool (org.hibernate.tool.schema.spi.SchemaManagementTool)3 ScriptSourceInput (org.hibernate.tool.schema.spi.ScriptSourceInput)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 HibernateSchemaManagementTool (org.hibernate.tool.schema.internal.HibernateSchemaManagementTool)2 SchemaDropperImpl (org.hibernate.tool.schema.internal.SchemaDropperImpl)2 ExceptionHandler (org.hibernate.tool.schema.spi.ExceptionHandler)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 Database (org.hibernate.boot.model.relational.Database)1 TransactionCoordinatorBuilder (org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder)1 ExceptionHandlerCollectingImpl (org.hibernate.tool.schema.internal.ExceptionHandlerCollectingImpl)1 GroupedSchemaMigratorImpl (org.hibernate.tool.schema.internal.GroupedSchemaMigratorImpl)1 IndividuallySchemaMigratorImpl (org.hibernate.tool.schema.internal.IndividuallySchemaMigratorImpl)1