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;
}
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;
}
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);
}
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();
}
}
}
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);
}
Aggregations