Example usage for org.hibernate.engine.config.spi ConfigurationService getSetting

List of usage examples for org.hibernate.engine.config.spi ConfigurationService getSetting

Introduction

In this page you can find the example usage for org.hibernate.engine.config.spi ConfigurationService getSetting.

Prototype

public <T> T getSetting(String name, Converter<T> converter);

Source Link

Document

Get the named setting, using the specified converter.

Usage

From source file:edu.jhuapl.dorset.components.HibernateServiceTest.java

License:Open Source License

@Test
public void testCreationOfSessionFactory() {
    Properties props = getProperties();
    Config conf = ConfigFactory.parseProperties(props);

    hs = new HibernateService(conf);
    SessionFactory sf = hs.getSessionFactory();
    assertNotNull(sf);//  ww  w . j  a  va 2  s  . c om
    assertFalse(sf.isClosed());

    // traverse through the session factory to get at configuration values
    SessionFactoryOptions sfo = sf.getSessionFactoryOptions();
    StandardServiceRegistry ssr = sfo.getServiceRegistry();
    ConfigurationService cs = ssr.getService(ConfigurationService.class);
    assertEquals(props.getProperty("hibernate.connection.driver_class"),
            cs.getSetting("hibernate.connection.driver_class", StandardConverters.STRING));
    assertEquals(props.getProperty("hibernate.connection.url"),
            cs.getSetting("hibernate.connection.url", StandardConverters.STRING));
    assertEquals(props.getProperty("hibernate.dialect"),
            cs.getSetting("hibernate.dialect", StandardConverters.STRING));
    assertEquals(props.getProperty("hibernate.hbm2ddl.auto"),
            cs.getSetting("hibernate.hbm2ddl.auto", StandardConverters.STRING));

    // check mapping
    ClassMetadata cm = sf.getClassMetadata(TestObject.class);
    String[] names = cm.getPropertyNames();
    assertEquals(1, names.length);
    assertEquals("name", names[0]);
    assertEquals("string", cm.getPropertyType("name").getName());
}

From source file:org.infinispan.test.hibernate.cache.util.CacheTestUtil.java

License:LGPL

public static InfinispanRegionFactory startRegionFactory(ServiceRegistry serviceRegistry) {
    try {/*from  w  w w  .  j  av a2 s  . c  o  m*/
        final ConfigurationService cfgService = serviceRegistry.getService(ConfigurationService.class);
        final Properties properties = toProperties(cfgService.getSettings());

        String factoryType = cfgService.getSetting(AvailableSettings.CACHE_REGION_FACTORY,
                StandardConverters.STRING);
        Class clazz = Thread.currentThread().getContextClassLoader().loadClass(factoryType);
        InfinispanRegionFactory regionFactory;
        if (clazz == InfinispanRegionFactory.class) {
            regionFactory = new TestInfinispanRegionFactory(properties);
        } else {
            if (InfinispanRegionFactory.class.isAssignableFrom(clazz)) {
                regionFactory = createRegionFactory(clazz, properties);
            } else {
                throw new IllegalArgumentException(clazz + " is not InfinispanRegionFactory");
            }
        }

        final SessionFactoryOptionsImpl sessionFactoryOptions = new SessionFactoryOptionsImpl(
                new SessionFactoryBuilderImpl.SessionFactoryOptionsStateStandardImpl(
                        (StandardServiceRegistry) serviceRegistry));

        regionFactory.start(sessionFactoryOptions, properties);

        return regionFactory;
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}