Search in sources :

Example 16 with SchemaExport

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

Example 17 with SchemaExport

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);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) SchemaUpdate(org.hibernate.tool.hbm2ddl.SchemaUpdate) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) SchemaExport(org.hibernate.tool.hbm2ddl.SchemaExport) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 18 with SchemaExport

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

Example 19 with SchemaExport

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

Example 20 with SchemaExport

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

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