Search in sources :

Example 21 with BootstrapServiceRegistry

use of org.hibernate.boot.registry.BootstrapServiceRegistry in project hibernate-orm by hibernate.

the class BootstrapTest method test_bootstrap_bootstrap_native_registry_BootstrapServiceRegistry_example.

@Test
public void test_bootstrap_bootstrap_native_registry_BootstrapServiceRegistry_example() {
    ClassLoader customClassLoader = Thread.currentThread().getContextClassLoader();
    Integrator customIntegrator = new BeanValidationIntegrator();
    //tag::bootstrap-bootstrap-native-registry-BootstrapServiceRegistry-example[]
    BootstrapServiceRegistryBuilder bootstrapRegistryBuilder = new BootstrapServiceRegistryBuilder();
    // add a custom ClassLoader
    bootstrapRegistryBuilder.applyClassLoader(customClassLoader);
    // manually add an Integrator
    bootstrapRegistryBuilder.applyIntegrator(customIntegrator);
    BootstrapServiceRegistry bootstrapRegistry = bootstrapRegistryBuilder.build();
//end::bootstrap-bootstrap-native-registry-BootstrapServiceRegistry-example[]
}
Also used : BootstrapServiceRegistryBuilder(org.hibernate.boot.registry.BootstrapServiceRegistryBuilder) BeanValidationIntegrator(org.hibernate.cfg.beanvalidation.BeanValidationIntegrator) BeanValidationIntegrator(org.hibernate.cfg.beanvalidation.BeanValidationIntegrator) Integrator(org.hibernate.integrator.spi.Integrator) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) Test(org.junit.Test)

Example 22 with BootstrapServiceRegistry

use of org.hibernate.boot.registry.BootstrapServiceRegistry in project hibernate-orm by hibernate.

the class DialectFactoryTest method setUp.

@Before
public void setUp() {
    final BootstrapServiceRegistry bootReg = new BootstrapServiceRegistryBuilder().applyClassLoader(DialectFactoryTest.class.getClassLoader()).build();
    registry = new StandardServiceRegistryBuilder(bootReg).build();
    dialectFactory = new DialectFactoryImpl();
    dialectFactory.injectServices((ServiceRegistryImplementor) registry);
}
Also used : BootstrapServiceRegistryBuilder(org.hibernate.boot.registry.BootstrapServiceRegistryBuilder) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) DialectFactoryImpl(org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) Before(org.junit.Before)

Example 23 with BootstrapServiceRegistry

use of org.hibernate.boot.registry.BootstrapServiceRegistry in project hibernate-orm by hibernate.

the class ImmutableTest method testMisplacedImmutableAnnotation.

@Test
public void testMisplacedImmutableAnnotation() {
    MetadataSources metadataSources = new MetadataSources().addAnnotatedClass(Foobar.class);
    try {
        metadataSources.buildMetadata();
        fail("Expecting exception due to misplaced @Immutable annotation");
    } catch (AnnotationException ignore) {
    } finally {
        ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry();
        if (metaServiceRegistry instanceof BootstrapServiceRegistry) {
            BootstrapServiceRegistryBuilder.destroy(metaServiceRegistry);
        }
    }
}
Also used : MetadataSources(org.hibernate.boot.MetadataSources) AnnotationException(org.hibernate.AnnotationException) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) ServiceRegistry(org.hibernate.service.ServiceRegistry) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) Test(org.junit.Test)

Example 24 with BootstrapServiceRegistry

use of org.hibernate.boot.registry.BootstrapServiceRegistry in project hibernate-orm by hibernate.

the class FetchProfileTest method testXmlOverride.

@Test
public void testXmlOverride() {
    Configuration config = new Configuration();
    config.addAnnotatedClass(Customer5.class);
    config.addAnnotatedClass(Order.class);
    config.addAnnotatedClass(Country.class);
    InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("org/hibernate/test/annotations/fetchprofile/mappings.hbm.xml");
    config.addInputStream(is);
    SessionFactoryImplementor sessionImpl = (SessionFactoryImplementor) config.buildSessionFactory(serviceRegistry);
    assertTrue("fetch profile not parsed properly", sessionImpl.containsFetchProfileDefinition("orders-profile"));
    sessionImpl.close();
    // now the same with no xml
    final MetadataSources metadataSources = new MetadataSources().addAnnotatedClass(Customer5.class).addAnnotatedClass(Order.class).addAnnotatedClass(Country.class);
    try {
        metadataSources.buildMetadata();
        fail();
    } catch (MappingException e) {
        log.trace("success");
    } finally {
        ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry();
        if (metaServiceRegistry instanceof BootstrapServiceRegistry) {
            BootstrapServiceRegistryBuilder.destroy(metaServiceRegistry);
        }
    }
}
Also used : Configuration(org.hibernate.cfg.Configuration) InputStream(java.io.InputStream) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) MetadataSources(org.hibernate.boot.MetadataSources) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) ServiceRegistry(org.hibernate.service.ServiceRegistry) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) MappingException(org.hibernate.MappingException) Test(org.junit.Test)

Example 25 with BootstrapServiceRegistry

use of org.hibernate.boot.registry.BootstrapServiceRegistry in project hibernate-orm by hibernate.

the class FetchProfileTest method testWrongAssociationName.

@Test
public void testWrongAssociationName() {
    final MetadataSources metadataSources = new MetadataSources().addAnnotatedClass(Customer2.class).addAnnotatedClass(Order.class).addAnnotatedClass(Country.class);
    try {
        metadataSources.buildMetadata();
        fail();
    } catch (MappingException e) {
        log.trace("success");
    } finally {
        ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry();
        if (metaServiceRegistry instanceof BootstrapServiceRegistry) {
            BootstrapServiceRegistryBuilder.destroy(metaServiceRegistry);
        }
    }
}
Also used : MetadataSources(org.hibernate.boot.MetadataSources) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) ServiceRegistry(org.hibernate.service.ServiceRegistry) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) MappingException(org.hibernate.MappingException) Test(org.junit.Test)

Aggregations

BootstrapServiceRegistry (org.hibernate.boot.registry.BootstrapServiceRegistry)26 Test (org.junit.Test)18 MetadataSources (org.hibernate.boot.MetadataSources)16 ServiceRegistry (org.hibernate.service.ServiceRegistry)14 BootstrapServiceRegistryBuilder (org.hibernate.boot.registry.BootstrapServiceRegistryBuilder)11 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)11 Metadata (org.hibernate.boot.Metadata)5 MappingException (org.hibernate.MappingException)4 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)4 TestForIssue (org.hibernate.testing.TestForIssue)4 FileInputStream (java.io.FileInputStream)3 Properties (java.util.Properties)3 AnnotationException (org.hibernate.AnnotationException)3 File (java.io.File)2 MetadataBuilder (org.hibernate.boot.MetadataBuilder)2 Configuration (org.hibernate.cfg.Configuration)2 Integrator (org.hibernate.integrator.spi.Integrator)2 InputStream (java.io.InputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 HashMap (java.util.HashMap)1