use of org.hibernate.tool.schema.SourceType in project hibernate-orm by hibernate.
the class CrossSchemaForeignKeyGenerationTest method testImprovedSchemaMigrationForeignKeysAreGeneratedAfterAllTheTablesAreCreated.
@Test
@TestForIssue(jiraKey = "HHH-10420")
public void testImprovedSchemaMigrationForeignKeysAreGeneratedAfterAllTheTablesAreCreated() throws Exception {
final MetadataSources metadataSources = new MetadataSources(ssr);
metadataSources.addAnnotatedClass(SchemaOneEntity.class);
metadataSources.addAnnotatedClass(SchemaTwoEntity.class);
MetadataImplementor metadata = (MetadataImplementor) metadataSources.buildMetadata();
metadata.validate();
final HibernateSchemaManagementTool tool = (HibernateSchemaManagementTool) ssr.getService(SchemaManagementTool.class);
final Map configurationValues = ssr.getService(ConfigurationService.class).getSettings();
final ExecutionOptions options = new ExecutionOptions() {
@Override
public boolean shouldManageNamespaces() {
return true;
}
@Override
public Map getConfigurationValues() {
return configurationValues;
}
@Override
public ExceptionHandler getExceptionHandler() {
return ExceptionHandlerLoggedImpl.INSTANCE;
}
};
new GroupedSchemaMigratorImpl(tool, DefaultSchemaFilter.INSTANCE).doMigration(metadata, options, TargetDescriptorImpl.INSTANCE);
new SchemaDropperImpl(tool).doDrop(metadata, options, ssr.getService(JdbcEnvironment.class).getDialect(), new SourceDescriptor() {
@Override
public SourceType getSourceType() {
return SourceType.METADATA;
}
@Override
public ScriptSourceInput getScriptSourceInput() {
return null;
}
}, buildTargets());
}
use of org.hibernate.tool.schema.SourceType 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);
}
use of org.hibernate.tool.schema.SourceType in project hibernate-orm by hibernate.
the class SchemaManagementToolCoordinator method buildScriptTargetDescriptor.
private static JpaTargetAndSourceDescriptor buildScriptTargetDescriptor(Map configurationValues, SettingSelector settingSelector, ServiceRegistry serviceRegistry) {
final Object scriptSourceSetting = settingSelector.getScriptSourceSetting(configurationValues);
final SourceType sourceType = SourceType.interpret(settingSelector.getSourceTypeSetting(configurationValues), scriptSourceSetting != null ? SourceType.SCRIPT : SourceType.METADATA);
final boolean includesScripts = sourceType != SourceType.METADATA;
if (includesScripts && scriptSourceSetting == null) {
throw new SchemaManagementException("Schema generation configuration indicated to include CREATE scripts, but no script was specified");
}
String charsetName = (String) configurationValues.get(AvailableSettings.HBM2DDL_CHARSET_NAME);
final ScriptSourceInput scriptSourceInput = includesScripts ? Helper.interpretScriptSourceSetting(scriptSourceSetting, serviceRegistry.getService(ClassLoaderService.class), charsetName) : null;
final ScriptTargetOutput scriptTargetOutput = Helper.interpretScriptTargetSetting(settingSelector.getScriptTargetSetting(configurationValues), serviceRegistry.getService(ClassLoaderService.class), charsetName);
return new JpaTargetAndSourceDescriptor() {
@Override
public EnumSet<TargetType> getTargetTypes() {
return EnumSet.of(TargetType.SCRIPT);
}
@Override
public ScriptTargetOutput getScriptTargetOutput() {
return scriptTargetOutput;
}
@Override
public SourceType getSourceType() {
return sourceType;
}
@Override
public ScriptSourceInput getScriptSourceInput() {
return scriptSourceInput;
}
};
}
use of org.hibernate.tool.schema.SourceType in project hibernate-orm by hibernate.
the class SchemaManagementToolCoordinator method buildDatabaseTargetDescriptor.
private static JpaTargetAndSourceDescriptor buildDatabaseTargetDescriptor(Map configurationValues, SettingSelector settingSelector, ServiceRegistry serviceRegistry) {
final Object scriptSourceSetting = settingSelector.getScriptSourceSetting(configurationValues);
final SourceType sourceType = SourceType.interpret(settingSelector.getSourceTypeSetting(configurationValues), scriptSourceSetting != null ? SourceType.SCRIPT : SourceType.METADATA);
final boolean includesScripts = sourceType != SourceType.METADATA;
if (includesScripts && scriptSourceSetting == null) {
throw new SchemaManagementException("Schema generation configuration indicated to include CREATE scripts, but no script was specified");
}
final ScriptSourceInput scriptSourceInput = includesScripts ? Helper.interpretScriptSourceSetting(scriptSourceSetting, serviceRegistry.getService(ClassLoaderService.class), (String) configurationValues.get(AvailableSettings.HBM2DDL_CHARSET_NAME)) : null;
return new JpaTargetAndSourceDescriptor() {
@Override
public EnumSet<TargetType> getTargetTypes() {
return EnumSet.of(TargetType.DATABASE);
}
@Override
public ScriptTargetOutput getScriptTargetOutput() {
return null;
}
@Override
public SourceType getSourceType() {
return sourceType;
}
@Override
public ScriptSourceInput getScriptSourceInput() {
return scriptSourceInput;
}
};
}
use of org.hibernate.tool.schema.SourceType in project hibernate-orm by hibernate.
the class CrossSchemaForeignKeyGenerationTest method testSchemaMigrationForeignKeysAreGeneratedAfterAllTheTablesAreCreated.
@Test
@TestForIssue(jiraKey = "HHH-10420")
public void testSchemaMigrationForeignKeysAreGeneratedAfterAllTheTablesAreCreated() throws Exception {
final MetadataSources metadataSources = new MetadataSources(ssr);
metadataSources.addAnnotatedClass(SchemaOneEntity.class);
metadataSources.addAnnotatedClass(SchemaTwoEntity.class);
MetadataImplementor metadata = (MetadataImplementor) metadataSources.buildMetadata();
metadata.validate();
final Database database = metadata.getDatabase();
final HibernateSchemaManagementTool tool = (HibernateSchemaManagementTool) ssr.getService(SchemaManagementTool.class);
final Map configurationValues = ssr.getService(ConfigurationService.class).getSettings();
final ExecutionOptions options = new ExecutionOptions() {
@Override
public boolean shouldManageNamespaces() {
return true;
}
@Override
public Map getConfigurationValues() {
return configurationValues;
}
@Override
public ExceptionHandler getExceptionHandler() {
return ExceptionHandlerLoggedImpl.INSTANCE;
}
};
new IndividuallySchemaMigratorImpl(tool, DefaultSchemaFilter.INSTANCE).doMigration(metadata, options, TargetDescriptorImpl.INSTANCE);
new IndividuallySchemaMigratorImpl(tool, DefaultSchemaFilter.INSTANCE).doMigration(metadata, options, TargetDescriptorImpl.INSTANCE);
new SchemaDropperImpl(tool).doDrop(metadata, options, ssr.getService(JdbcEnvironment.class).getDialect(), new SourceDescriptor() {
@Override
public SourceType getSourceType() {
return SourceType.METADATA;
}
@Override
public ScriptSourceInput getScriptSourceInput() {
return null;
}
}, buildTargets());
}
Aggregations