Search in sources :

Example 21 with MetadataImplementor

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

the class DisabledForeignKeyTest method expandedTests.

@Test
@TestForIssue(jiraKey = "HHH-9704")
public void expandedTests() {
    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();
        // export the schema
        new SchemaExport().execute(EnumSet.of(TargetType.DATABASE), SchemaExport.Action.BOTH, metadata);
        try {
            // update the schema
            new SchemaUpdate().execute(EnumSet.of(TargetType.DATABASE), metadata);
        } finally {
            // drop the schema
            new SchemaExport().execute(EnumSet.of(TargetType.DATABASE), SchemaExport.Action.DROP, metadata);
        }
    } finally {
        StandardServiceRegistryBuilder.destroy(standardRegistry);
    }
}
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 22 with MetadataImplementor

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

the class SequenceExportTest 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();
    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 23 with MetadataImplementor

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

the class ValueVisitorTest method testProperCallbacks.

@Test
public void testProperCallbacks() {
    final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(serviceRegistry).buildMetadata();
    final Table tbl = new Table();
    final RootClass rootClass = new RootClass(metadataBuildingContext);
    ValueVisitor vv = new ValueVisitorValidator();
    new Any(metadata, tbl).accept(vv);
    new Array(metadata, rootClass).accept(vv);
    new Bag(metadata, rootClass).accept(vv);
    new Component(metadata, rootClass).accept(vv);
    new DependantValue(metadata, tbl, null).accept(vv);
    new IdentifierBag(metadata, rootClass).accept(vv);
    new List(metadata, rootClass).accept(vv);
    new ManyToOne(metadata, tbl).accept(vv);
    new Map(metadata, rootClass).accept(vv);
    new OneToMany(metadata, rootClass).accept(vv);
    new OneToOne(metadata, tbl, rootClass).accept(vv);
    new PrimitiveArray(metadata, rootClass).accept(vv);
    new Set(metadata, rootClass).accept(vv);
    new SimpleValue(metadata).accept(vv);
}
Also used : RootClass(org.hibernate.mapping.RootClass) Table(org.hibernate.mapping.Table) Set(org.hibernate.mapping.Set) ValueVisitor(org.hibernate.mapping.ValueVisitor) DependantValue(org.hibernate.mapping.DependantValue) MetadataSources(org.hibernate.boot.MetadataSources) Bag(org.hibernate.mapping.Bag) IdentifierBag(org.hibernate.mapping.IdentifierBag) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) IdentifierBag(org.hibernate.mapping.IdentifierBag) OneToMany(org.hibernate.mapping.OneToMany) Any(org.hibernate.mapping.Any) ManyToOne(org.hibernate.mapping.ManyToOne) SimpleValue(org.hibernate.mapping.SimpleValue) Array(org.hibernate.mapping.Array) PrimitiveArray(org.hibernate.mapping.PrimitiveArray) OneToOne(org.hibernate.mapping.OneToOne) PrimitiveArray(org.hibernate.mapping.PrimitiveArray) List(org.hibernate.mapping.List) Component(org.hibernate.mapping.Component) Map(org.hibernate.mapping.Map) Test(org.junit.Test)

Example 24 with MetadataImplementor

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

the class Tests method testJpaJoinColumnPhysicalNaming.

@Test
@TestForIssue(jiraKey = "HHH-9961")
public void testJpaJoinColumnPhysicalNaming() {
    final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySettings(Environment.getProperties()).build();
    try {
        final MetadataSources metadataSources = new MetadataSources(ssr);
        metadataSources.addAnnotatedClass(Language.class);
        final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder();
        metadataBuilder.applyImplicitNamingStrategy(ImplicitNamingStrategyJpaCompliantImpl.INSTANCE);
        metadataBuilder.applyPhysicalNamingStrategy(PhysicalNamingStrategyImpl.INSTANCE);
        final Metadata metadata = metadataBuilder.build();
        ((MetadataImplementor) metadata).validate();
        final PersistentClass languageBinding = metadata.getEntityBinding(Language.class.getName());
        final Property property = languageBinding.getProperty("fallBack");
        Iterator itr = property.getValue().getColumnIterator();
        assertTrue(itr.hasNext());
        final Column column = (Column) itr.next();
        assertFalse(itr.hasNext());
        assertEquals("C_FALLBACK_ID", column.getName().toUpperCase(Locale.ROOT));
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataBuilder(org.hibernate.boot.MetadataBuilder) Column(org.hibernate.mapping.Column) MetadataSources(org.hibernate.boot.MetadataSources) Metadata(org.hibernate.boot.Metadata) Iterator(java.util.Iterator) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) Property(org.hibernate.mapping.Property) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) PersistentClass(org.hibernate.mapping.PersistentClass) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 25 with MetadataImplementor

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

the class SequenceReadingTest method testSequenceReading.

@Test
public void testSequenceReading() {
    StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.DIALECT, MyExtendedH2Dialect.class).build();
    try {
        final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(MyEntity.class).buildMetadata();
        metadata.validate();
        try {
            // try to update the schema
            new SchemaUpdate().execute(EnumSet.of(TargetType.DATABASE), metadata);
        } finally {
            try {
                // clean up
                new SchemaExport().drop(EnumSet.of(TargetType.DATABASE), metadata);
            } catch (Exception ignore) {
            }
        }
    } 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)

Aggregations

MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)67 MetadataSources (org.hibernate.boot.MetadataSources)58 Test (org.junit.Test)53 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)33 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)33 TestForIssue (org.hibernate.testing.TestForIssue)25 SchemaUpdate (org.hibernate.tool.hbm2ddl.SchemaUpdate)19 SchemaExport (org.hibernate.tool.hbm2ddl.SchemaExport)16 PersistentClass (org.hibernate.mapping.PersistentClass)15 File (java.io.File)13 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 Namespace (org.hibernate.boot.model.relational.Namespace)4 Sequence (org.hibernate.boot.model.relational.Sequence)4 SchemaDropperImpl (org.hibernate.tool.schema.internal.SchemaDropperImpl)4