Search in sources :

Example 11 with ExceptionHandler

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

        @Override
        public SchemaFilter getSchemaFilter() {
            return SchemaFilter.ALL;
        }
    };
}
Also used : ExceptionHandler(org.hibernate.tool.schema.spi.ExceptionHandler) DefaultSchemaFilter(org.hibernate.tool.schema.internal.DefaultSchemaFilter) SchemaFilter(org.hibernate.tool.schema.spi.SchemaFilter) 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 12 with ExceptionHandler

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

the class SchemaUpdate method execute.

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<String, Object> config = new HashMap<>(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 ExceptionHandler exceptionHandler = haltOnError ? ExceptionHandlerHaltImpl.INSTANCE : new ExceptionHandlerCollectingImpl();
    final ExecutionOptions executionOptions = SchemaManagementToolCoordinator.buildExecutionOptions(config, exceptionHandler);
    final TargetDescriptor targetDescriptor = SchemaExport.buildTargetDescriptor(targetTypes, outputFile, append, serviceRegistry);
    try {
        tool.getSchemaMigrator(config).doMigration(metadata, executionOptions, ContributableMatcher.ALL, 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) HashMap(java.util.HashMap) TargetDescriptor(org.hibernate.tool.schema.spi.TargetDescriptor) ExceptionHandlerCollectingImpl(org.hibernate.tool.schema.internal.ExceptionHandlerCollectingImpl)

Aggregations

ExceptionHandler (org.hibernate.tool.schema.spi.ExceptionHandler)12 ExecutionOptions (org.hibernate.tool.schema.spi.ExecutionOptions)12 Map (java.util.Map)10 HashMap (java.util.HashMap)6 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)6 Before (org.junit.Before)6 SchemaFilter (org.hibernate.tool.schema.spi.SchemaFilter)5 MetadataSources (org.hibernate.boot.MetadataSources)4 DefaultSchemaFilter (org.hibernate.tool.schema.internal.DefaultSchemaFilter)3 SourceDescriptor (org.hibernate.tool.schema.spi.SourceDescriptor)3 TargetDescriptor (org.hibernate.tool.schema.spi.TargetDescriptor)3 EnumSet (java.util.EnumSet)2 Metadata (org.hibernate.boot.Metadata)2 Database (org.hibernate.boot.model.relational.Database)2 QualifiedTableName (org.hibernate.boot.model.relational.QualifiedTableName)2 ConfigurationService (org.hibernate.engine.config.spi.ConfigurationService)2 DriverManagerConnectionProviderImpl (org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl)2 TableStructure (org.hibernate.id.enhanced.TableStructure)2 Table (org.hibernate.mapping.Table)2 TransactionCoordinatorBuilder (org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder)2