use of org.hibernate.tool.schema.spi.TargetDescriptor in project hibernate-orm by hibernate.
the class SchemaUpdateTableBackedSequenceTest method testCreateTableOnUpdate.
@Test
public void testCreateTableOnUpdate() throws SQLException {
Metadata metadata = new MetadataSources(ssr).buildMetadata();
Database database = metadata.getDatabase();
TableStructure tableStructure = new TableStructure(database.getJdbcEnvironment(), new QualifiedTableName(null, null, Identifier.toIdentifier("test_seq")), Identifier.toIdentifier("nextval"), 20, 30, Long.class);
tableStructure.registerExportables(database);
// lets make sure the InitCommand is there
assertEquals(1, database.getDefaultNamespace().getTables().size());
Table table = database.getDefaultNamespace().getTables().iterator().next();
assertEquals(1, table.getInitCommands().size());
final TargetImpl target = new TargetImpl();
ssr.getService(SchemaManagementTool.class).getSchemaMigrator(Collections.emptyMap()).doMigration(metadata, new ExecutionOptions() {
@Override
public boolean shouldManageNamespaces() {
return true;
}
@Override
public Map getConfigurationValues() {
return ssr.getService(ConfigurationService.class).getSettings();
}
@Override
public ExceptionHandler getExceptionHandler() {
return ExceptionHandlerLoggedImpl.INSTANCE;
}
}, new TargetDescriptor() {
@Override
public EnumSet<TargetType> getTargetTypes() {
return EnumSet.of(TargetType.SCRIPT, TargetType.DATABASE);
}
@Override
public ScriptTargetOutput getScriptTargetOutput() {
return target;
}
});
assertTrue(target.found);
new SchemaExport().drop(EnumSet.of(TargetType.DATABASE), metadata);
}
use of org.hibernate.tool.schema.spi.TargetDescriptor in project hibernate-orm by hibernate.
the class SchemaExport method execute.
@SuppressWarnings("unchecked")
public void execute(EnumSet<TargetType> targetTypes, Action action, Metadata metadata, ServiceRegistry serviceRegistry) {
if (action == Action.NONE) {
LOG.debug("Skipping SchemaExport as Action.NONE was passed");
return;
}
if (targetTypes.isEmpty()) {
LOG.debug("Skipping SchemaExport as no targets were specified");
return;
}
exceptions.clear();
LOG.runningHbm2ddlSchemaExport();
final TargetDescriptor targetDescriptor = buildTargetDescriptor(targetTypes, outputFile, serviceRegistry);
doExecution(action, needsJdbcConnection(targetTypes), metadata, serviceRegistry, targetDescriptor);
}
use of org.hibernate.tool.schema.spi.TargetDescriptor 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 ExceptionHandler exceptionHandler = haltOnError ? ExceptionHandlerHaltImpl.INSTANCE : 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 {
if (exceptionHandler instanceof ExceptionHandlerCollectingImpl) {
exceptions.addAll(((ExceptionHandlerCollectingImpl) exceptionHandler).getExceptions());
}
}
}
Aggregations