Search in sources :

Example 31 with Metadata

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

the class LegacyPostCommitListenerTest method prepareBootstrapRegistryBuilder.

@Override
protected void prepareBootstrapRegistryBuilder(BootstrapServiceRegistryBuilder builder) {
    super.prepareBootstrapRegistryBuilder(builder);
    builder.applyIntegrator(new Integrator() {

        @Override
        public void integrate(Metadata metadata, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
            integrate(serviceRegistry);
        }

        private void integrate(SessionFactoryServiceRegistry serviceRegistry) {
            serviceRegistry.getService(EventListenerRegistry.class).getEventListenerGroup(EventType.POST_COMMIT_DELETE).appendListener(postCommitDeleteEventListener);
            serviceRegistry.getService(EventListenerRegistry.class).getEventListenerGroup(EventType.POST_COMMIT_UPDATE).appendListener(postCommitUpdateEventListener);
            serviceRegistry.getService(EventListenerRegistry.class).getEventListenerGroup(EventType.POST_COMMIT_INSERT).appendListener(postCommitInsertEventListener);
        }

        @Override
        public void disintegrate(SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
        }
    });
}
Also used : SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) Metadata(org.hibernate.boot.Metadata) Integrator(org.hibernate.integrator.spi.Integrator) SessionFactoryServiceRegistry(org.hibernate.service.spi.SessionFactoryServiceRegistry) EventListenerRegistry(org.hibernate.event.service.spi.EventListenerRegistry)

Example 32 with Metadata

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

the class PostCommitListenerTest method prepareBootstrapRegistryBuilder.

@Override
protected void prepareBootstrapRegistryBuilder(BootstrapServiceRegistryBuilder builder) {
    super.prepareBootstrapRegistryBuilder(builder);
    builder.applyIntegrator(new Integrator() {

        @Override
        public void integrate(Metadata metadata, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
            integrate(serviceRegistry);
        }

        private void integrate(SessionFactoryServiceRegistry serviceRegistry) {
            serviceRegistry.getService(EventListenerRegistry.class).getEventListenerGroup(EventType.POST_COMMIT_DELETE).appendListener(postCommitDeleteEventListener);
            serviceRegistry.getService(EventListenerRegistry.class).getEventListenerGroup(EventType.POST_COMMIT_UPDATE).appendListener(postCommitUpdateEventListener);
            serviceRegistry.getService(EventListenerRegistry.class).getEventListenerGroup(EventType.POST_COMMIT_INSERT).appendListener(postCommitInsertEventListener);
        }

        @Override
        public void disintegrate(SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
        }
    });
}
Also used : SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) Metadata(org.hibernate.boot.Metadata) Integrator(org.hibernate.integrator.spi.Integrator) SessionFactoryServiceRegistry(org.hibernate.service.spi.SessionFactoryServiceRegistry) EventListenerRegistry(org.hibernate.event.service.spi.EventListenerRegistry)

Example 33 with Metadata

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

the class ExtendsTest method testMissingSuper.

@Test
public void testMissingSuper() {
    try {
        Metadata metadata = new MetadataSources(serviceRegistry).addResource(getBaseForMappings() + "extendshbm/Customer.hbm.xml").addResource(getBaseForMappings() + "extendshbm/Employee.hbm.xml").buildMetadata();
        fail("Should not be able to build sessionFactory without a Person");
    } catch (HibernateException e) {
    }
}
Also used : HibernateException(org.hibernate.HibernateException) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) Test(org.junit.Test)

Example 34 with Metadata

use of org.hibernate.boot.Metadata 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 35 with Metadata

use of org.hibernate.boot.Metadata 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)

Aggregations

Metadata (org.hibernate.boot.Metadata)99 MetadataSources (org.hibernate.boot.MetadataSources)88 Test (org.junit.Test)73 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)46 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)41 PersistentClass (org.hibernate.mapping.PersistentClass)29 TestForIssue (org.hibernate.testing.TestForIssue)24 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)12 Property (org.hibernate.mapping.Property)11 SchemaCreatorImpl (org.hibernate.tool.schema.internal.SchemaCreatorImpl)11 Collection (org.hibernate.mapping.Collection)10 RootClass (org.hibernate.mapping.RootClass)10 Map (java.util.Map)9 HashMap (java.util.HashMap)8 SessionFactory (org.hibernate.SessionFactory)8 Session (org.hibernate.Session)7 Integrator (org.hibernate.integrator.spi.Integrator)7 SessionFactoryServiceRegistry (org.hibernate.service.spi.SessionFactoryServiceRegistry)7 ServiceRegistry (org.hibernate.service.ServiceRegistry)6 Properties (java.util.Properties)5