Search in sources :

Example 41 with MetadataSources

use of org.hibernate.boot.MetadataSources in project hibernate-orm by hibernate.

the class QueryReturnTest method testQueryReturn.

@Test
public void testQueryReturn() {
    StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder().applySetting("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
    StandardServiceRegistry standardServiceRegistry = serviceRegistryBuilder.build();
    MetadataSources metadataSources = new MetadataSources(standardServiceRegistry);
    try {
        metadataSources.addInputStream(new ReaderInputStream(new StringReader(QUERY_RETURN_HBM_XML)));
        Metadata metadata = metadataSources.buildMetadata();
        NamedSQLQueryDefinition myQuery = metadata.getNamedNativeQueryDefinition("myQuery");
        Assert.assertNotNull(myQuery);
        NativeSQLQueryReturn[] myQueryReturns = myQuery.getQueryReturns();
        Assert.assertNotNull(myQueryReturns);
        Assert.assertEquals(1, myQueryReturns.length);
        Assert.assertTrue(NativeSQLQueryRootReturn.class.isInstance(myQueryReturns[0]));
        NativeSQLQueryRootReturn myQueryRootReturn = (NativeSQLQueryRootReturn) myQueryReturns[0];
        Assert.assertEquals("e", myQueryRootReturn.getAlias());
        Assert.assertEquals("org.hibernate.test.hbm.query.QueryReturnTest$Bar", myQueryRootReturn.getReturnEntityName());
    } finally {
        if (standardServiceRegistry instanceof StandardServiceRegistryImpl) {
            ((StandardServiceRegistryImpl) standardServiceRegistry).destroy();
        }
    }
}
Also used : ReaderInputStream(org.hibernate.engine.jdbc.ReaderInputStream) NamedSQLQueryDefinition(org.hibernate.engine.spi.NamedSQLQueryDefinition) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) NativeSQLQueryReturn(org.hibernate.engine.query.spi.sql.NativeSQLQueryReturn) MetadataSources(org.hibernate.boot.MetadataSources) StringReader(java.io.StringReader) Metadata(org.hibernate.boot.Metadata) NativeSQLQueryRootReturn(org.hibernate.engine.query.spi.sql.NativeSQLQueryRootReturn) StandardServiceRegistryImpl(org.hibernate.boot.registry.internal.StandardServiceRegistryImpl) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test)

Example 42 with MetadataSources

use of org.hibernate.boot.MetadataSources in project hibernate-orm by hibernate.

the class UniqueDelegateTest method testUniqueDelegateConsulted.

@Test
@TestForIssue(jiraKey = "HHH-10203")
public void testUniqueDelegateConsulted() {
    final Metadata metadata = new MetadataSources(ssr).addResource("org/hibernate/test/hbm/uk/person_unique.hbm.xml").buildMetadata();
    final JournalingSchemaToolingTarget target = new JournalingSchemaToolingTarget();
    new SchemaCreatorImpl(ssr).doCreation(metadata, false, target);
    assertThat(getAlterTableToAddUniqueKeyCommandCallCount, equalTo(1));
    assertThat(getColumnDefinitionUniquenessFragmentCallCount, equalTo(1));
    assertThat(getTableCreationUniqueConstraintsFragmentCallCount, equalTo(1));
    new SchemaDropperImpl(ssr).doDrop(metadata, false, target);
    // unique keys are not dropped explicitly
    assertThat(getAlterTableToAddUniqueKeyCommandCallCount, equalTo(1));
    assertThat(getColumnDefinitionUniquenessFragmentCallCount, equalTo(1));
    assertThat(getTableCreationUniqueConstraintsFragmentCallCount, equalTo(1));
}
Also used : SchemaCreatorImpl(org.hibernate.tool.schema.internal.SchemaCreatorImpl) SchemaDropperImpl(org.hibernate.tool.schema.internal.SchemaDropperImpl) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) JournalingSchemaToolingTarget(org.hibernate.test.hbm.index.JournalingSchemaToolingTarget) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 43 with MetadataSources

use of org.hibernate.boot.MetadataSources in project hibernate-orm by hibernate.

the class CollectionPkTest method verifyPkNameUsed.

private void verifyPkNameUsed(String mappingResource, String expectedName) {
    final Metadata metadata = new MetadataSources(ssr).addResource(mappingResource).buildMetadata();
    final JournalingSchemaToolingTarget target = new JournalingSchemaToolingTarget();
    new SchemaCreatorImpl(ssr).doCreation(metadata, false, target);
    assertTrue("Expected foreign-key name [" + expectedName + "] not seen in schema creation output", target.containedText(expectedName));
}
Also used : SchemaCreatorImpl(org.hibernate.tool.schema.internal.SchemaCreatorImpl) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) JournalingSchemaToolingTarget(org.hibernate.test.hbm.index.JournalingSchemaToolingTarget)

Example 44 with MetadataSources

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

use of org.hibernate.boot.MetadataSources in project hibernate-orm by hibernate.

the class ExtendsTest method testAllSeparateInOne.

@Test
public void testAllSeparateInOne() {
    Metadata metadata = new MetadataSources(serviceRegistry).addResource(getBaseForMappings() + "extendshbm/allseparateinone.hbm.xml").buildMetadata();
    assertNotNull(metadata.getEntityBinding("org.hibernate.test.extendshbm.Customer"));
    assertNotNull(metadata.getEntityBinding("org.hibernate.test.extendshbm.Person"));
    assertNotNull(metadata.getEntityBinding("org.hibernate.test.extendshbm.Employee"));
}
Also used : Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) Test(org.junit.Test)

Aggregations

MetadataSources (org.hibernate.boot.MetadataSources)189 Test (org.junit.Test)133 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)105 Metadata (org.hibernate.boot.Metadata)87 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)73 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)58 TestForIssue (org.hibernate.testing.TestForIssue)47 PersistentClass (org.hibernate.mapping.PersistentClass)36 SchemaExport (org.hibernate.tool.hbm2ddl.SchemaExport)31 SchemaUpdate (org.hibernate.tool.hbm2ddl.SchemaUpdate)19 BootstrapServiceRegistry (org.hibernate.boot.registry.BootstrapServiceRegistry)18 ServiceRegistry (org.hibernate.service.ServiceRegistry)18 Before (org.junit.Before)18 Property (org.hibernate.mapping.Property)17 File (java.io.File)14 SchemaCreatorImpl (org.hibernate.tool.schema.internal.SchemaCreatorImpl)14 Map (java.util.Map)13 MetadataBuilder (org.hibernate.boot.MetadataBuilder)12 Type (org.hibernate.type.Type)12 SimpleValue (org.hibernate.mapping.SimpleValue)11