Search in sources :

Example 41 with SchemaExport

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

the class SQLServer2008NVarCharTypeTest method createSchemaExport.

private SchemaExport createSchemaExport(Class[] annotatedClasses) {
    final MetadataSources metadataSources = new MetadataSources(ssr);
    for (Class c : annotatedClasses) {
        metadataSources.addAnnotatedClass(c);
    }
    metadata = (MetadataImplementor) metadataSources.buildMetadata();
    metadata.validate();
    SchemaExport schemaExport = new SchemaExport();
    schemaExport.setHaltOnError(true).setFormat(false);
    return schemaExport;
}
Also used : MetadataSources(org.hibernate.boot.MetadataSources) SchemaExport(org.hibernate.tool.hbm2ddl.SchemaExport)

Example 42 with SchemaExport

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

the class DisabledForeignKeyTest method basicTests.

@Test
@TestForIssue(jiraKey = "HHH-9704")
public void basicTests() {
    StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder();
    StandardServiceRegistry standardRegistry = registryBuilder.build();
    try {
        final MetadataSources sources = new MetadataSources(standardRegistry);
        sources.addAnnotatedClass(ManyToManyOwner.class);
        sources.addAnnotatedClass(ManyToManyTarget.class);
        final MetadataImplementor metadata = (MetadataImplementor) sources.buildMetadata();
        metadata.validate();
        new SchemaExport().execute(EnumSet.of(TargetType.STDOUT), SchemaExport.Action.CREATE, metadata);
        int fkCount = 0;
        for (Table table : metadata.collectTableMappings()) {
            for (Map.Entry<ForeignKeyKey, ForeignKey> entry : table.getForeignKeys().entrySet()) {
                assertFalse("Creation for ForeignKey [" + entry.getKey() + "] was not disabled", entry.getValue().isCreationEnabled());
                fkCount++;
            }
        }
        // ultimately I want to actually create the ForeignKet reference, but simply disable its creation
        // via ForeignKet#disableCreation()
        assertEquals("Was expecting 4 FKs", 0, fkCount);
    } finally {
        StandardServiceRegistryBuilder.destroy(standardRegistry);
    }
}
Also used : ForeignKeyKey(org.hibernate.mapping.Table.ForeignKeyKey) Table(org.hibernate.mapping.Table) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) ForeignKey(org.hibernate.mapping.ForeignKey) Map(java.util.Map) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) SchemaExport(org.hibernate.tool.hbm2ddl.SchemaExport) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 43 with SchemaExport

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

the class CollectionJoinTableNamingTest method assertSameTableUsed.

private void assertSameTableUsed(Metadata metadata) {
    Collection inputs1Mapping = metadata.getCollectionBinding(Ptx.class.getName() + ".inputs1");
    assertEquals("ptx_input", inputs1Mapping.getCollectionTable().getName());
    Collection inputs2Mapping = metadata.getCollectionBinding(Ptx.class.getName() + ".inputs2");
    assertEquals("ptx_input", inputs2Mapping.getCollectionTable().getName());
    assertSame(inputs1Mapping.getCollectionTable(), inputs2Mapping.getCollectionTable());
    // NOTE : here so that tester can more easily see the produced table. It is only dumped to stdout
    new SchemaExport().create(EnumSet.of(TargetType.STDOUT), metadata);
    for (int i = 0; i < inputs1Mapping.getCollectionTable().getColumnSpan(); i++) {
        final Column column = inputs1Mapping.getCollectionTable().getColumn(i);
        // this, coupled with JPA saying the 2 collections implicitly map to the same table,
        // is the crux of the problem: all columns are null, so we effectively can never
        // insert rows into it.
        assertFalse(column.isNullable());
    }
}
Also used : Column(org.hibernate.mapping.Column) OrderColumn(javax.persistence.OrderColumn) Collection(org.hibernate.mapping.Collection) SchemaExport(org.hibernate.tool.hbm2ddl.SchemaExport)

Example 44 with SchemaExport

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

the class ColumnNamesTest method setUp.

@Before
public void setUp() throws IOException {
    ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.KEYWORD_AUTO_QUOTING_ENABLED, "true").applySetting(AvailableSettings.HBM2DDL_JDBC_METADATA_EXTRACTOR_STRATEGY, jdbcMetadataExtractorStrategy).build();
    output = File.createTempFile("update_script", ".sql");
    output.deleteOnExit();
    metadata = new MetadataSources(ssr).addAnnotatedClass(Employee.class).buildMetadata();
    new SchemaExport().create(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 45 with SchemaExport

use of org.hibernate.tool.hbm2ddl.SchemaExport 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

SchemaExport (org.hibernate.tool.hbm2ddl.SchemaExport)48 MetadataSources (org.hibernate.boot.MetadataSources)31 Test (org.junit.Test)22 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)17 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)17 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)4 SQLException (java.sql.SQLException)2 Map (java.util.Map)2 Entity (javax.persistence.Entity)2 Table (org.hibernate.mapping.Table)2 ServiceRegistry (org.hibernate.service.ServiceRegistry)2 MidPointNamingStrategy (com.evolveum.midpoint.repo.sql.util.MidPointNamingStrategy)1 Connection (java.sql.Connection)1 EnumSet (java.util.EnumSet)1 MappedSuperclass (javax.persistence.MappedSuperclass)1