Search in sources :

Example 41 with MetadataImplementor

use of org.hibernate.boot.spi.MetadataImplementor in project hibernate-orm by hibernate.

the class ForeignKeyNameTest method testSubclassForeignKeyNameIsNotAutoGeneratedWhenProvided.

@Test
public void testSubclassForeignKeyNameIsNotAutoGeneratedWhenProvided() 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).addResource("org/hibernate/test/schemaupdate/inheritance/Payment.hbm.xml").buildMetadata();
        metadata.validate();
        new SchemaUpdate().setHaltOnError(true).setOutputFile(output.getAbsolutePath()).setDelimiter(";").setFormat(true).execute(EnumSet.of(TargetType.SCRIPT), metadata);
        String fileContent = new String(Files.readAllBytes(output.toPath()));
        assertThat(fileContent.toLowerCase().contains("fk_cc_pay"), 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 42 with MetadataImplementor

use of org.hibernate.boot.spi.MetadataImplementor 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 43 with MetadataImplementor

use of org.hibernate.boot.spi.MetadataImplementor in project hibernate-orm by hibernate.

the class CrossSchemaForeignKeyGenerationTest method testSchemaMigrationForeignKeysAreGeneratedAfterAllTheTablesAreCreated.

@Test
@TestForIssue(jiraKey = "HHH-10420")
public void testSchemaMigrationForeignKeysAreGeneratedAfterAllTheTablesAreCreated() throws Exception {
    final MetadataSources metadataSources = new MetadataSources(ssr);
    metadataSources.addAnnotatedClass(SchemaOneEntity.class);
    metadataSources.addAnnotatedClass(SchemaTwoEntity.class);
    MetadataImplementor metadata = (MetadataImplementor) metadataSources.buildMetadata();
    metadata.validate();
    final Database database = metadata.getDatabase();
    final HibernateSchemaManagementTool tool = (HibernateSchemaManagementTool) ssr.getService(SchemaManagementTool.class);
    final Map configurationValues = ssr.getService(ConfigurationService.class).getSettings();
    final ExecutionOptions options = new ExecutionOptions() {

        @Override
        public boolean shouldManageNamespaces() {
            return true;
        }

        @Override
        public Map getConfigurationValues() {
            return configurationValues;
        }

        @Override
        public ExceptionHandler getExceptionHandler() {
            return ExceptionHandlerLoggedImpl.INSTANCE;
        }
    };
    new IndividuallySchemaMigratorImpl(tool, DefaultSchemaFilter.INSTANCE).doMigration(metadata, options, TargetDescriptorImpl.INSTANCE);
    new SchemaDropperImpl(tool).doDrop(metadata, options, ssr.getService(JdbcEnvironment.class).getDialect(), new SourceDescriptor() {

        @Override
        public SourceType getSourceType() {
            return SourceType.METADATA;
        }

        @Override
        public ScriptSourceInput getScriptSourceInput() {
            return null;
        }
    }, buildTargets());
}
Also used : HibernateSchemaManagementTool(org.hibernate.tool.schema.internal.HibernateSchemaManagementTool) SchemaManagementTool(org.hibernate.tool.schema.spi.SchemaManagementTool) SourceDescriptor(org.hibernate.tool.schema.spi.SourceDescriptor) ScriptSourceInput(org.hibernate.tool.schema.spi.ScriptSourceInput) SourceType(org.hibernate.tool.schema.SourceType) MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) HibernateSchemaManagementTool(org.hibernate.tool.schema.internal.HibernateSchemaManagementTool) ExecutionOptions(org.hibernate.tool.schema.spi.ExecutionOptions) SchemaDropperImpl(org.hibernate.tool.schema.internal.SchemaDropperImpl) Database(org.hibernate.boot.model.relational.Database) ConfigurationService(org.hibernate.engine.config.spi.ConfigurationService) Map(java.util.Map) IndividuallySchemaMigratorImpl(org.hibernate.tool.schema.internal.IndividuallySchemaMigratorImpl) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 44 with MetadataImplementor

use of org.hibernate.boot.spi.MetadataImplementor 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 45 with MetadataImplementor

use of org.hibernate.boot.spi.MetadataImplementor in project hibernate-orm by hibernate.

the class SchemaMigrationTargetScriptCreationTest method tearDown.

@After
public void tearDown() {
    ServiceRegistry serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry(Environment.getProperties());
    try {
        MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(serviceRegistry).addAnnotatedClass(TestEntity.class).buildMetadata();
        metadata.validate();
        new SchemaExport().drop(EnumSet.of(TargetType.DATABASE, TargetType.STDOUT), metadata);
    } finally {
        ServiceRegistryBuilder.destroy(serviceRegistry);
    }
}
Also used : MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) ServiceRegistry(org.hibernate.service.ServiceRegistry) SchemaExport(org.hibernate.tool.hbm2ddl.SchemaExport) After(org.junit.After)

Aggregations

MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)68 MetadataSources (org.hibernate.boot.MetadataSources)58 Test (org.junit.Test)53 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)34 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)33 TestForIssue (org.hibernate.testing.TestForIssue)25 SchemaUpdate (org.hibernate.tool.hbm2ddl.SchemaUpdate)19 SchemaExport (org.hibernate.tool.hbm2ddl.SchemaExport)17 PersistentClass (org.hibernate.mapping.PersistentClass)15 File (java.io.File)14 MetadataBuilder (org.hibernate.boot.MetadataBuilder)7 Property (org.hibernate.mapping.Property)7 SimpleValue (org.hibernate.mapping.SimpleValue)7 Type (org.hibernate.type.Type)7 AbstractStandardBasicType (org.hibernate.type.AbstractStandardBasicType)6 BasicType (org.hibernate.type.BasicType)6 Metadata (org.hibernate.boot.Metadata)4 PhysicalNamingStrategy (org.hibernate.boot.model.naming.PhysicalNamingStrategy)4 Namespace (org.hibernate.boot.model.relational.Namespace)4 Sequence (org.hibernate.boot.model.relational.Sequence)4