Search in sources :

Example 6 with ExecutionOptions

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

the class UniqueConstraintDropTest method setUp.

@Before
public void setUp() throws Exception {
    output = File.createTempFile("update_script", ".sql");
    output.deleteOnExit();
    ssr = new StandardServiceRegistryBuilder().applySetting(Environment.HBM2DDL_AUTO, "none").applySetting(Environment.FORMAT_SQL, "false").applySetting(Environment.SHOW_SQL, "true").build();
    metadata = (MetadataImplementor) new MetadataSources(ssr).addResource("org/hibernate/test/schemaupdate/uniqueconstraint/TestEntity.hbm.xml").buildMetadata();
    metadata.validate();
    tool = (HibernateSchemaManagementTool) ssr.getService(SchemaManagementTool.class);
    final Map configurationValues = ssr.getService(ConfigurationService.class).getSettings();
    options = new ExecutionOptions() {

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

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

        @Override
        public ExceptionHandler getExceptionHandler() {
            return ExceptionHandlerLoggedImpl.INSTANCE;
        }
    };
}
Also used : ExceptionHandler(org.hibernate.tool.schema.spi.ExceptionHandler) ExecutionOptions(org.hibernate.tool.schema.spi.ExecutionOptions) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) ConfigurationService(org.hibernate.engine.config.spi.ConfigurationService) Map(java.util.Map) Before(org.junit.Before)

Example 7 with ExecutionOptions

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

the class IndividuallySchemaValidatorImplTest method setUp.

@Before
public void setUp() throws IOException {
    ssr = new StandardServiceRegistryBuilder().build();
    tool = (HibernateSchemaManagementTool) ssr.getService(SchemaManagementTool.class);
    configurationValues = ssr.getService(ConfigurationService.class).getSettings();
    executionOptions = new ExecutionOptions() {

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

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

        @Override
        public ExceptionHandler getExceptionHandler() {
            return ExceptionHandlerLoggedImpl.INSTANCE;
        }
    };
}
Also used : ExceptionHandler(org.hibernate.tool.schema.spi.ExceptionHandler) ExecutionOptions(org.hibernate.tool.schema.spi.ExecutionOptions) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) HashMap(java.util.HashMap) Map(java.util.Map) Before(org.junit.Before)

Example 8 with ExecutionOptions

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

Example 9 with ExecutionOptions

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

the class SchemaDropperImpl method generateDropCommands.

/**
	 * For testing...
	 *
	 * @param metadata The metadata for which to generate the creation commands.
	 *
	 * @return The generation commands
	 */
public List<String> generateDropCommands(Metadata metadata, final boolean manageNamespaces) {
    final JournalingGenerationTarget target = new JournalingGenerationTarget();
    final ServiceRegistry serviceRegistry = ((MetadataImplementor) metadata).getMetadataBuildingOptions().getServiceRegistry();
    final Dialect dialect = serviceRegistry.getService(JdbcEnvironment.class).getDialect();
    final ExecutionOptions options = new ExecutionOptions() {

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

        @Override
        public Map getConfigurationValues() {
            return Collections.emptyMap();
        }

        @Override
        public ExceptionHandler getExceptionHandler() {
            return ExceptionHandlerHaltImpl.INSTANCE;
        }
    };
    dropFromMetadata(metadata, options, dialect, FormatStyle.NONE.getFormatter(), target);
    return target.commands;
}
Also used : ExecutionOptions(org.hibernate.tool.schema.spi.ExecutionOptions) Dialect(org.hibernate.dialect.Dialect) ServiceRegistry(org.hibernate.service.ServiceRegistry) JdbcEnvironment(org.hibernate.engine.jdbc.env.spi.JdbcEnvironment)

Example 10 with ExecutionOptions

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

the class SchemaUpdate method execute.

@SuppressWarnings("unchecked")
public void execute(EnumSet<TargetType> targetTypes, Metadata metadata, ServiceRegistry serviceRegistry) {
    if (targetTypes.isEmpty()) {
        LOG.debug("Skipping SchemaExport as no targets were specified");
        return;
    }
    exceptions.clear();
    LOG.runningHbm2ddlSchemaUpdate();
    Map config = new HashMap();
    config.putAll(serviceRegistry.getService(ConfigurationService.class).getSettings());
    config.put(AvailableSettings.HBM2DDL_DELIMITER, delimiter);
    config.put(AvailableSettings.FORMAT_SQL, format);
    final SchemaManagementTool tool = serviceRegistry.getService(SchemaManagementTool.class);
    final ExceptionHandlerCollectingImpl exceptionHandler = new ExceptionHandlerCollectingImpl();
    final ExecutionOptions executionOptions = SchemaManagementToolCoordinator.buildExecutionOptions(config, exceptionHandler);
    final TargetDescriptor targetDescriptor = SchemaExport.buildTargetDescriptor(targetTypes, outputFile, serviceRegistry);
    try {
        tool.getSchemaMigrator(config).doMigration(metadata, executionOptions, targetDescriptor);
    } finally {
        exceptions.addAll(exceptionHandler.getExceptions());
    }
}
Also used : SchemaManagementTool(org.hibernate.tool.schema.spi.SchemaManagementTool) ExecutionOptions(org.hibernate.tool.schema.spi.ExecutionOptions) HashMap(java.util.HashMap) TargetDescriptor(org.hibernate.tool.schema.spi.TargetDescriptor) ExceptionHandlerCollectingImpl(org.hibernate.tool.schema.internal.ExceptionHandlerCollectingImpl) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ExecutionOptions (org.hibernate.tool.schema.spi.ExecutionOptions)11 Map (java.util.Map)9 ExceptionHandler (org.hibernate.tool.schema.spi.ExceptionHandler)5 SchemaManagementTool (org.hibernate.tool.schema.spi.SchemaManagementTool)5 HashMap (java.util.HashMap)4 MetadataSources (org.hibernate.boot.MetadataSources)4 SourceDescriptor (org.hibernate.tool.schema.spi.SourceDescriptor)4 ConfigurationService (org.hibernate.engine.config.spi.ConfigurationService)3 SourceType (org.hibernate.tool.schema.SourceType)3 ScriptSourceInput (org.hibernate.tool.schema.spi.ScriptSourceInput)3 Test (org.junit.Test)3 Database (org.hibernate.boot.model.relational.Database)2 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)2 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)2 Dialect (org.hibernate.dialect.Dialect)2 JdbcEnvironment (org.hibernate.engine.jdbc.env.spi.JdbcEnvironment)2 ServiceRegistry (org.hibernate.service.ServiceRegistry)2 TestForIssue (org.hibernate.testing.TestForIssue)2 ExceptionHandlerCollectingImpl (org.hibernate.tool.schema.internal.ExceptionHandlerCollectingImpl)2 HibernateSchemaManagementTool (org.hibernate.tool.schema.internal.HibernateSchemaManagementTool)2