Search in sources :

Example 71 with MetadataImplementor

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

the class LegacySequenceExportTest method testMultipleUsesOfExplicitSequenceName.

@Test
@TestForIssue(jiraKey = "HHH-9936")
public void testMultipleUsesOfExplicitSequenceName() {
    final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(Entity3.class).addAnnotatedClass(Entity4.class).buildMetadata();
    metadata.validate();
    assertEquals(0, metadata.getDatabase().getAuxiliaryDatabaseObjects().size());
    int count = 0;
    for (Namespace namespace : metadata.getDatabase().getNamespaces()) {
        for (Sequence sequence : namespace.getSequences()) {
            count++;
        }
    }
    assertEquals(1, count);
}
Also used : MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) Sequence(org.hibernate.boot.model.relational.Sequence) Namespace(org.hibernate.boot.model.relational.Namespace) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 72 with MetadataImplementor

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

the class SequenceExportTest method testMultipleUsesOfDefaultSequenceName.

@Test
@TestForIssue(jiraKey = "HHH-9936")
public void testMultipleUsesOfDefaultSequenceName() {
    final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(Entity1.class).addAnnotatedClass(Entity2.class).buildMetadata();
    metadata.validate();
    int namespaceCount = 0;
    int sequenceCount = 0;
    for (Namespace namespace : metadata.getDatabase().getNamespaces()) {
        namespaceCount++;
        for (Sequence sequence : namespace.getSequences()) {
            sequenceCount++;
        }
    }
    assertEquals(1, namespaceCount);
    assertEquals(1, sequenceCount);
}
Also used : MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) Sequence(org.hibernate.boot.model.relational.Sequence) Namespace(org.hibernate.boot.model.relational.Namespace) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 73 with MetadataImplementor

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

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

the class InheritedAttributeOverridingTest method testInheritedAttributeOverridingMappedsuperclass.

@Test
@TestForIssue(jiraKey = "HHH-9485")
public void testInheritedAttributeOverridingMappedsuperclass() {
    Metadata metadata = new MetadataSources(standardServiceRegistry).addAnnotatedClass(A.class).addAnnotatedClass(B.class).buildMetadata();
    ((MetadataImplementor) metadata).validate();
}
Also used : Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 75 with MetadataImplementor

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

the class AttributeConverterTest method testBasicOrmXmlConverterApplication.

@Test
@TestForIssue(jiraKey = "HHH-8462")
public void testBasicOrmXmlConverterApplication() {
    final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
    try {
        MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(Tester.class).addURL(ConfigHelper.findAsResource("org/hibernate/test/converter/orm.xml")).getMetadataBuilder().build();
        PersistentClass tester = metadata.getEntityBinding(Tester.class.getName());
        Property nameProp = tester.getProperty("name");
        SimpleValue nameValue = (SimpleValue) nameProp.getValue();
        Type type = nameValue.getType();
        assertNotNull(type);
        if (!AttributeConverterTypeAdapter.class.isInstance(type)) {
            fail("AttributeConverter not applied");
        }
        AttributeConverterTypeAdapter basicType = assertTyping(AttributeConverterTypeAdapter.class, type);
        assertSame(StringTypeDescriptor.INSTANCE, basicType.getJavaTypeDescriptor());
        assertEquals(Types.CLOB, basicType.getSqlTypeDescriptor().getSqlType());
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : BasicType(org.hibernate.type.BasicType) AbstractStandardBasicType(org.hibernate.type.AbstractStandardBasicType) Type(org.hibernate.type.Type) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) AttributeConverterTypeAdapter(org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter) Property(org.hibernate.mapping.Property) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) PersistentClass(org.hibernate.mapping.PersistentClass) SimpleValue(org.hibernate.mapping.SimpleValue) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Aggregations

MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)113 MetadataSources (org.hibernate.boot.MetadataSources)80 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)62 Test (org.junit.Test)56 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)52 SimpleValue (org.hibernate.mapping.SimpleValue)32 RootClass (org.hibernate.mapping.RootClass)31 PersistentClass (org.hibernate.mapping.PersistentClass)27 TestForIssue (org.hibernate.testing.TestForIssue)26 Table (org.hibernate.mapping.Table)23 Test (org.junit.jupiter.api.Test)23 SchemaExport (org.hibernate.tool.hbm2ddl.SchemaExport)22 SchemaUpdate (org.hibernate.tool.hbm2ddl.SchemaUpdate)20 Column (org.hibernate.mapping.Column)17 ArrayList (java.util.ArrayList)15 ServiceRegistry (org.hibernate.service.ServiceRegistry)15 File (java.io.File)14 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)14 Configuration (org.hibernate.cfg.Configuration)12 Property (org.hibernate.mapping.Property)11