Search in sources :

Example 1 with GenerationTarget

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

the class HibernateSchemaManagementTool method buildGenerationTargets.

GenerationTarget[] buildGenerationTargets(TargetDescriptor targetDescriptor, DdlTransactionIsolator ddlTransactionIsolator, Map options) {
    final String scriptDelimiter = ConfigurationHelper.getString(HBM2DDL_DELIMITER, options);
    final GenerationTarget[] targets = new GenerationTarget[targetDescriptor.getTargetTypes().size()];
    int index = 0;
    if (targetDescriptor.getTargetTypes().contains(TargetType.STDOUT)) {
        targets[index] = new GenerationTargetToStdout(scriptDelimiter);
        index++;
    }
    if (targetDescriptor.getTargetTypes().contains(TargetType.SCRIPT)) {
        if (targetDescriptor.getScriptTargetOutput() == null) {
            throw new SchemaManagementException("Writing to script was requested, but no script file was specified");
        }
        targets[index] = new GenerationTargetToScript(targetDescriptor.getScriptTargetOutput(), scriptDelimiter);
        index++;
    }
    if (targetDescriptor.getTargetTypes().contains(TargetType.DATABASE)) {
        targets[index] = new GenerationTargetToDatabase(ddlTransactionIsolator, false);
    }
    return targets;
}
Also used : GenerationTargetToStdout(org.hibernate.tool.schema.internal.exec.GenerationTargetToStdout) SchemaManagementException(org.hibernate.tool.schema.spi.SchemaManagementException) GenerationTarget(org.hibernate.tool.schema.internal.exec.GenerationTarget) GenerationTargetToScript(org.hibernate.tool.schema.internal.exec.GenerationTargetToScript) GenerationTargetToDatabase(org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase)

Example 2 with GenerationTarget

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

the class HibernateSchemaManagementTool method buildGenerationTargets.

GenerationTarget[] buildGenerationTargets(TargetDescriptor targetDescriptor, JdbcContext jdbcContext, Map options, boolean needsAutoCommit) {
    final String scriptDelimiter = ConfigurationHelper.getString(HBM2DDL_DELIMITER, options);
    final GenerationTarget[] targets = new GenerationTarget[targetDescriptor.getTargetTypes().size()];
    int index = 0;
    if (targetDescriptor.getTargetTypes().contains(TargetType.STDOUT)) {
        targets[index] = new GenerationTargetToStdout(scriptDelimiter);
        index++;
    }
    if (targetDescriptor.getTargetTypes().contains(TargetType.SCRIPT)) {
        if (targetDescriptor.getScriptTargetOutput() == null) {
            throw new SchemaManagementException("Writing to script was requested, but no script file was specified");
        }
        targets[index] = new GenerationTargetToScript(targetDescriptor.getScriptTargetOutput(), scriptDelimiter);
        index++;
    }
    if (targetDescriptor.getTargetTypes().contains(TargetType.DATABASE)) {
        targets[index] = new GenerationTargetToDatabase(getDdlTransactionIsolator(jdbcContext), true);
    }
    return targets;
}
Also used : GenerationTargetToStdout(org.hibernate.tool.schema.internal.exec.GenerationTargetToStdout) SchemaManagementException(org.hibernate.tool.schema.spi.SchemaManagementException) GenerationTarget(org.hibernate.tool.schema.internal.exec.GenerationTarget) GenerationTargetToScript(org.hibernate.tool.schema.internal.exec.GenerationTargetToScript) GenerationTargetToDatabase(org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase)

Example 3 with GenerationTarget

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

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

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

GenerationTarget (org.hibernate.tool.schema.internal.exec.GenerationTarget)6 GenerationTargetToDatabase (org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase)3 JdbcContext (org.hibernate.tool.schema.internal.exec.JdbcContext)3 SchemaManagementException (org.hibernate.tool.schema.spi.SchemaManagementException)3 GenerationTargetToScript (org.hibernate.tool.schema.internal.exec.GenerationTargetToScript)2 GenerationTargetToStdout (org.hibernate.tool.schema.internal.exec.GenerationTargetToStdout)2 HibernateException (org.hibernate.HibernateException)1 Metadata (org.hibernate.boot.Metadata)1 MetadataSources (org.hibernate.boot.MetadataSources)1 ConnectionProvider (org.hibernate.engine.jdbc.connections.spi.ConnectionProvider)1 DdlTransactionIsolator (org.hibernate.resource.transaction.spi.DdlTransactionIsolator)1 DdlTransactionIsolatorTestingImpl (org.hibernate.test.util.DdlTransactionIsolatorTestingImpl)1 TestForIssue (org.hibernate.testing.TestForIssue)1 SchemaValidator (org.hibernate.tool.hbm2ddl.SchemaValidator)1 DatabaseInformation (org.hibernate.tool.schema.extract.spi.DatabaseInformation)1 SchemaCreatorImpl (org.hibernate.tool.schema.internal.SchemaCreatorImpl)1 SchemaDropperImpl (org.hibernate.tool.schema.internal.SchemaDropperImpl)1 CommandAcceptanceException (org.hibernate.tool.schema.spi.CommandAcceptanceException)1 Test (org.junit.Test)1