use of org.hibernate.tool.hbm2ddl.SchemaExport 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.tool.hbm2ddl.SchemaExport in project hibernate-orm by hibernate.
the class ForeignKeyMigrationTest method testMigrationOfForeignKeys.
@Test
@TestForIssue(jiraKey = "HHH-9716")
public // @FailureExpected( jiraKey = "HHH-9716" )
void testMigrationOfForeignKeys() {
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
try {
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(Box.class).addAnnotatedClass(Thing.class).buildMetadata();
metadata.validate();
// first create the schema...
new SchemaExport().create(EnumSet.of(TargetType.DATABASE), metadata);
try {
// try to update the just created schema
new SchemaUpdate().execute(EnumSet.of(TargetType.DATABASE), metadata);
} finally {
// clean up
new SchemaExport().drop(EnumSet.of(TargetType.DATABASE), metadata);
}
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.tool.hbm2ddl.SchemaExport 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.tool.hbm2ddl.SchemaExport in project hibernate-orm by hibernate.
the class SchemaUpdateWithKeywordAutoQuotingEnabledTest method tearsDown.
@After
public void tearsDown() {
new SchemaExport().setHaltOnError(true).setFormat(false).drop(EnumSet.of(TargetType.DATABASE), metadata);
StandardServiceRegistryBuilder.destroy(ssr);
}
use of org.hibernate.tool.hbm2ddl.SchemaExport 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));
}
Aggregations