Search in sources :

Example 11 with SchemaExport

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);
}
Also used : MetadataSources(org.hibernate.boot.MetadataSources) SchemaExport(org.hibernate.tool.hbm2ddl.SchemaExport) Before(org.junit.Before)

Example 12 with SchemaExport

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());
}
Also used : SchemaExport(org.hibernate.tool.hbm2ddl.SchemaExport) Test(org.junit.Test)

Example 13 with SchemaExport

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());
}
Also used : SchemaExport(org.hibernate.tool.hbm2ddl.SchemaExport) Test(org.junit.Test)

Example 14 with SchemaExport

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));
}
Also used : MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) File(java.io.File) SchemaExport(org.hibernate.tool.hbm2ddl.SchemaExport) Test(org.junit.Test) RequiresDialectFeature(org.hibernate.testing.RequiresDialectFeature) TestForIssue(org.hibernate.testing.TestForIssue)

Example 15 with SchemaExport

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;
}
Also used : SchemaExport(org.hibernate.tool.hbm2ddl.SchemaExport) After(org.junit.After)

Aggregations

SchemaExport (org.hibernate.tool.hbm2ddl.SchemaExport)46 MetadataSources (org.hibernate.boot.MetadataSources)30 Test (org.junit.Test)22 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)16 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)15 TestForIssue (org.hibernate.testing.TestForIssue)12 SchemaUpdate (org.hibernate.tool.hbm2ddl.SchemaUpdate)9 After (org.junit.After)9 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)8 Before (org.junit.Before)7 File (java.io.File)3 SQLException (java.sql.SQLException)2 Map (java.util.Map)2 Table (org.hibernate.mapping.Table)2 MidPointNamingStrategy (com.evolveum.midpoint.repo.sql.util.MidPointNamingStrategy)1 Connection (java.sql.Connection)1 EnumSet (java.util.EnumSet)1 Entity (javax.persistence.Entity)1 OrderColumn (javax.persistence.OrderColumn)1 Metadata (org.hibernate.boot.Metadata)1