use of org.hibernate.boot.MetadataSources in project hibernate-orm by hibernate.
the class ForeignKeyGenerationTest method createSchema.
private void createSchema(Class[] annotatedClasses) {
final MetadataSources metadataSources = new MetadataSources(ssr);
for (Class c : annotatedClasses) {
metadataSources.addAnnotatedClass(c);
}
metadata = (MetadataImplementor) metadataSources.buildMetadata();
metadata.validate();
new SchemaExport().setHaltOnError(true).setOutputFile(output.getAbsolutePath()).setFormat(false).create(EnumSet.of(TargetType.SCRIPT), metadata);
}
use of org.hibernate.boot.MetadataSources in project hibernate-orm by hibernate.
the class SchemaUpdateWithKeywordAutoQuotingEnabledTest method setUp.
@Before
public void setUp() throws IOException {
final StandardServiceRegistryBuilder standardServiceRegistryBuilder = new StandardServiceRegistryBuilder();
standardServiceRegistryBuilder.applySetting(org.hibernate.cfg.AvailableSettings.KEYWORD_AUTO_QUOTING_ENABLED, "true");
ssr = standardServiceRegistryBuilder.build();
final MetadataSources metadataSources = new MetadataSources(ssr);
metadataSources.addAnnotatedClass(Match.class);
metadata = (MetadataImplementor) metadataSources.buildMetadata();
metadata.validate();
new SchemaExport().setHaltOnError(true).setFormat(false).createOnly(EnumSet.of(TargetType.DATABASE), metadata);
}
use of org.hibernate.boot.MetadataSources in project hibernate-orm by hibernate.
the class CrossSchemaForeignKeyGenerationTest method testSchemaExportForeignKeysAreGeneratedAfterAllTheTablesAreCreated.
@Test
@TestForIssue(jiraKey = "HHH-10420")
public void testSchemaExportForeignKeysAreGeneratedAfterAllTheTablesAreCreated() throws Exception {
final MetadataSources metadataSources = new MetadataSources(ssr);
metadataSources.addAnnotatedClass(SchemaOneEntity.class);
metadataSources.addAnnotatedClass(SchemaTwoEntity.class);
MetadataImplementor metadata = (MetadataImplementor) metadataSources.buildMetadata();
metadata.validate();
new SchemaExport().setHaltOnError(true).setOutputFile(output.getAbsolutePath()).setFormat(false).create(EnumSet.of(TargetType.SCRIPT, TargetType.STDOUT), metadata);
final List<String> sqlLines = Files.readAllLines(output.toPath(), Charset.defaultCharset());
assertThat("Expected alter table SCHEMA1.Child add constraint but is : " + sqlLines.get(4), sqlLines.get(sqlLines.size() - 1).startsWith("alter table "), is(true));
}
use of org.hibernate.boot.MetadataSources 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.boot.MetadataSources in project hibernate-orm by hibernate.
the class SchemaUpdate method buildMetadata.
private static MetadataImplementor buildMetadata(CommandLineArgs parsedArgs, ServiceRegistry serviceRegistry) throws Exception {
final MetadataSources metadataSources = new MetadataSources(serviceRegistry);
for (String filename : parsedArgs.hbmXmlFiles) {
metadataSources.addFile(filename);
}
for (String filename : parsedArgs.jarFiles) {
metadataSources.addJar(new File(filename));
}
final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder();
final StrategySelector strategySelector = serviceRegistry.getService(StrategySelector.class);
if (parsedArgs.implicitNamingStrategyImplName != null) {
metadataBuilder.applyImplicitNamingStrategy(strategySelector.resolveStrategy(ImplicitNamingStrategy.class, parsedArgs.implicitNamingStrategyImplName));
}
if (parsedArgs.physicalNamingStrategyImplName != null) {
metadataBuilder.applyPhysicalNamingStrategy(strategySelector.resolveStrategy(PhysicalNamingStrategy.class, parsedArgs.physicalNamingStrategyImplName));
}
return (MetadataImplementor) metadataBuilder.build();
}
Aggregations