Search in sources :

Example 16 with SchemaUpdate

use of org.hibernate.tool.hbm2ddl.SchemaUpdate in project hibernate-orm by hibernate.

the class InheritanceSchemaUpdateTest method testBidirectionalOneToManyReferencingRootEntity.

@Test
public void testBidirectionalOneToManyReferencingRootEntity() throws Exception {
    StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
    MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(Step.class).addAnnotatedClass(GroupStep.class).buildMetadata();
    metadata.validate();
    try {
        try {
            new SchemaUpdate().execute(EnumSet.of(TargetType.DATABASE), metadata);
        } finally {
            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)

Example 17 with SchemaUpdate

use of org.hibernate.tool.hbm2ddl.SchemaUpdate in project hibernate-orm by hibernate.

the class TestFkUpdating method testUpdate.

@Test
public void testUpdate() {
    System.out.println("********* Starting SchemaUpdate for TEST *************************");
    new SchemaUpdate().execute(EnumSet.of(TargetType.DATABASE, TargetType.STDOUT), metadata);
    System.out.println("********* Completed SchemaUpdate for TEST *************************");
}
Also used : SchemaUpdate(org.hibernate.tool.hbm2ddl.SchemaUpdate) Test(org.junit.Test)

Example 18 with SchemaUpdate

use of org.hibernate.tool.hbm2ddl.SchemaUpdate in project hibernate-orm by hibernate.

the class CrossSchemaForeignKeyGenerationTest method testSchemaUpdateDoesNotFailResolvingCrossSchemaForeignKey.

@Test
@TestForIssue(jiraKey = "HHH-10802")
public void testSchemaUpdateDoesNotFailResolvingCrossSchemaForeignKey() 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().setOutputFile(output.getAbsolutePath()).setFormat(false).create(EnumSet.of(TargetType.DATABASE), metadata);
    new SchemaUpdate().setHaltOnError(true).setOutputFile(output.getAbsolutePath()).setFormat(false).execute(EnumSet.of(TargetType.DATABASE), metadata);
    new SchemaExport().setHaltOnError(true).setOutputFile(output.getAbsolutePath()).setFormat(false).drop(EnumSet.of(TargetType.DATABASE), metadata);
}
Also used : MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) SchemaUpdate(org.hibernate.tool.hbm2ddl.SchemaUpdate) SchemaExport(org.hibernate.tool.hbm2ddl.SchemaExport) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 19 with SchemaUpdate

use of org.hibernate.tool.hbm2ddl.SchemaUpdate in project hibernate-orm by hibernate.

the class SchemaUpdateDelimiterTest method testSchemaUpdateApplyDelimiterToGeneratedSQL.

@Test
public void testSchemaUpdateApplyDelimiterToGeneratedSQL() 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(EXPECTED_DELIMITER).setFormat(false).execute(EnumSet.of(TargetType.SCRIPT), metadata);
        List<String> sqlLines = Files.readAllLines(output.toPath(), Charset.defaultCharset());
        for (String line : sqlLines) {
            assertThat("The expected delimiter is not applied " + line, line.endsWith(EXPECTED_DELIMITER), is(true));
        }
    } 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) File(java.io.File) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test)

Example 20 with SchemaUpdate

use of org.hibernate.tool.hbm2ddl.SchemaUpdate in project hibernate-orm by hibernate.

the class MigrationTest method testSimpleColumnAddition.

@Test
public void testSimpleColumnAddition() {
    String resource1 = "org/hibernate/test/schemaupdate/1_Version.hbm.xml";
    String resource2 = "org/hibernate/test/schemaupdate/2_Version.hbm.xml";
    MetadataImplementor v1metadata = (MetadataImplementor) new MetadataSources(serviceRegistry).addResource(resource1).buildMetadata();
    new SchemaExport().drop(EnumSet.of(TargetType.DATABASE), v1metadata);
    final SchemaUpdate v1schemaUpdate = new SchemaUpdate();
    v1schemaUpdate.execute(EnumSet.of(TargetType.DATABASE, TargetType.STDOUT), v1metadata);
    assertEquals(0, v1schemaUpdate.getExceptions().size());
    MetadataImplementor v2metadata = (MetadataImplementor) new MetadataSources(serviceRegistry).addResource(resource2).buildMetadata();
    final SchemaUpdate v2schemaUpdate = new SchemaUpdate();
    v2schemaUpdate.execute(EnumSet.of(TargetType.DATABASE, TargetType.STDOUT), v2metadata);
    assertEquals(0, v2schemaUpdate.getExceptions().size());
    new SchemaExport().drop(EnumSet.of(TargetType.DATABASE), v2metadata);
}
Also used : MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) SchemaUpdate(org.hibernate.tool.hbm2ddl.SchemaUpdate) SchemaExport(org.hibernate.tool.hbm2ddl.SchemaExport) Test(org.junit.Test)

Aggregations

SchemaUpdate (org.hibernate.tool.hbm2ddl.SchemaUpdate)25 Test (org.junit.Test)23 MetadataSources (org.hibernate.boot.MetadataSources)20 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)20 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)15 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)15 SchemaExport (org.hibernate.tool.hbm2ddl.SchemaExport)9 File (java.io.File)7 TestForIssue (org.hibernate.testing.TestForIssue)7 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 SchemaValidator (org.hibernate.tool.hbm2ddl.SchemaValidator)2 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)1 Holder (com.evolveum.midpoint.util.Holder)1 IOException (java.io.IOException)1 Connection (java.sql.Connection)1 DatabaseMetaData (java.sql.DatabaseMetaData)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1