Search in sources :

Example 1 with JdbcContext

use of org.hibernate.tool.schema.internal.exec.JdbcContext in project hibernate-orm by hibernate.

the class SchemaCreatorImpl method doCreation.

@Override
public void doCreation(Metadata metadata, ExecutionOptions options, SourceDescriptor sourceDescriptor, TargetDescriptor targetDescriptor) {
    if (targetDescriptor.getTargetTypes().isEmpty()) {
        return;
    }
    final JdbcContext jdbcContext = tool.resolveJdbcContext(options.getConfigurationValues());
    final GenerationTarget[] targets = tool.buildGenerationTargets(targetDescriptor, jdbcContext, options.getConfigurationValues(), true);
    doCreation(metadata, jdbcContext.getDialect(), options, sourceDescriptor, targets);
}
Also used : JdbcContext(org.hibernate.tool.schema.internal.exec.JdbcContext) GenerationTarget(org.hibernate.tool.schema.internal.exec.GenerationTarget)

Example 2 with JdbcContext

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

use of org.hibernate.tool.schema.internal.exec.JdbcContext in project hibernate-orm by hibernate.

the class AbstractSchemaMigrator method doMigration.

@Override
public void doMigration(Metadata metadata, ExecutionOptions options, TargetDescriptor targetDescriptor) {
    if (!targetDescriptor.getTargetTypes().isEmpty()) {
        final JdbcContext jdbcContext = tool.resolveJdbcContext(options.getConfigurationValues());
        final DdlTransactionIsolator ddlTransactionIsolator = tool.getDdlTransactionIsolator(jdbcContext);
        try {
            final DatabaseInformation databaseInformation = Helper.buildDatabaseInformation(tool.getServiceRegistry(), ddlTransactionIsolator, metadata.getDatabase().getDefaultNamespace().getName());
            final GenerationTarget[] targets = tool.buildGenerationTargets(targetDescriptor, ddlTransactionIsolator, options.getConfigurationValues());
            try {
                for (GenerationTarget target : targets) {
                    target.prepare();
                }
                try {
                    performMigration(metadata, databaseInformation, options, jdbcContext.getDialect(), targets);
                } finally {
                    for (GenerationTarget target : targets) {
                        try {
                            target.release();
                        } catch (Exception e) {
                            log.debugf("Problem releasing GenerationTarget [%s] : %s", target, e.getMessage());
                        }
                    }
                }
            } finally {
                try {
                    databaseInformation.cleanup();
                } catch (Exception e) {
                    log.debug("Problem releasing DatabaseInformation : " + e.getMessage());
                }
            }
        } finally {
            ddlTransactionIsolator.release();
        }
    }
}
Also used : DatabaseInformation(org.hibernate.tool.schema.extract.spi.DatabaseInformation) JdbcContext(org.hibernate.tool.schema.internal.exec.JdbcContext) GenerationTarget(org.hibernate.tool.schema.internal.exec.GenerationTarget) DdlTransactionIsolator(org.hibernate.resource.transaction.spi.DdlTransactionIsolator) CommandAcceptanceException(org.hibernate.tool.schema.spi.CommandAcceptanceException) SchemaManagementException(org.hibernate.tool.schema.spi.SchemaManagementException)

Example 4 with JdbcContext

use of org.hibernate.tool.schema.internal.exec.JdbcContext in project hibernate-orm by hibernate.

the class AbstractSchemaValidator method doValidation.

@Override
public void doValidation(Metadata metadata, ExecutionOptions options) {
    final JdbcContext jdbcContext = tool.resolveJdbcContext(options.getConfigurationValues());
    final DdlTransactionIsolator isolator = tool.getDdlTransactionIsolator(jdbcContext);
    final DatabaseInformation databaseInformation = Helper.buildDatabaseInformation(tool.getServiceRegistry(), isolator, metadata.getDatabase().getDefaultNamespace().getName());
    try {
        performValidation(metadata, databaseInformation, options, jdbcContext.getDialect());
    } finally {
        try {
            databaseInformation.cleanup();
        } catch (Exception e) {
            log.debug("Problem releasing DatabaseInformation : " + e.getMessage());
        }
        isolator.release();
    }
}
Also used : DatabaseInformation(org.hibernate.tool.schema.extract.spi.DatabaseInformation) JdbcContext(org.hibernate.tool.schema.internal.exec.JdbcContext) DdlTransactionIsolator(org.hibernate.resource.transaction.spi.DdlTransactionIsolator) SchemaManagementException(org.hibernate.tool.schema.spi.SchemaManagementException)

Example 5 with JdbcContext

use of org.hibernate.tool.schema.internal.exec.JdbcContext in project hibernate-orm by hibernate.

the class SchemaDropperImpl method doDrop.

@Override
public void doDrop(Metadata metadata, ExecutionOptions options, SourceDescriptor sourceDescriptor, TargetDescriptor targetDescriptor) {
    if (targetDescriptor.getTargetTypes().isEmpty()) {
        return;
    }
    final JdbcContext jdbcContext = tool.resolveJdbcContext(options.getConfigurationValues());
    final GenerationTarget[] targets = tool.buildGenerationTargets(targetDescriptor, jdbcContext, options.getConfigurationValues(), true);
    doDrop(metadata, options, jdbcContext.getDialect(), sourceDescriptor, targets);
}
Also used : JdbcContext(org.hibernate.tool.schema.internal.exec.JdbcContext) GenerationTarget(org.hibernate.tool.schema.internal.exec.GenerationTarget)

Aggregations

JdbcContext (org.hibernate.tool.schema.internal.exec.JdbcContext)5 GenerationTarget (org.hibernate.tool.schema.internal.exec.GenerationTarget)3 DdlTransactionIsolator (org.hibernate.resource.transaction.spi.DdlTransactionIsolator)2 DatabaseInformation (org.hibernate.tool.schema.extract.spi.DatabaseInformation)2 SchemaManagementException (org.hibernate.tool.schema.spi.SchemaManagementException)2 Map (java.util.Map)1 TransactionCoordinatorBuilder (org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder)1 SourceType (org.hibernate.tool.schema.SourceType)1 GenerationTargetToDatabase (org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase)1 CommandAcceptanceException (org.hibernate.tool.schema.spi.CommandAcceptanceException)1 ExceptionHandler (org.hibernate.tool.schema.spi.ExceptionHandler)1 ExecutionOptions (org.hibernate.tool.schema.spi.ExecutionOptions)1 ScriptSourceInput (org.hibernate.tool.schema.spi.ScriptSourceInput)1 SourceDescriptor (org.hibernate.tool.schema.spi.SourceDescriptor)1