use of org.hibernate.tool.hbm2ddl.SchemaUpdate in project hibernate-orm by hibernate.
the class QuotedTableNameWithForeignKeysSchemaUpdateTest method setUp.
@Before
public void setUp() {
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
try {
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addResource("org/hibernate/test/schemaupdate/UserGroup.hbm.xml").buildMetadata();
metadata.validate();
new SchemaUpdate().execute(EnumSet.of(TargetType.DATABASE), metadata);
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.tool.hbm2ddl.SchemaUpdate in project hibernate-orm by hibernate.
the class QuotedTableNameWithForeignKeysSchemaUpdateTest method testGeneratingUpdateScript.
@Test
public void testGeneratingUpdateScript() {
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
try {
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addResource("org/hibernate/test/schemaupdate/UserGroup.hbm.xml").buildMetadata();
new SchemaUpdate().execute(EnumSet.of(TargetType.STDOUT), metadata);
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.tool.hbm2ddl.SchemaUpdate in project hibernate-orm by hibernate.
the class SqlServerQuoteSchemaTest method test.
@Test
public void test() {
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.GLOBALLY_QUOTED_IDENTIFIERS, Boolean.TRUE.toString()).build();
try {
output.deleteOnExit();
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(MyEntity.class).buildMetadata();
metadata.validate();
new SchemaUpdate().setHaltOnError(true).setOutputFile(output.getAbsolutePath()).setDelimiter(";").setFormat(true).execute(EnumSet.of(TargetType.DATABASE, TargetType.SCRIPT), metadata);
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
try {
String fileContent = new String(Files.readAllBytes(output.toPath()));
Pattern fileContentPattern = Pattern.compile("create table \\[my\\-schema\\]\\.\\[my_entity\\]");
Matcher fileContentMatcher = fileContentPattern.matcher(fileContent.toLowerCase());
assertThat(fileContentMatcher.find(), is(true));
} catch (IOException e) {
fail(e.getMessage());
}
ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.GLOBALLY_QUOTED_IDENTIFIERS, Boolean.TRUE.toString()).build();
try {
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(MyEntityUpdated.class).buildMetadata();
metadata.validate();
new SchemaUpdate().setHaltOnError(true).setOutputFile(output.getAbsolutePath()).setDelimiter(";").setFormat(true).execute(EnumSet.of(TargetType.DATABASE, TargetType.SCRIPT), metadata);
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
try {
String fileContent = new String(Files.readAllBytes(output.toPath()));
Pattern fileContentPattern = Pattern.compile("alter table .*?\\.\\[my\\-schema\\]\\.\\[my_entity\\]");
Matcher fileContentMatcher = fileContentPattern.matcher(fileContent.toLowerCase());
assertThat(fileContentMatcher.find(), is(true));
} catch (IOException e) {
fail(e.getMessage());
}
}
use of org.hibernate.tool.hbm2ddl.SchemaUpdate in project hibernate-orm by hibernate.
the class SchemaUpdateFormatterTest method testSetFormat.
@Test
public void testSetFormat() throws Exception {
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(Environment.HBM2DDL_AUTO, "none").build();
try {
File output = File.createTempFile("update_script", ".sql");
output.deleteOnExit();
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(TestEntity.class).buildMetadata();
metadata.validate();
new SchemaUpdate().setHaltOnError(true).setOutputFile(output.getAbsolutePath()).setDelimiter(DELIMITER).setFormat(true).execute(EnumSet.of(TargetType.SCRIPT), metadata);
String outputContent = new String(Files.readAllBytes(output.toPath()));
// Old Macs use \r as a new line delimiter
outputContent = outputContent.replaceAll("\r", "\n");
// On Windows, \r\n would become \n\n, so we eliminate duplicates
outputContent = outputContent.replaceAll("\n\n", "\n");
Assert.assertTrue(Pattern.compile(AFTER_FORMAT).matcher(outputContent).matches());
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.tool.hbm2ddl.SchemaUpdate 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);
}
}
Aggregations