use of org.hibernate.tool.hbm2ddl.SchemaExport in project hibernate-orm by hibernate.
the class SchemaExportTest method setUp.
@Before
public void setUp() {
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry(Environment.getProperties());
metadata = (MetadataImplementor) new MetadataSources(serviceRegistry).addResource("org/hibernate/test/schemaupdate/mapping.hbm.xml").buildMetadata();
metadata.validate();
new SchemaExport().drop(EnumSet.of(TargetType.DATABASE, TargetType.STDOUT), metadata);
}
use of org.hibernate.tool.hbm2ddl.SchemaExport in project hibernate-orm by hibernate.
the class SchemaExportTest method testCreateAndDropOnlyType.
@Test
public void testCreateAndDropOnlyType() {
final SchemaExport schemaExport = new SchemaExport();
// create w/o dropping first; (OK because tables don't exist yet
schemaExport.execute(EnumSet.of(TargetType.DATABASE), SchemaExport.Action.CREATE, metadata);
assertEquals(0, schemaExport.getExceptions().size());
// create w/o dropping again; should cause an exception because the tables exist already
schemaExport.execute(EnumSet.of(TargetType.DATABASE), SchemaExport.Action.CREATE, metadata);
assertEquals(1, schemaExport.getExceptions().size());
// drop tables only
schemaExport.execute(EnumSet.of(TargetType.DATABASE), SchemaExport.Action.DROP, metadata);
assertEquals(0, schemaExport.getExceptions().size());
}
use of org.hibernate.tool.hbm2ddl.SchemaExport in project hibernate-orm by hibernate.
the class SchemaExportTest method testBothType.
@Test
public void testBothType() {
final SchemaExport schemaExport = new SchemaExport();
// drop beforeQuery create (nothing to drop yeT)
schemaExport.execute(EnumSet.of(TargetType.DATABASE), SchemaExport.Action.DROP, metadata);
if (doesDialectSupportDropTableIfExist()) {
assertEquals(0, schemaExport.getExceptions().size());
} else {
assertEquals(1, schemaExport.getExceptions().size());
}
// drop beforeQuery create again (this time drops the tables beforeQuery re-creating)
schemaExport.execute(EnumSet.of(TargetType.DATABASE), SchemaExport.Action.BOTH, metadata);
int exceptionCount = schemaExport.getExceptions().size();
if (doesDialectSupportDropTableIfExist()) {
assertEquals(0, exceptionCount);
}
// drop tables
schemaExport.execute(EnumSet.of(TargetType.DATABASE), SchemaExport.Action.DROP, metadata);
assertEquals(0, schemaExport.getExceptions().size());
}
use of org.hibernate.tool.hbm2ddl.SchemaExport in project hibernate-orm by hibernate.
the class SchemaExportTest method testHibernateMappingSchemaPropertyIsNotIgnored.
@Test
@TestForIssue(jiraKey = "HHH-10678")
@RequiresDialectFeature(value = DialectChecks.SupportSchemaCreation.class)
public void testHibernateMappingSchemaPropertyIsNotIgnored() throws Exception {
File output = File.createTempFile("update_script", ".sql");
output.deleteOnExit();
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(serviceRegistry).addResource("org/hibernate/test/schemaupdate/mapping2.hbm.xml").buildMetadata();
metadata.validate();
final SchemaExport schemaExport = new SchemaExport();
schemaExport.setOutputFile(output.getAbsolutePath());
schemaExport.execute(EnumSet.of(TargetType.SCRIPT), SchemaExport.Action.CREATE, metadata);
String fileContent = new String(Files.readAllBytes(output.toPath()));
assertThat(fileContent, fileContent.toLowerCase().contains("create table schema1.version"), is(true));
}
use of org.hibernate.tool.hbm2ddl.SchemaExport in project hibernate-orm by hibernate.
the class TestFkUpdating method tearDown.
@After
public void tearDown() {
System.out.println("********* Starting SchemaExport (drop) for TEAR-DOWN *************************");
new SchemaExport().drop(EnumSet.of(TargetType.DATABASE, TargetType.STDOUT), metadata);
System.out.println("********* Completed SchemaExport (drop) for TEAR-DOWN *************************");
StandardServiceRegistryBuilder.destroy(serviceRegistry);
serviceRegistry = null;
}
Aggregations