Search in sources :

Example 1 with ExceptionHandlerCollectingImpl

use of org.hibernate.tool.schema.internal.ExceptionHandlerCollectingImpl 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 ExceptionHandlerCollectingImpl

use of org.hibernate.tool.schema.internal.ExceptionHandlerCollectingImpl 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

HashMap (java.util.HashMap)2 Map (java.util.Map)2 ExceptionHandlerCollectingImpl (org.hibernate.tool.schema.internal.ExceptionHandlerCollectingImpl)2 ExecutionOptions (org.hibernate.tool.schema.spi.ExecutionOptions)2 SchemaManagementTool (org.hibernate.tool.schema.spi.SchemaManagementTool)2 ExceptionHandler (org.hibernate.tool.schema.spi.ExceptionHandler)1 SourceDescriptor (org.hibernate.tool.schema.spi.SourceDescriptor)1 TargetDescriptor (org.hibernate.tool.schema.spi.TargetDescriptor)1